#P9752. Five-Dial Lock Security
Five-Dial Lock Security
Five-Dial Lock Security
Little Y uses a five‐dial combination lock to secure his bicycle. Each dial is labeled with the digits from to in a cyclic order (i.e. after comes , and before comes ). When locking his bicycle, starting from the correct password, he performs a single random move. In each move, he rotates either a single dial or two adjacent dials by the same nonzero amount (where ) in one direction. For example, he can change the lock state from 0 0 1 1 5
to 1 1 1 1 5
by rotating the first two dials by , but he cannot change it to 1 2 1 1 5
because the two dials must be rotated by the same amount.
After some time, Little Y worries about the security of his locking method. He has recorded lock states after locking his bicycle (note that none of these states is the correct password).
Your task is to count the number of possible correct passwords (each a 5‐digit number, with possible leading zeros) such that for every recorded state , there exists a valid move (rotating either a single dial or two adjacent dials by a nonzero amount) which transforms into . In other words, when comparing and a recorded state , the differences computed modulo must be all zero except for either exactly one position or exactly two consecutive positions where the difference is the same nonzero value.
inputFormat
The first line contains an integer (), the number of recorded states. Each of the next lines contains a string of 5 digits representing a recorded state of the lock (possibly with leading zeros).
outputFormat
Output a single integer: the number of possible correct passwords that can generate every recorded state via a single valid move.
sample
1
00115
81