#P5. [CSP-S 2023] Password lock
[CSP-S 2023] Password lock
Description
Xiao Y has a password lock with five dials. As shown in the figure, there are numbers from to on each dial. Each dial is a loop from to , where can change to or by shifting one position.
Because it is relatively safe on campus, the locking method adopted by Xiao Y is: starting from the correct password, randomly turning the password lock only once; Each time, only one dial is rotated by a certain amplitude or two adjacent dials are rotated simultaneously.
When Little Y chooses to rotate two adjacent dials at the same time, the amplitude of rotation of the two dials is the same, that is, Little Y can convert the password lock from to , but not to .
After a long time, Xiao Y was also worried about the safety of locking the car like this, so he recorded the states of the password lock after locking the car. Note that none of these states are the correct password.
How many possible correct passwords does Xiao Y have to verify the security of locking the car in this way, so that each correct password can generate all n states of the password lock after locking the car according to the locking method he uses.
Input
The first line of input contains a positive integer , representing the number of states of the password lock after the car is locked.
The next line contains five integers per line, representing the state of a password lock.
Output
Output a line containing an integer representing how many correct passwords the states of the password lock can correspond to according to the given locking method.
Samples
1
0 0 1 1 5
81
Tips
[Sample Input 1 Explanation]
There are a total of possible solutions. There are options for rotating one dial and options for rotating two dials.
[Sample 2]
See lock/lock2.in
and lock/lock2.ans
in the player directory.
[Data Range]
For all test data: .
Test point | Special properties | |
---|---|---|
None | ||
A | ||
None |
Special property A: Ensure that all correct passwords can obtain the states given by the test data by rotating only one dial.