Problem p02862 (python)

Fixed submission:
def ext_gcd(p, a):
  #require a, m be relative prime
  #m > a  
  if a == 0:
    return 1, 0
  else:
    x1, y1 = ext_gcd(a, p%a)
    y = x1 - y1 * int(p/a)
    x = y1
    return x, y

x, y = map(int, input().split())

n = (2 * y - x)/3
m = (2 * x - y)/3

if n != int(n) or m != int(m) or n<0 or m<0:
  ans = 0
else:
   n = int(n)
   m = int(m)
   if n < m :
      c = m
      m = n
      n = c
   # (n+m!)/(n!)(m!) mod (1e9+7)
   ans = 1
   prime = 1000000007 
   for i in range(n+1,m+n+1):
        ans = int(ans * i) 
        ans = (ans % prime)
   for i in range(1, m+1):
      ori_inv = int(ext_gcd(prime, i)[1])
      while ori_inv < 0 :
        ori_inv += prime
      ans = int(ans * ori_inv)  
      ans = (ans % prime)
print(ans)

Buggy submission (verdict: Runtime Error):
def ext_gcd(p, a):
  #require a, m be relative prime
  #m > a  
  if a == 0:
    return 1, 0
  else:
    x1, y1 = ext_gcd(a, p%a)
    y = x1 - y1 * int(p/a)
    x = y1
    return x, y

x, y = map(int, input().split())

n = (-1/3)*x + (2/3)*y
m = (-1/3)*y + (2/3)*x

if n != int(n) or m != int(m) or n<0 or m<0:
  ans = 0
else:
   n = int(n)
   m = int(m)
   if n < m :
      m = c
      m = n
      n = c
   # (n+m!)/(n!)(m!) mod (1e9+7)
   ans = 1
   prime = 1000000007 
   for i in range(n+1,m+n+1):
        ans = int(ans * i) 
        ans = (ans % prime)
   for i in range(1, m+1):
      ori_inv = int(ext_gcd(prime, i)[1])
      while ori_inv < 0 :
        ori_inv += prime
      ans = int(ans * ori_inv)  
      ans = (ans % prime)
print(ans)

Buggy submission (verdict: Runtime Error):
def ext_gcd(m, a):
  #require a, m be relative prime
  #m > a  
  if m < a:
    assert ('error')
  elif a == 0:
    return 1, 0
  else:
    x1, y1 = ext_gcd(a, m%a)
    y = x1 - y1 * int(m/a)
    x = y1
    return x, y

x, y = map(int, input().split())

n = (-1/3)*x + (2/3)*y
m = (-1/3)*y + (2/3)*x

if n != int(n) or m != int(m) or n<0 or m<0:
  ans = 0
else:
   n = int(n)
   m = int(m)
   if n < m :
      m = c
      m = n
      n = c
   # (n+m!)/(n!)(m!) mod (1e9+7)
   ans = 1
   prime = 1000000007 
   for i in range(n+1,m+n+1):
        ans = int(ans * i) 
        ans = (ans % prime)
   for i in range(1, m+1):
      ori_inv = int(ext_gcd(prime, i)[1])
      while ori_inv < 0 :
        ori_inv += prime
      ans = int(ans * ori_inv)  
      ans = (ans % prime)
print(ans)

Buggy submission (verdict: Runtime Error):
def ext_gcd(m, a):
  #require a, m be relative prime
  #m > a  
  if m < a:
    assert ('error')
  elif a == 0:
    return 1, 0
  else:
    x1, y1 = ext_gcd(a, m%a)
    y = x1 - y1 * int(m/a)
    x = y1
    return x, y

x, y = map(int, input().split())

n = (-1/3)*x + (2/3)*y
m = (-1/3)*y + (2/3)*x

if n != int(n) or m != int(m) or n<0 or m<0:
  ans = 0
else:
   n = int(n)
   m = int(m)
   if n < m :
      m = c
      m = n
      n = c
   # (n+m!)/(n!)(m!) mod (1e9+7)
   ans = 1
   prime = 1000000007 
   for i in range(n+1,m+n+1):
        ans = int(ans * i) 
        ans = (ans % prime)
   for i in range(1, m+1):
      ori_inv = int(ext_gcd(prime, i)[1])
      while ori_inv < 0 :
        ori_inv += prime
      assert int(ori_inv * i) % prime == 1
      ans = int(ans * ori_inv)  
      ans = (ans % prime)
print(ans)

Buggy submission (verdict: Runtime Error):
import numpy as np
x, y = map(int, input().split())
table = np.ones((x+1, y+1)) * -1

for i in range(x):
  table[i,0] = 0
for j in range(y):
  table[0,j] = 0
table[0,0] = 1


for i in range(1,x+1):
  for j in range(1,y+1):
     a1 = 0
     a2 = 0
     if i-1 >= 0 and  j-2 >= 0:
        a1 = table[i-1, j-2]
     if i-2 >= 0 and  j-1 >= 0:
      	a2 = table[i-2,j-1]
     table[i,j] = a1 + a2

print(int(table[x,y] % (1e9+7)))

Buggy submission (verdict: Runtime Error):
import numpy as np
x, y = map(int, input().split())
table = np.zeros((x+1, y+1))
for i in range(x):
  table[i,0] = 0
for j in range(y):
  table[0,j] = 0
table[0,0] = 1



#if table is not global but pass to function will this work?
def knight(x,y):
  if x >= 0 and y >= 0:
    if table[x,y] != -1:
      return table[x,y]
    else:
      ans = knight(x-2, y-1) + knight(x-1, y-2)
      table[x,y] = ans
      return ans
  else:
    return 0
ans = knight(x, y)
print(int(ans % (1e9+7)))