#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 00 to 99 on each dial. Each dial is a loop from 00 to 99, where 99 can change to 00 or 88 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 0  0  1  1  5\tt{0\;0\;1\;1\;5} to 1  1  1  1  5\tt{1\;1\;1\;1\;5}, but not to 1  2  1  1  5\tt{1\;2\;1\;1\;5}.

After a long time, Xiao Y was also worried about the safety of locking the car like this, so he recorded the nn states of the password lock after locking the car. Note that none of these nn 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 nn, representing the number of states of the password lock after the car is locked.

The next nn 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 nn 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 8181 possible solutions. There are 4545 options for rotating one dial and 3636 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: 1n81 \leq n \leq 8.

Test point nn\leq Special properties
131 \sim 3 11 None
454 \sim 5 22
686 \sim 8 88 A
9109 \sim 10 None

Special property A: Ensure that all correct passwords can obtain the nn states given by the test data by rotating only one dial.