#P379. 练65.2 跳房子

练65.2 跳房子

Description

The cows are playing a non-traditional version of the children's "hopscotch" game. Instead of a linear arrangement of numbered squares, they have created a 5×55 \times 5 grid of numbers, aligned with the xx and yy axes. The cows skillfully jump from number to number in the grid: forward, backward, left, or right (never diagonally), landing on another number in the grid. They continue jumping (using the same rules), possibly landing on numbers they've already visited. After a total of five jumps, their path forms a six-digit integer (which may start with 00, e.g., 000201000201). Find the total number of distinct integers that can be formed in this way.

Input Format

Lines 11 to 55: The grid, each line contains 55 integers.

Output Format

Line 11: The total number of distinct integers that can be formed.

Sample

1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 2 1
1 1 1 1 1
15