Buggy python submission (verdict: Runtime Error):
def cmb(n, k, mod, fac, infac):
  k = min(k,n-k)
  return fac[n] * infac[k] * infac[n-k] % mod

def tables(mod, n):
  fac = [1, 1] 
  infac = [1, 1] 
  inverse = [0, 1] 
  for i in range(2, n+1):
    fac.append((fac[-1] * i) % mod)
    inverse.append((-inverse[mod % i] * (mod // i)) % mod)
    infac.append((infac[-1] * inverse[-1]) % mod)
  return fac,infac

X,Y = map(int, input().split())

if X > Y:
  X, Y = Y, X

move = X + Y

if move % 3 != 0:
  print(0)
else:
  total = move // 3
  n = X - total
  
  if n > 0:
    print(0)
  else:
    MOD = 10 ** 9 + 7
    fac, infac = tables(MOD, total)
    ans = cmb(total, n, MOD, fac, infac)
    
    print(ans)

Fixed submission:
def cmb(n, k, mod, fac, infac):
  k = min(k,n-k)
  return fac[n] * infac[k] * infac[n-k] % mod

def tables(mod, n):
  fac = [1, 1] 
  infac = [1, 1] 
  inverse = [0, 1] 
  for i in range(2, n+1):
    fac.append((fac[-1] * i) % mod)
    inverse.append((-inverse[mod % i] * (mod // i)) % mod)
    infac.append((infac[-1] * inverse[-1]) % mod)
  return fac,infac

X,Y = map(int, input().split())

if X > Y:
  X, Y = Y, X

move = X + Y

if move % 3 != 0:
  print(0)
else:
  total = move // 3
  n = X - total
  
  if n < 0:
    print(0)
    
  else:
    MOD = 10 ** 9 + 7
    fac, infac = tables(MOD, total)
    ans = cmb(total, n, MOD, fac, infac)
    
    print(ans)

Buggy python submission (verdict: Runtime Error):
import math
from scipy.special import comb

#def permod(n, r):
  #return (math.factorial(n) // math.factorial(n - r)) % (10 ** 9 + 7)

from operator import mul
from functools import reduce

def com(n, r):
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom

def main():
  X,Y = map(int,input().split())
  
  if (X + Y) % 3 != 0:
    print(0)
    
  else:
    a = Y - (X + Y) // 3
    b = X - (X + Y) // 3
    
    ans = com(a + b,b)
    
    print(ans)
    
main()

Fixed submission:
def cmb(n, k, mod, fac, infac):
  k = min(k,n-k)
  return fac[n] * infac[k] * infac[n-k] % mod

def tables(mod, n):
  fac = [1, 1] 
  infac = [1, 1] 
  inverse = [0, 1] 
  for i in range(2, n+1):
    fac.append((fac[-1] * i) % mod)
    inverse.append((-inverse[mod % i] * (mod // i)) % mod)
    infac.append((infac[-1] * inverse[-1]) % mod)
  return fac,infac

X,Y = map(int, input().split())

if X > Y:
  X, Y = Y, X

move = X + Y

if move % 3 != 0:
  print(0)
else:
  total = move // 3
  n = X - total
  
  if n < 0:
    print(0)
    
  else:
    MOD = 10 ** 9 + 7
    fac, infac = tables(MOD, total)
    ans = cmb(total, n, MOD, fac, infac)
    
    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import math
from scipy.misc import comb

#def permod(n, r):
  #return (math.factorial(n) // math.factorial(n - r)) % (10 ** 9 + 7)

def main():
  X,Y = map(int,input().split())
  
  if (X + Y) % 3 != 0:
    print(0)
    
  else:
    a = Y - (X + Y) // 3
    b = X - (X + Y) // 3
    
    total = a + b
    m = min(a,b)
    
    ans = comb(total,m,exact = True)
    print(ans)
    
main()

Fixed submission:
def cmb(n, k, mod, fac, infac):
  k = min(k,n-k)
  return fac[n] * infac[k] * infac[n-k] % mod

def tables(mod, n):
  fac = [1, 1] 
  infac = [1, 1] 
  inverse = [0, 1] 
  for i in range(2, n+1):
    fac.append((fac[-1] * i) % mod)
    inverse.append((-inverse[mod % i] * (mod // i)) % mod)
    infac.append((infac[-1] * inverse[-1]) % mod)
  return fac,infac

X,Y = map(int, input().split())

if X > Y:
  X, Y = Y, X

move = X + Y

if move % 3 != 0:
  print(0)
else:
  total = move // 3
  n = X - total
  
  if n < 0:
    print(0)
    
  else:
    MOD = 10 ** 9 + 7
    fac, infac = tables(MOD, total)
    ans = cmb(total, n, MOD, fac, infac)
    
    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import math

def permod(n, r):
  return (math.factorial(n) // math.factorial(n - r)) % (10 ** 9 + 7)

def main():
  X,Y = map(int,input().split())
  
  if (X + Y) % 3 != 0:
    print(0)
    
  else:
    a = Y - (X + Y) // 3
    b = X - (X + Y) // 3
    
    total = a + b
    m = min(a,b)
    
    ans = permod(total,m)
    print(ans)
    
main()

Fixed submission:
def cmb(n, k, mod, fac, infac):
  k = min(k,n-k)
  return fac[n] * infac[k] * infac[n-k] % mod

def tables(mod, n):
  fac = [1, 1] 
  infac = [1, 1] 
  inverse = [0, 1] 
  for i in range(2, n+1):
    fac.append((fac[-1] * i) % mod)
    inverse.append((-inverse[mod % i] * (mod // i)) % mod)
    infac.append((infac[-1] * inverse[-1]) % mod)
  return fac,infac

X,Y = map(int, input().split())

if X > Y:
  X, Y = Y, X

move = X + Y

if move % 3 != 0:
  print(0)
else:
  total = move // 3
  n = X - total
  
  if n < 0:
    print(0)
    
  else:
    MOD = 10 ** 9 + 7
    fac, infac = tables(MOD, total)
    ans = cmb(total, n, MOD, fac, infac)
    
    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import math

X,Y = map(int,input().split())

if (X + Y) % 3 != 0:
  print(0)
  
else:
  a = Y - (X + Y) // 3
  b = X - (X + Y) // 3
  total = a + b
  m = min(a,b)
  def permod(n, r):
    return (math.factorial(n) // math.factorial(n - r)) % (10 ** 9 + 7)
  
  ans = permod(total,m)
  print(ans)

Fixed submission:
def cmb(n, k, mod, fac, infac):
  k = min(k,n-k)
  return fac[n] * infac[k] * infac[n-k] % mod

def tables(mod, n):
  fac = [1, 1] 
  infac = [1, 1] 
  inverse = [0, 1] 
  for i in range(2, n+1):
    fac.append((fac[-1] * i) % mod)
    inverse.append((-inverse[mod % i] * (mod // i)) % mod)
    infac.append((infac[-1] * inverse[-1]) % mod)
  return fac,infac

X,Y = map(int, input().split())

if X > Y:
  X, Y = Y, X

move = X + Y

if move % 3 != 0:
  print(0)
else:
  total = move // 3
  n = X - total
  
  if n < 0:
    print(0)
    
  else:
    MOD = 10 ** 9 + 7
    fac, infac = tables(MOD, total)
    ans = cmb(total, n, MOD, fac, infac)
    
    print(ans)

Buggy python submission (verdict: Runtime Error):
from functools import reduce
from operator import mul

X,Y = map(int,input().split())

if (X + Y) % 3 != 0:
  print(0)
  
else:
  a = Y - (X + Y) // 3
  b = X - (X + Y) // 3
  total = a + b
  m = min(a,b)
  nums = [i for i in range(m,total + 1)]
  div = [i for i in range(1,m + 1)]
  M = reduce(mul,div)
  N = reduce(mul,nums) * M
  print((N // M) % (10 ** 9 + 7))
  

Fixed submission:
def cmb(n, k, mod, fac, infac):
  k = min(k,n-k)
  return fac[n] * infac[k] * infac[n-k] % mod

def tables(mod, n):
  fac = [1, 1] 
  infac = [1, 1] 
  inverse = [0, 1] 
  for i in range(2, n+1):
    fac.append((fac[-1] * i) % mod)
    inverse.append((-inverse[mod % i] * (mod // i)) % mod)
    infac.append((infac[-1] * inverse[-1]) % mod)
  return fac,infac

X,Y = map(int, input().split())

if X > Y:
  X, Y = Y, X

move = X + Y

if move % 3 != 0:
  print(0)
else:
  total = move // 3
  n = X - total
  
  if n < 0:
    print(0)
    
  else:
    MOD = 10 ** 9 + 7
    fac, infac = tables(MOD, total)
    ans = cmb(total, n, MOD, fac, infac)
    
    print(ans)

Buggy python submission (verdict: Runtime Error):
X,Y = map(int,(input().split()))

mod = 10 ** 9 + 7

def recur(x,y):
  if x == X and y == Y:
    return 1 % mod
  
  elif x > X or y > Y:
    return 0
  
  else:
    ret1 = recur(x + 1,y + 2)
    ret2 = recur(x + 2,y + 1)
    
    return ret1 + ret2
    
print(recur(0,0))

Fixed submission:
def cmb(n, k, mod, fac, infac):
  k = min(k,n-k)
  return fac[n] * infac[k] * infac[n-k] % mod

def tables(mod, n):
  fac = [1, 1] 
  infac = [1, 1] 
  inverse = [0, 1] 
  for i in range(2, n+1):
    fac.append((fac[-1] * i) % mod)
    inverse.append((-inverse[mod % i] * (mod // i)) % mod)
    infac.append((infac[-1] * inverse[-1]) % mod)
  return fac,infac

X,Y = map(int, input().split())

if X > Y:
  X, Y = Y, X

move = X + Y

if move % 3 != 0:
  print(0)
else:
  total = move // 3
  n = X - total
  
  if n < 0:
    print(0)
    
  else:
    MOD = 10 ** 9 + 7
    fac, infac = tables(MOD, total)
    ans = cmb(total, n, MOD, fac, infac)
    
    print(ans)