Board Jump

Time limit1sMemory limit128 MB

Problem

You are given an N × N game board. Each cell holds a single digit from 0 to 9. A piece starts on the top-left cell and must reach the bottom-right cell.

The number written in a cell is the exact distance (jump length) you must move from that cell. You may only move to the right or downward, and you must move exactly that many cells to the right or exactly that many cells down. A cell containing 0 is a terminal cell from which no further move is possible.

Count the number of distinct paths that start at the top-left cell and reach the bottom-right cell while following these rules.

Input

The first line contains an integer N (4 ≤ N ≤ 100). Each of the next N lines contains N digits between 0 and 9, separated by spaces.

Output

Print, on a single line, the number of distinct paths from the top-left cell to the bottom-right cell that follow the rules. The number of paths may exceed $2^{63}-1$, but it never has more than 100 digits.

Hint

Figure 1Figure 2