#Lutece1493. Magic Cube
Magic Cube
Migrated from Lutece 1493 Magic Cube
All parts of this problem, including description, images, samples, data and checker, might be broken. If you find bugs in this problem, please contact the admins.
Description
Magic Cube is a cube (M M M) which contains a integer number (0 number < P) in each sell (So you know there are numbers).
Alice have one big cube and N smaller cubes (each small cube is unique),
The cube is magic since when you put a small cube in bigger one, the number in the same location will add up and mod P.
You job is to determine the location of each cube, so that we can make every number in big cube equal 0 after putting all the small cubes.
Note:
-
We guarantee that there is only one solution.
-
You cannot rotate cube.
-
We give the numbers in cubes in order of position [0, 0, 0], [0, 0, 1], ..., [0, 1, 0], ..., [1, 0, 0], ...
Input
The first line is three integers M (2 M 7), N (1 N 12), P (3 P 5)
Second line is M M M integers, showing the numbers in big cube.
Then is N lines, which first is a integer L[i] (1 L[i] < M) shows the length of the small cube, then follows numbers (0 number < P).
Output
Output N lines of triad of integers, shows the location of this small cube.
Samples
2 1 3
1 0 0 0 0 0 0 0
1 2
0 0 0