Buggy python submission (verdict: Runtime Error):
import sys
from math import *
from collections import deque, Counter, defaultdict
from fractions import gcd
input = lambda: sys.stdin.readline().rstrip()

def eprint(s):
    sys.stderr.write('DEBUG: {}'.format(s))
    return

""" 
参考:http://drken1215.hatenablog.com/entry/2018/06/08/210000
maximとmodを適宜設定。
あ入力忘れを考慮してあえて入力例通らないようにしておいたで。

combを使う前にcominit()を使う

"""
maxim = 10**6 + 10
mod = 10**9+7
fac = [None] * maxim
finv = [None] * maxim
inv = [None] * maxim

def cominit():
    fac[0], fac[1] = 1, 1
    finv[0], finv[1] = 1, 1
    inv[1] = 1

    for i in range(2, maxim):
        fac[i] = fac[i-1] * i % mod
        inv[i] = mod - inv[mod % i] * (mod // i) % mod
        finv[i] = finv[i-1] * inv[i] % mod

def com(n, k):
    if (n < k):
        return 0
    if (n < 0 or k < 0):
        return 0

    return fac[n] * (finv[k] * finv[n - k] % mod) % mod


def main():
    x,y = map(int, input().split())
    if (x+y) % 3 != 0 or x/2 > y or y > 2*x:
        print(0)
        return

    # (x+y) // 3で何段目かわかる
    # パスカルの三角形で言うところのハジから何番目かがわかればいい

    # k段目の点は -x + 3*k上にある
    # 2*xが一番端にある
    
    k = (x+y) // 3
    # k段目の上端は (k, 2k)に存在する
    # 左から何番目かは2*k -yで求まる
    # 解は kC2*k-y

    cominit()
    m = (2*y-x)//3
    n = m+x-y
    
    print(comb(m+n,n))

    return

if __name__ == '__main__':
    main()

Fixed submission:
from math import factorial
import sys

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

maxim = 10**6+10
mod = 10**9 + 7

fac = [None] * maxim
finv = [None] * maxim
inv = [None] * maxim

def cominit():
    fac[0], fac[1] = 1, 1
    finv[0], finv[1] = 1, 1
    inv[1] = 1

    for i in range(2, maxim):
        fac[i] = fac[i-1] * i % mod
        inv[i] = mod - inv[mod % i] * (mod // i) % mod
        finv[i] = finv[i-1] * inv[i] % mod

def com(n, k):
    if (n < k):
        return 0
    if (n < 0 or k < 0):
        return 0
    return fac[n] * (finv[k] * finv[n - k] % mod) % mod


def main():
    if (x + y) % 3 != 0:
        return 0
    else:

        b = (2*y - x) // 3 
        a = b + x -y
        if a < 0 or b < 0:
            print(0)
            sys.exit()
        
        cominit()
        ans = com(a+b, b)
        return ans 
    # answer = (a+b)! / a!b! mod 10^9+7


    
print(main())

# 999999 999999

Buggy python submission (verdict: Runtime Error):
import sys
from math import *
from collections import deque, Counter, defaultdict
from fractions import gcd
input = lambda: sys.stdin.readline().rstrip()

def eprint(s):
    sys.stderr.write('DEBUG: {}'.format(s))
    return

""" 
参考:http://drken1215.hatenablog.com/entry/2018/06/08/210000
maximとmodを適宜設定。
あ入力忘れを考慮してあえて入力例通らないようにしておいたで。

combを使う前にcominit()を使う

"""
maxim = 10**6 + 10
mod = 10**9+7
fac = [None] * maxim
finv = [None] * maxim
inv = [None] * maxim

def cominit():
    fac[0], fac[1] = 1, 1
    finv[0], finv[1] = 1, 1
    inv[1] = 1

    for i in range(2, maxim):
        fac[i] = fac[i-1] * i % mod
        inv[i] = mod - inv[mod % i] * (mod // i) % mod
        finv[i] = finv[i-1] * inv[i] % mod

def com(n, k):
    if (n < k):
        return 0
    if (n < 0 or k < 0):
        return 0

    return fac[n] * (finv[k] * finv[n - k] % mod) % mod


def main():
    x,y = map(int, input().split())
    if (x+y) % 3 != 0 or x/2 > y or y > 2*x:
        print(0)
        return

    # (x+y) // 3で何段目かわかる
    # パスカルの三角形で言うところのハジから何番目かがわかればいい

    # k段目の点は -x + 3*k上にある
    # 2*xが一番端にある

    if y < x:
        y,x = x,y
        # パスカルの三角形は左右対称
    
    k = (x+y) // 3
    # k段目の上端は (k, 2k)に存在する
    # 左から何番目かは2*k -yで求まる
    # 解は kC2*k-y

    cominit()
    m = (2*x-y)//3
    n = y-x+m
    print(comb(n+m, m))


    return

if __name__ == '__main__':
    main()

Fixed submission:
from math import factorial
import sys

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

maxim = 10**6+10
mod = 10**9 + 7

fac = [None] * maxim
finv = [None] * maxim
inv = [None] * maxim

def cominit():
    fac[0], fac[1] = 1, 1
    finv[0], finv[1] = 1, 1
    inv[1] = 1

    for i in range(2, maxim):
        fac[i] = fac[i-1] * i % mod
        inv[i] = mod - inv[mod % i] * (mod // i) % mod
        finv[i] = finv[i-1] * inv[i] % mod

def com(n, k):
    if (n < k):
        return 0
    if (n < 0 or k < 0):
        return 0
    return fac[n] * (finv[k] * finv[n - k] % mod) % mod


def main():
    if (x + y) % 3 != 0:
        return 0
    else:

        b = (2*y - x) // 3 
        a = b + x -y
        if a < 0 or b < 0:
            print(0)
            sys.exit()
        
        cominit()
        ans = com(a+b, b)
        return ans 
    # answer = (a+b)! / a!b! mod 10^9+7


    
print(main())

# 999999 999999

Buggy python submission (verdict: Runtime Error):
import sys
from math import *
from collections import deque, Counter, defaultdict
from fractions import gcd
input = lambda: sys.stdin.readline().rstrip()

def eprint(s):
    sys.stderr.write('DEBUG: {}'.format(s))
    return

""" 
参考:http://drken1215.hatenablog.com/entry/2018/06/08/210000
maximとmodを適宜設定。
あ入力忘れを考慮してあえて入力例通らないようにしておいたで。

combを使う前にcominit()を使う

"""
maxim = 10**6 + 10
mod = 10**9+7
fac = [None] * maxim
finv = [None] * maxim
inv = [None] * maxim

def cominit():
    fac[0], fac[1] = 1, 1
    finv[0], finv[1] = 1, 1
    inv[1] = 1

    for i in range(2, maxim):
        fac[i] = fac[i-1] * i % mod
        inv[i] = mod - inv[mod % i] * (mod // i) % mod
        finv[i] = finv[i-1] * inv[i] % mod

def com(n, k):
    if (n < k):
        return 0
    if (n < 0 or k < 0):
        return 0

    return fac[n] * (finv[k] * finv[n - k] % mod) % mod


def main():
    x,y = map(int, input().split())
    if (x+y) % 3 != 0 or x/2 > y or y > 2*x:
        print(0)
        return

    # (x+y) // 3で何段目かわかる
    # パスカルの三角形で言うところのハジから何番目かがわかればいい

    # k段目の点は -x + 3*k上にある
    # 2*xが一番端にある

    if y < x:
        y,x = x,y
        # パスカルの三角形は左右対称
    
    k = (x+y) // 3
    # k段目の上端は (k, 2k)に存在する
    # 左から何番目かは2*k -yで求まる
    # 解は kC2*k-y

    cominit()
    print(comb(k, 2*k-y))


    return

if __name__ == '__main__':
    main()

Fixed submission:
from math import factorial
import sys

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

maxim = 10**6+10
mod = 10**9 + 7

fac = [None] * maxim
finv = [None] * maxim
inv = [None] * maxim

def cominit():
    fac[0], fac[1] = 1, 1
    finv[0], finv[1] = 1, 1
    inv[1] = 1

    for i in range(2, maxim):
        fac[i] = fac[i-1] * i % mod
        inv[i] = mod - inv[mod % i] * (mod // i) % mod
        finv[i] = finv[i-1] * inv[i] % mod

def com(n, k):
    if (n < k):
        return 0
    if (n < 0 or k < 0):
        return 0
    return fac[n] * (finv[k] * finv[n - k] % mod) % mod


def main():
    if (x + y) % 3 != 0:
        return 0
    else:

        b = (2*y - x) // 3 
        a = b + x -y
        if a < 0 or b < 0:
            print(0)
            sys.exit()
        
        cominit()
        ans = com(a+b, b)
        return ans 
    # answer = (a+b)! / a!b! mod 10^9+7


    
print(main())

# 999999 999999

Buggy python submission (verdict: Time Limit Exceeded):
import sys
from math import *
from collections import deque, Counter, defaultdict
from fractions import gcd
input = lambda: sys.stdin.readline().rstrip()

def eprint(s):
    sys.stderr.write('DEBUG: {}'.format(s))
    return

""" 
参考:http://drken1215.hatenablog.com/entry/2018/06/08/210000
maximとmodを適宜設定。
あ入力忘れを考慮してあえて入力例通らないようにしておいたで。

combを使う前にcominit()を使う

"""
maxim = 10**7
mod = 10**9+7
fac = [None] * maxim
finv = [None] * maxim
inv = [None] * maxim

def cominit():
    fac[0], fac[1] = 1, 1
    finv[0], finv[1] = 1, 1
    inv[1] = 1

    for i in range(2, maxim):
        fac[i] = fac[i-1] * i % mod
        inv[i] = mod - inv[mod % i] * (mod // i) % mod
        finv[i] = finv[i-1] * inv[i] % mod

def com(n, k):
    if (n < k):
        return 0
    if (n < 0 or k < 0):
        return 0
    return fac[n] * (finv[k] * finv[n - k] % mod) % mod


def main():
    x,y = map(int, input().split())
    if (x+y) % 3 != 0 or x/2 > y or y > 2*x:
        print(0)
        return

    # (x+y) // 3で何段目かわかる
    # パスカルの三角形で言うところのハジから何番目かがわかればいい

    # k段目の点は -x + 3*k上にある
    # 2*xが一番端にある

    if y < x:
        y,x = x,y
        # パスカルの三角形は左右対称
    
    k = (x+y) // 3
    # k段目の上端は (k, 2k)に存在する
    # 左から何番目かは2*k -yで求まる
    # 解は kC2*k-y

    cominit()
    print(comb(k, 2*k-y))


    return

if __name__ == '__main__':
    main()

Fixed submission:
from math import factorial
import sys

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

maxim = 10**6+10
mod = 10**9 + 7

fac = [None] * maxim
finv = [None] * maxim
inv = [None] * maxim

def cominit():
    fac[0], fac[1] = 1, 1
    finv[0], finv[1] = 1, 1
    inv[1] = 1

    for i in range(2, maxim):
        fac[i] = fac[i-1] * i % mod
        inv[i] = mod - inv[mod % i] * (mod // i) % mod
        finv[i] = finv[i-1] * inv[i] % mod

def com(n, k):
    if (n < k):
        return 0
    if (n < 0 or k < 0):
        return 0
    return fac[n] * (finv[k] * finv[n - k] % mod) % mod


def main():
    if (x + y) % 3 != 0:
        return 0
    else:

        b = (2*y - x) // 3 
        a = b + x -y
        if a < 0 or b < 0:
            print(0)
            sys.exit()
        
        cominit()
        ans = com(a+b, b)
        return ans 
    # answer = (a+b)! / a!b! mod 10^9+7


    
print(main())

# 999999 999999

Buggy python submission (verdict: Runtime Error):
import sys
from math import *
from collections import deque, Counter, defaultdict
from fractions import gcd
input = lambda: sys.stdin.readline().rstrip()

def eprint(s):
    sys.stderr.write('DEBUG: {}'.format(s))
    return

""" 
参考:http://drken1215.hatenablog.com/entry/2018/06/08/210000
maximとmodを適宜設定。
あ入力忘れを考慮してあえて入力例通らないようにしておいたで。

combを使う前にcominit()を使う

"""
maxim = 10**6 + 10
mod = 10**9+7
fac = [None] * maxim
finv = [None] * maxim
inv = [None] * maxim

def cominit():
    fac[0], fac[1] = 1, 1
    finv[0], finv[1] = 1, 1
    inv[1] = 1

    for i in range(2, maxim):
        fac[i] = fac[i-1] * i % mod
        inv[i] = mod - inv[mod % i] * (mod // i) % mod
        finv[i] = finv[i-1] * inv[i] % mod

def com(n, k):
    if (n < k):
        return 0
    if (n < 0 or k < 0):
        return 0
    return fac[n] * (finv[k] * finv[n - k] % mod) % mod


def main():
    x,y = map(int, input().split())
    if (x+y) % 3 != 0 or x/2 > y or y > 2*x:
        print(0)
        return

    # (x+y) // 3で何段目かわかる
    # パスカルの三角形で言うところのハジから何番目かがわかればいい

    # k段目の点は -x + 3*k上にある
    # 2*xが一番端にある

    if y < x:
        y,x = x,y
        # パスカルの三角形は左右対称
    
    k = (x+y) // 3
    # k段目の上端は (k, 2k)に存在する
    # 左から何番目かは2*k -yで求まる
    # 解は kC2*k-y

    cominit()
    print(comb(k, 2*k-y))


    return

if __name__ == '__main__':
    main()

Fixed submission:
from math import factorial
import sys

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

maxim = 10**6+10
mod = 10**9 + 7

fac = [None] * maxim
finv = [None] * maxim
inv = [None] * maxim

def cominit():
    fac[0], fac[1] = 1, 1
    finv[0], finv[1] = 1, 1
    inv[1] = 1

    for i in range(2, maxim):
        fac[i] = fac[i-1] * i % mod
        inv[i] = mod - inv[mod % i] * (mod // i) % mod
        finv[i] = finv[i-1] * inv[i] % mod

def com(n, k):
    if (n < k):
        return 0
    if (n < 0 or k < 0):
        return 0
    return fac[n] * (finv[k] * finv[n - k] % mod) % mod


def main():
    if (x + y) % 3 != 0:
        return 0
    else:

        b = (2*y - x) // 3 
        a = b + x -y
        if a < 0 or b < 0:
            print(0)
            sys.exit()
        
        cominit()
        ans = com(a+b, b)
        return ans 
    # answer = (a+b)! / a!b! mod 10^9+7


    
print(main())

# 999999 999999

Buggy python submission (verdict: Runtime Error):
import math
import numpy as np

def comb(n,k,p):
  """power_funcを用いて(nCk) mod p を求める"""
  from math import factorial
  if n<0 or k<0 or n<k: return 0
  if n==0 or k==0: return 1
  a=calc(np.math.factorial(n)) %p
  b=calc(np.math.factorial(k)) %p
  c=calc(np.math.factorial(n-k)) %p
  return (a*power_func(b,p-2,p)*power_func(c,p-2,p))%p
def power_func(a,b,p):
  """a^b mod p を求める"""
  if b==0: return 1
  if b%2==0:
    d=power_func(a,b//2,p)
    return d*d %p
  if b%2==1:
    return (a*power_func(a,b-1,p ))%p
 
x, y = map(int, input().split())

if (x + y) % 3 != 0:
    ans = 0
else:

    b = (2*y - x) / 3 
    a = b + x -y

    

    ans = comb(a+b, b, 1000000007)

    # answer = (a+b)! / a!b! mod 10^9+7

    
print(ans)

# 999999 999999


Fixed submission:
from math import factorial
import sys

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

maxim = 10**6+10
mod = 10**9 + 7

fac = [None] * maxim
finv = [None] * maxim
inv = [None] * maxim

def cominit():
    fac[0], fac[1] = 1, 1
    finv[0], finv[1] = 1, 1
    inv[1] = 1

    for i in range(2, maxim):
        fac[i] = fac[i-1] * i % mod
        inv[i] = mod - inv[mod % i] * (mod // i) % mod
        finv[i] = finv[i-1] * inv[i] % mod

def com(n, k):
    if (n < k):
        return 0
    if (n < 0 or k < 0):
        return 0
    return fac[n] * (finv[k] * finv[n - k] % mod) % mod


def main():
    if (x + y) % 3 != 0:
        return 0
    else:

        b = (2*y - x) // 3 
        a = b + x -y
        if a < 0 or b < 0:
            print(0)
            sys.exit()
        
        cominit()
        ans = com(a+b, b)
        return ans 
    # answer = (a+b)! / a!b! mod 10^9+7


    
print(main())

# 999999 999999

Buggy python submission (verdict: Runtime Error):
import math
import numpy as np

def comb(n,k,p):
  """power_funcを用いて(nCk) mod p を求める"""
  from math import factorial
  if n<0 or k<0 or n<k: return 0
  if n==0 or k==0: return 1
  a=np.math.factorial(n) %p
  b=np.math.factorial(k) %p
  c=np.math.factorial(n-k) %p
  return (a*power_func(b,p-2,p)*power_func(c,p-2,p))%p
def power_func(a,b,p):
  """a^b mod p を求める"""
  if b==0: return 1
  if b%2==0:
    d=power_func(a,b//2,p)
    return d*d %p
  if b%2==1:
    return (a*power_func(a,b-1,p ))%p
 
x, y = map(int, input().split())

if (x + y) % 3 != 0:
    ans = 0
else:

    b = (2*y - x) / 3 
    a = b + x -y

    

    ans = comb(a+b, b, 1000000007)

    # answer = (a+b)! / a!b! mod 10^9+7

    
print(ans)

# 999999 999999


Fixed submission:
from math import factorial
import sys

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

maxim = 10**6+10
mod = 10**9 + 7

fac = [None] * maxim
finv = [None] * maxim
inv = [None] * maxim

def cominit():
    fac[0], fac[1] = 1, 1
    finv[0], finv[1] = 1, 1
    inv[1] = 1

    for i in range(2, maxim):
        fac[i] = fac[i-1] * i % mod
        inv[i] = mod - inv[mod % i] * (mod // i) % mod
        finv[i] = finv[i-1] * inv[i] % mod

def com(n, k):
    if (n < k):
        return 0
    if (n < 0 or k < 0):
        return 0
    return fac[n] * (finv[k] * finv[n - k] % mod) % mod


def main():
    if (x + y) % 3 != 0:
        return 0
    else:

        b = (2*y - x) // 3 
        a = b + x -y
        if a < 0 or b < 0:
            print(0)
            sys.exit()
        
        cominit()
        ans = com(a+b, b)
        return ans 
    # answer = (a+b)! / a!b! mod 10^9+7


    
print(main())

# 999999 999999

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

def comb(n,k,p):
  """power_funcを用いて(nCk) mod p を求める"""
  from math import factorial
  if n<0 or k<0 or n<k: return 0
  if n==0 or k==0: return 1
  a=factorial(n) %p
  b=factorial(k) %p
  c=factorial(n-k) %p
  return (a*power_func(b,p-2,p)*power_func(c,p-2,p))%p
def power_func(a,b,p):
  """a^b mod p を求める"""
  if b==0: return 1
  if b%2==0:
    d=power_func(a,b//2,p)
    return d*d %p
  if b%2==1:
    return (a*power_func(a,b-1,p ))%p
 
x, y = map(int, input().split())

if (x + y) % 3 != 0:
    ans = 0
else:

    b = (2*y - x) / 3 
    a = b + x -y

    

    ans = comb(a+b, b, 1000000007)

    # answer = (a+b)! / a!b! mod 10^9+7

    
print(ans)

# 999999 999999


Fixed submission:
from math import factorial
import sys

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

maxim = 10**6+10
mod = 10**9 + 7

fac = [None] * maxim
finv = [None] * maxim
inv = [None] * maxim

def cominit():
    fac[0], fac[1] = 1, 1
    finv[0], finv[1] = 1, 1
    inv[1] = 1

    for i in range(2, maxim):
        fac[i] = fac[i-1] * i % mod
        inv[i] = mod - inv[mod % i] * (mod // i) % mod
        finv[i] = finv[i-1] * inv[i] % mod

def com(n, k):
    if (n < k):
        return 0
    if (n < 0 or k < 0):
        return 0
    return fac[n] * (finv[k] * finv[n - k] % mod) % mod


def main():
    if (x + y) % 3 != 0:
        return 0
    else:

        b = (2*y - x) // 3 
        a = b + x -y
        if a < 0 or b < 0:
            print(0)
            sys.exit()
        
        cominit()
        ans = com(a+b, b)
        return ans 
    # answer = (a+b)! / a!b! mod 10^9+7


    
print(main())

# 999999 999999

Buggy python submission (verdict: Runtime Error):
import math

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

if (x + y) % 3 != 0:
    ans = 0
else:

    b = (2*y - x) / 3 
    a = b + x -y

    a_b = math.factorial(a+b)
    ab = math.factorial(a)* math.factorial(b) % 1000000007
    

    ans = (a_b // ab) % 1000000007

    # answer = (a+b)! / a!b! mod 10^9+7

    
print(ans)

# 999999 999999

Fixed submission:
from math import factorial
import sys

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

maxim = 10**6+10
mod = 10**9 + 7

fac = [None] * maxim
finv = [None] * maxim
inv = [None] * maxim

def cominit():
    fac[0], fac[1] = 1, 1
    finv[0], finv[1] = 1, 1
    inv[1] = 1

    for i in range(2, maxim):
        fac[i] = fac[i-1] * i % mod
        inv[i] = mod - inv[mod % i] * (mod // i) % mod
        finv[i] = finv[i-1] * inv[i] % mod

def com(n, k):
    if (n < k):
        return 0
    if (n < 0 or k < 0):
        return 0
    return fac[n] * (finv[k] * finv[n - k] % mod) % mod


def main():
    if (x + y) % 3 != 0:
        return 0
    else:

        b = (2*y - x) // 3 
        a = b + x -y
        if a < 0 or b < 0:
            print(0)
            sys.exit()
        
        cominit()
        ans = com(a+b, b)
        return ans 
    # answer = (a+b)! / a!b! mod 10^9+7


    
print(main())

# 999999 999999

Buggy python submission (verdict: Runtime Error):
import math

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

if (x + y) % 3 != 0:
    ans = 0
else:

    b = (2*y - x) / 3 
    a = b + x -y

    a_b = math.factorial(a+b)
    ab = math.factorial(a)* math.factorial(b)
    

    ans = (a_b // ab) % 1000000007

    # answer = (a+b)! / a!b! mod 10^9+7

    
print(ans)

Fixed submission:
from math import factorial
import sys

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

maxim = 10**6+10
mod = 10**9 + 7

fac = [None] * maxim
finv = [None] * maxim
inv = [None] * maxim

def cominit():
    fac[0], fac[1] = 1, 1
    finv[0], finv[1] = 1, 1
    inv[1] = 1

    for i in range(2, maxim):
        fac[i] = fac[i-1] * i % mod
        inv[i] = mod - inv[mod % i] * (mod // i) % mod
        finv[i] = finv[i-1] * inv[i] % mod

def com(n, k):
    if (n < k):
        return 0
    if (n < 0 or k < 0):
        return 0
    return fac[n] * (finv[k] * finv[n - k] % mod) % mod


def main():
    if (x + y) % 3 != 0:
        return 0
    else:

        b = (2*y - x) // 3 
        a = b + x -y
        if a < 0 or b < 0:
            print(0)
            sys.exit()
        
        cominit()
        ans = com(a+b, b)
        return ans 
    # answer = (a+b)! / a!b! mod 10^9+7


    
print(main())

# 999999 999999