map int input split for in range append for in range append y-2 while

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
x,y = map(int,input().split())
a = []
for i in range(x):
a.append([])
for j in range(y):
a[i].append(0)
a[0][0] = 1
k = x+y-2
l = 1
while k >= l:
i = l+1
while i >= 0:
i -= 1
j = l-i
if x > i > -1 and y > j > -1:
if j-1>=0 and i-2>=0: a[i][j] = a[i][j]+a[i-2][j-1]
if j+1<y and i-2>=0: a[i][j] = a[i][j]+a[i-2][j+1]
if j-2>=0 and i-1>=0: a[i][j] = a[i][j]+a[i-1][j-2]
if j-2>=0 and i+1<x: a[i][j] = a[i][j]+a[i+1][j-2]
l += 1
print(a[-1][-1]%1000007)