// Arup Guha
// 1/5/2014
// Solution to 2005 MCPC Problem A: Pascal's Travels

import java.util.*;

public class a {

	public static void main(String[] args) {

		Scanner stdin = new Scanner(System.in);
		int n = stdin.nextInt();

		// Process all cases.
		while (n != -1) {

			// Read in grid and store as integers.
			int[][] grid = new int[n][n];
			for (int i=0; i<n; i++) {
				String line = stdin.next();
				for (int j=0; j<n; j++)
					grid[i][j] = line.charAt(j) - '0';
			}

			long[][] dp = new long[n][n];
			dp[0][0] = 1;

			// Cycle through all squares.
			for (int i=0; i<n; i++) {
				for (int j=0; j<n; j++) {

					// Dead end...
					if (grid[i][j] == 0) continue;

					// Go down if we can.
					if (i+grid[i][j] < n) dp[i+grid[i][j]][j] += dp[i][j];

					// Go right if we can.
					if (j+grid[i][j] < n) dp[i][j+grid[i][j]] += dp[i][j];
				}
			}

			// Result is in bottom right corner.
			System.out.println(dp[n-1][n-1]);

			// Go to next case.
			n = stdin.nextInt();
		}
	}
}