In the event of technical difficulties with Szkopuł, please contact us via email at [email protected].
If you would like to talk about tasks, solutions or technical problems, please visit our Discord servers. They are moderated by the community, but members of the support team are also active there.
Byteman invented a new semidigital signature system called ByteCrypt. In this system each user receives a personal key of the shape of cube (empty inside) of edge length , which he or she uses for signing documents. Every side of every cube is divided into regions, each of which may contain exactly one chip (encoding or of general purpose) or remain empty. All encoding chips are identical; similarly, every two chips of general purpose are identical. The pattern created by encoding chips on each side of every cube is always the same (each side can be rotated in such way that the patterns on all sides of all cubes will be exactly the same); the only difference between any two sides of any cubes is which of the remaining regions are occupied by chips of general purpose. Moreover, all chips are always located on one surface of each cube's side only - the surface that is directed to the inside of the cubic key.
Bytehacker is going to break the ByteCrypt system; he already learned how to counterfeit the cubic keys. He would like to know how many keys he needs to be able to pretend to be any of the users of the system. More precisely, for every possible user's key (defined by the pattern of chips of general purpose on each side of the cube and how the cube is composed of the sides) Bytehacker would like to possess such a key that after disassembling (separating its sides), relocating and rotating the sides in any way and then building a new cube out of the pieces results in a key that is identical with the considered user's key. Two keys are identical if there is a way of rotating one of them that results in the second one. In order not to depress Bytehacker, return the remainder of the division of the number of required keys by .
Write a program which:
In the first line of the input there is exactly one positive integer (). In each of consecutive lines there are integers (), separated by single spaces. means that in -th column of -th row of every side there is a encoding chip. means that the corresponding region does not contain an encoding chip, so it can be empty or contain a chip of general purpose.
In the only line of the output there should be exactly one integer - the number of keys that Bytehacker needs modulo .
For the input data:
3 1 0 0 1 1 1 0 0 1
the correct result is:
5005
Task author: Krzysztof Duleba.