Problem Statement
Windra has an by grid of positive integers . Windra starts at the top left (which contains ). Windra will then make a series of moves, he has two choices for each move, if he is at coordinate he can:
- Move to coordinate
- Move to coordinate
Note that some moves may go off the grid.
Windra's evil twin, Bindra, plots to kill Windra by setting him on a path that goes off the grid. Bindra would like to know how many paths go off the grid.
Input Format
Your first line will contain a single integer . Your next lines will contain integers each, representing your row of integers in .
Output Format
You should output a single integer representing the number of paths off the grid.
Constraints
- ## Template
n = int(input())
a = [list(map(int, input().split())) for _ in range(n)]
# print your output
Sample Cases
Input 1
2
1 1
1 1
Output 1
6
Explanation 1
There are the following paths:
- Down, down
- Down, right, down
- Down, right, right
- Right, down, down
- Right, down, right
- Right, right ### Input 2
5
2 1 1 1 1
1 1 2 1 3
1 1 1 1 1
1 1 1 2 1
4 1 1 1 1
Output 2
55
Input 3
5
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 2 2
1 1 1 2 1
Output 3
112
Comments