https://www.acmicpc.net/problem/17070
def init():
n = int(input())
board = [list(map(int, input().split())) for _ in range(n)]
dp = [[[0, 0, 0] for _ in range(n)] for _ in range(n)]
dp[0][1][0] = 1
return n, board, dp
n, board, dp = init()
for y in range(n):
for x in range(2, n):
if sum(board[y][x-1:x+1]) == 0:
dp[y][x][0] = dp[y][x-1][0] + dp[y][x-1][2]
if board[y-1][x] == 0 and board[y][x] == 0:
dp[y][x][1] = dp[y-1][x][1] + dp[y-1][x][2]
if sum(board[y-1][x-1:x+1]) + sum(board[y][x-1:x+1]) == 0:
dp[y][x][2] = sum(dp[y-1][x-1])
print(sum(dp[-1][-1]))