import Foundation
let n = Int(readLine()!)!
var matrix: [[Int]] = []
(0..<n).forEach { _ in
let row = readLine()?.split(separator: " ").map{ Int(String($0))! }
matrix.append(row!)
}
var table = Array(repeating: Array(repeating: -1, count: n), count: n)
func travel(y: Int, x: Int) -> Int {
if y == n - 1 && x == n - 1 { return 1 }
else if (table[y][x] == -1) {
let dy = [1, 0]
let dx = [0, 1]
let s = matrix[y][x]
table[y][x] = 0
for i in (0..<2) {
let ny = dy[i] * s + y
let nx = dx[i] * s + x
if ny < n && nx < n {
table[y][x] += travel(y: ny, x: nx)
}
}
}
return table[y][x]
}
print(travel(y: 0, x: 0))
참고 : https://www.acmicpc.net/problem/1890