qyliang/CodeNanoFix huggingface dataset:
Buggy code:

def acinput():
    return list(map(int, input().split(" ")))


def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])
            #print(result)
            result%=(10**9+7)

    return result


X,Y=acinput()

import numpy as np
from numpy.linalg import solve
 

x=solve([[1,2],[2,1]],[X,Y])

#print(x)

if np.all(x%1.0==0) and np.all(x>=0):
    print(cmb(int(np.sum(x)),int(np.min(x)),10**9+7))

else:
    print(0)



Fixed code:

def acinput():
    return list(map(int, input().split(" ")))


def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])
            #print(result)
            result%=(10**9+7)

    return result


X,Y=acinput()

import numpy as np
from numpy.linalg import solve
 

x=solve([[1,2],[2,1]],[X,Y])

#print(x)

if np.all(x%1.0==0) and np.all(x>=0):
    print(cmb(int(np.sum(x)),int(np.min(x))))
    #print(cmb(int(np.sum(x)),int(np.min(x)),10**9+7))

else:
    print(0)
Buggy code:
x,y=map(int,input().split())
a=max(x,y)
b=min(x,y)
s=a-b
A=a-s-s
if A>=0 and A%3==0:
    t=A//3
    p=t+s
    q=t
    ans=1
    print(p,q)
    for i in range(q):
        ans=ans*(p+q-i)*pow((i+1),10**9+5,10**9+7)
        ans=ans%(10**9+7)
    print(ans)
else:
    print(0)

Fixed code:
x,y=map(int,input().split())
a=max(x,y)
b=min(x,y)
s=a-b
A=a-s-s
if A>=0 and A%3==0:
    t=A//3
    p=t+s
    q=t
    ans=1
    for i in range(q):
        ans=ans*(p+q-i)*pow((i+1),10**9+5,10**9+7)
        ans=ans%(10**9+7)
    print(ans)
else:
    print(0)
Buggy code:
def pow_mod(n, m, mod):
    if m == 0:
        return 1
    if m == 1:
        return n

    res = 1
    if m % 2 == 1:
        res = n

    return ((pow_mod(n * n % mod, m // 2, mod) % mod) * res) % mod


def frac_mod(n, mod):
    ans = 1
    for i in range(1, n + 1):
        ans = (ans * i) % mod
    return ans


def cmb_mod(n, r, mod):

    mul1 = frac_mod(n, mod) % mod
    mul2 = pow_mod(frac_mod(r, mod), mod - 2, mod) % mod
    mul3 = pow_mod(frac_mod(n - r, mod), mod - 2, mod) % mod

    return (((mul1 * mul2) % mod) * mul3) % mod


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

if (x + y) % 3 != 0 or (2 * x - y) % 3 != 0 or (2 * y - x) % 3 != 0:
    print(-1)
    exit(0)


mod = 10 ** 9 + 7
a = (2 * y - x) // 3
b = (2 * x - y) // 3

print(cmb_mod(a + b, a, mod))


Fixed code:
def pow_mod(n, m, mod):
    if m == 0:
        return 1
    if m == 1:
        return n

    res = 1
    if m % 2 == 1:
        res = n

    return ((pow_mod(n * n % mod, m // 2, mod) % mod) * res) % mod


def frac_mod(n, mod):
    ans = 1
    for i in range(1, n + 1):
        ans = (ans * i) % mod
    return ans


def cmb_mod(n, r, mod):

    mul1 = frac_mod(n, mod) % mod
    mul2 = pow_mod(frac_mod(r, mod), mod - 2, mod) % mod
    mul3 = pow_mod(frac_mod(n - r, mod), mod - 2, mod) % mod

    return (((mul1 * mul2) % mod) * mul3) % mod


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

if (x + y) % 3 != 0 or (2 * x - y) % 3 != 0 or (2 * y - x) % 3 != 0:
    print(0)
    exit(0)


mod = 10 ** 9 + 7
a = (2 * y - x) // 3
b = (2 * x - y) // 3

if a < 0 or b < 0:
    print(0)
    exit(0)

print(cmb_mod(a + b, a, mod))
Buggy code:
import math, sys
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque
from copy import deepcopy
from functools import lru_cache
from heapq import heapify, heappop, heappush
from itertools import accumulate, combinations, permutations
input = sys.stdin.readline
mod = 10**9 + 7
ns = lambda: input().strip()
ni = lambda: int(input().strip())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

def main():

    def fur(n,r):
        p,q = 1,1
        for i in range(r):
            p = p*(n-i)%mod
            q = q*(i+1)%mod
        return p * pow(q,mod-2,mod) % mod

    x, y = nm()

    if (x + y) % 3 != 0:
        print(0)
    
    n = (2*y - x) // 3 # (X, Y) -> (X+1, Y+2) 
    m = (2*x - y) // 3 # (X, Y) -> (X+2, Y+1) 

    print(fur(n+m, n))

if __name__ == '__main__':
    main()

Fixed code:
import math, sys
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque
from copy import deepcopy
from functools import lru_cache
from heapq import heapify, heappop, heappush
from itertools import accumulate, combinations, permutations
input = sys.stdin.readline
mod = 10**9 + 7
ns = lambda: input().strip()
ni = lambda: int(input().strip())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

def main():

    def fur(n,r):
        p,q = 1,1
        for i in range(r):
            p = p*(n-i)%mod
            q = q*(i+1)%mod
        return p * pow(q,mod-2,mod) % mod

    x, y = nm()

    if (x + y) % 3 != 0:
        print(0)
        exit()
    
    n = (2*y - x) // 3 # (X, Y) -> (X+1, Y+2) 
    m = (2*x - y) // 3 # (X, Y) -> (X+2, Y+1) 

    if n < 0 or m < 0:
        print(0)
        exit()

    print(fur(n+m, n))

if __name__ == '__main__':
    main()
Buggy code:
X,Y=map(int,input().split())

def cmb(n,k):
    x,y=1,1
    for i in range(k):
        x*=(n-i)%mod
        y*=(k-i)%mod
    return x*pow(y,mod-2,mod)%mod

if (X+Y)%3!=0:
    print(0)
else:
    m=(2*X-Y)//3
    n=(2*Y-X)//3
    if n<0 or m<0:
        print(0)
    else:
        mod=10**9+7
        ans=cmb(n+m,min(n,m))
        print(ans)

Fixed code:
X,Y=map(int,input().split())

def cmb(n,k):
    x,y=1,1
    for i in range(k):
        x = x * (n-i)%mod
        y = y * (k-i)%mod
    return x*pow(y,mod-2,mod)%mod

if (X+Y)%3!=0:
    print(0)
else:
    m=(2*X-Y)//3
    n=(2*Y-X)//3
    if n<0 or m<0:
        print(0)
    else:
        mod=10**9+7
        ans=cmb(n+m,min(n,m))
        print(ans)
Buggy code:
X, Y = map(int, input().split())
mod = 10 ** 9 + 7
if (X + Y) % 3 != 0:
    print(0)
    exit()
    
n = (2 * Y - X) // 3
m = (2 * X - Y) // 3
if n < 0 or m < 0:
    print(0)
    exit()    

ans = 1
for i in range(1, n+1):
    ans *= ((n+m+1-i) * pow(i, mod-2, mod)) % mod
print(ans%mod)

Fixed code:
X, Y = map(int, input().split())
mod = 10 ** 9 + 7
if (X + Y) % 3 != 0:
    print(0)
    exit()
    
n = (2 * Y - X) // 3
m = (2 * X - Y) // 3
if n < 0 or m < 0:
    print(0)
    exit()    

ans = 1
for i in range(1, n+1):
    ans *= (n+m+1-i) * pow(i, mod-2, mod)
    ans %= mod
    
print(ans)
Buggy code:
x, y = map(int, input().split())
MOD = 10 ** 9 + 7

if (x+y) % 3 != 0:
    print(0)
    exit()

#m: (i+2, j+1), n (i+1, j+2)

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

if m < 0 or n < 0:
    print(0)
    exit()

nume = 1
ans = 1
i = 1

while i <= n:
    nume *= m+i
    nume %= MOD
    ans *= nume * pow(i, MOD-2, MOD)
    ans %= MOD
    i += 1

print(int(ans))

Fixed code:
x, y = map(int, input().split())
MOD = 10 ** 9 + 7

if (x+y) % 3 != 0:
    print(0)
    exit()

#m: (i+2, j+1), n (i+1, j+2)

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

if m < 0 or n < 0:
    print(0)
    exit()

ans = 1
i = 1

if n > m:
    n, m = m, n

while i <= n:
    ans *= (m+i) * pow(i, MOD-2, MOD)
    ans %= MOD
    i += 1

print(ans)
Buggy code:
import math
X, Y = map(int, input().split())

MOD = 10 ** 9 + 7

xx = 2 * Y - X
if (xx % 3 == 0 and Y - 2 * xx // 3 >= 0):
    a = xx // 3
    b = Y - 2 * a

    f = 1
    factorials = [1]
    for m in range(1, a + b + 1):
        f *= m
        f %= MOD
        factorials.append(f)

    inv = pow(f, MOD - 2, MOD)
    invs = [1] * (a + b + 1)
    invs[a + b] = inv
    for m in range(a + b, 1, -1):
        inv *= m
        inv %= MOD
        invs[m - 1] = inv

    print (a, b, inv)

    print (factorials[-1] * invs[a] * invs[b] % MOD)

    # print (math.factorial(a + b) // math.factorial(a) // math.factorial(b) %  MOD)


else:
    print (0)


Fixed code:
import math
X, Y = map(int, input().split())

MOD = 10 ** 9 + 7

xx = 2 * Y - X
if (xx >= 0 and xx % 3 == 0 and Y - 2 * xx // 3 >= 0):
    a = xx // 3
    b = Y - 2 * a

    f = 1
    factorials = [1]
    for m in range(1, a + b + 1):
        f *= m
        f %= MOD
        factorials.append(f)

    inv = pow(f, MOD - 2, MOD)
    invs = [1] * (a + b + 1)
    invs[a + b] = inv
    for m in range(a + b, 1, -1):
        inv *= m
        inv %= MOD
        invs[m - 1] = inv


    print (factorials[-1] * invs[a] * invs[b] % MOD)

    # print (math.factorial(a + b) // math.factorial(a) // math.factorial(b) %  MOD)


else:
    print (0)
Buggy code:
X,Y = map(int,input().split())
mod = pow(10,9)+7
if X>Y:X,Y = Y,X
n,m = -1,-1
for i in range(X):
    if (X-i) == 2*(Y-2*i):
        n,m = i,Y-2*i
        break
if n==-1:print(n,m)
else:
    if n>m:n,m = m,n
    a,b,m=1,1,n+m
    for i in range(1,n+1):
        a=(a*m)%mod
        b=(b*i)%mod
        m-=1
    b = pow(b,mod-2,mod)
    print((a*b)%mod)

Fixed code:
X,Y = map(int,input().split())
mod = pow(10,9)+7
n,m = -1,-1
for i in range(X+1):
    if (X-i)==2*(Y-2*i):
        n,m = i,Y-2*i
if n==-1:print(0)
else:
    a,b,m = 1,1,n+m
    for i in range(1,n+1):
        a=(a*m)%mod
        b=(b*i)%mod
        m-=1
    b = pow(b,mod-2,mod)
    print((a*b)%mod)
Buggy code:
a,b = map(int, input().split())
tried = (a + b)//3
p = 10**9 +7

if a < tried or b < tried or (a+b)%3 != 0:
    print(0)
    quit()
if abs(a-b) == 0:
    one = tried//2
else:
    one = abs(a-b)
n = tried
r = min(one, tried-one)
print(n,r)
n_fac = 1
r_fac = 1
n_r_fac = 1

for i in range(2,n+1):
    n_fac *= i
    n_fac %= p
for i in range(2,r+1):
    r_fac *= i
    r_fac %= p
for i in range(2,n-r+1):
    n_r_fac *= i
    n_r_fac %= p
r_fac_inverse = pow(r_fac, p-2, p)
n_r_fac_inverse = pow(n_r_fac, p-2, p)

print((n_fac * r_fac_inverse * n_r_fac_inverse)%p)


Fixed code:
a,b = map(int, input().split())
tried = (a + b)//3
p = 10**9 +7

if a < tried or b < tried or (a+b)%3 != 0:
    print(0)
    quit()
one = int((2 * a -  b)/3)
n = tried
r = min(one, tried-one)
n_fac = 1
r_fac = 1
n_r_fac = 1

for i in range(2,n+1):
    n_fac *= i
    n_fac %= p
for i in range(2,r+1):
    r_fac *= i
    r_fac %= p
for i in range(2,n-r+1):
    n_r_fac *= i
    n_r_fac %= p
r_fac_inverse = pow(r_fac, p-2, p)
n_r_fac_inverse = pow(n_r_fac, p-2, p)

print((n_fac * r_fac_inverse * n_r_fac_inverse)%p)
Buggy code:
import sys
from math import factorial

def ncr(n, r, p): 
    # initialize numerator 
    # and denominator 
    num = den = 1 
    for i in range(r): 
        num = (num * (n - i)) % p 
        den = (den * (i + 1)) % p 
    return (num * pow(den,  
            p - 2, p)) % p 

def check(x, y):
    if x < y:
        tmp = x
        x = y
        y = tmp

    n = x - y
    x -= 2 * n

    if (x + y) % 3 == 0:
        return True
    else:
        return False
    

# Read
line = sys.stdin.readlines()[0]
X, Y = map(int,line.split(' '))

# if not check(X, Y):
#     print(0)
#     exit(0)

m = int(1/3 * (2*Y - X))
n = int(Y - 2 * m)

if n < 0 or m < 0:
    print(0)
else:
    p = m if m < n else n
    print(ncr(n+m, p))


Fixed code:
import sys
from math import factorial

def ncr(n, r, p): 
    # initialize numerator 
    # and denominator 
    num = den = 1 
    for i in range(r): 
        num = (num * (n - i)) % p 
        den = (den * (i + 1)) % p 
    return (num * pow(den,  
            p - 2, p)) % p 

def check(x, y):
    if (x + y) % 3 == 0:
        return True
    else:
        return False
    

# Read
line = sys.stdin.readlines()[0]
X, Y = map(int,line.split(' '))

if not check(X, Y):
    print(0)
    exit(0)

m = int(1/3 * (2*Y - X))
n = int(Y - 2 * m)

if n < 0 or m < 0:
    print(0)
else:
    print(ncr(n+m, n, 10**9+7))
Buggy code:
x,y=map(int,input().split())
def cal(number,mod):
    m=mod-2
    mod2=""
    while m!=0:
        if m%2==0:
            mod2="0"+mod2
        else:
            mod2="1"+mod2
        m=m//2
    two=[]
    for i in range(len(mod2)):
        if mod2[len(mod2)-1-i]=="1":
            two.append(i)
    ret=1
    for i in two:
        v=i
        retsub=number
        while v>0:
            retsub=retsub**2
            retsub=retsub%mod
            v-=1
        ret*=retsub
    ret=ret%mod
    return ret
ans=0
M=10**9+7
if (2*x-y)%3==0:
    n=(x+y)//3
    r=(2*x-y)//3
    if n<r or r<0:
        print(0)
        exit()
    l=[1]
    num=1
    for i in range(1,n+1):
        p=(num*i)%(M)
        l.append(p)
        num=p
    print(n,r)
    a=l[n]
    b=cal(l[n-r],M)
    c=cal(l[r],M)
    ans=(a*b*c)%M
print(ans)

Fixed code:
x,y=map(int,input().split())
def cal(number,mod):
    m=mod-2
    mod2=""
    while m!=0:
        if m%2==0:
            mod2="0"+mod2
        else:
            mod2="1"+mod2
        m=m//2
    two=[]
    for i in range(len(mod2)):
        if mod2[len(mod2)-1-i]=="1":
            two.append(i)
    ret=1
    for i in two:
        v=i
        retsub=number
        while v>0:
            retsub=retsub**2
            retsub=retsub%mod
            v-=1
        ret*=retsub
    ret=ret%mod
    return ret
ans=0
M=10**9+7
if (2*x-y)%3==0:
    n=(x+y)//3
    r=(2*x-y)//3
    if n<r or r<0:
        print(0)
        exit()
    l=[1]
    num=1
    for i in range(1,n+1):
        p=(num*i)%(M)
        l.append(p)
        num=p
    a=l[n]
    b=cal(l[n-r],M)
    c=cal(l[r],M)
    ans=(a*b*c)%M
print(ans)
Buggy code:
MOD = 10 ** 9 + 7

x, y = map(int, input().split())
n = int((2 * x - y) / 3)
m = int(x - 2 * n)

if (x + y) % 3 != 0:
    print(0)
    exit()

def nCr(n, r, mod):
    r = min(r, n-r)
    numer = denom = 1
    for i in range(1, r+1):
        numer = numer * (n+1-i) % mod
        denom = denom * i % mod
    return numer * pow(denom, mod-2, mod) % mod

print(n, m)
if n >= 0 and m >= 0:
    print(nCr(n + m, n, MOD))
else:
    print(0)


Fixed code:
MOD = 10 ** 9 + 7

x, y = map(int, input().split())
n = int((2 * x - y) / 3)
m = int(x - 2 * n)

if (x + y) % 3 != 0:
    print(0)
    exit()

def nCr(n, r, mod):
    r = min(r, n-r)
    numer = denom = 1
    for i in range(1, r+1):
        numer = numer * (n+1-i) % mod
        denom = denom * i % mod
    return numer * pow(denom, mod-2, mod) % mod

if n >= 0 and m >= 0:
    print(nCr(n + m, n, MOD))
else:
    print(0)
Buggy code:
def nCr(n, r, mod):
    x, y = 1, 1
    for r_ in range(1, r+1):
        x = x*(n+1-r_)%mod
        y = y*r_%mod
    return x*pow(y, mod-2, mod)%mod

x, y = map(int, input().split())
if (x+y)%3 or 2*x<y or 2*y<x:
    print(0)
else:
    print(nCr((x+y)//3,(2*x-y)//3, mod))

Fixed code:
def nCr(n, r, mod):
    x, y = 1, 1
    for r_ in range(1, r+1):
        x = x*(n+1-r_)%mod
        y = y*r_%mod
    return x*pow(y, mod-2, mod)%mod

x, y = map(int, input().split())
mod = 10**9+7
if (x+y)%3 or 2*x<y or 2*y<x:
    print(0)
else:
    print(nCr((x+y)//3,(2*x-y)//3, mod))
Buggy code:
x,y=map(int,input().split())

mod=10**9+7
def C(n, r ,mod=10**9+7):
    if n-r<r: r=n-r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k]) %mod

    return result % mod

a=(-x+2*y)//3
b=(2*x-y)//3
if a%1!=0 or b%1!=0:
    print(0) 
    exit()
print(C(a+b,a))

Fixed code:
x,y=map(int,input().split())
if (x+y)%3!=0 : 
    print(0)
    exit()

a=(2*y-x)//3
b=(2*x-y)//3
if a<0 or b<0 :
    print(0)
    exit()

def C(n, r ,mod=10**9+7):
    if n-r<r: r=n-r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k]) %mod

    return result % mod

print(C(a+b,b))
Buggy code:
import numpy as np


MOD = 10**9 + 7

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

if (X + Y) % 3 != 0:
    print(0)
if (Y < X/2) or (Y > 2*X):
    print(0)
    
h = (2 * X - Y) // 3
v = (2 * Y - X) // 3

def extgcd(a, b):
    if b == 0:
        x = 1
        y = 0
    else:
        y, x = extgcd(b, a%b)
        y -= a//b * x
    return x, y
  
def low_inverse(a):
    ret, _ = extgcd(a, MOD)
    return ret
  
def low_combination(m, n):
    # calculate (m+n)!/n!m!
    ret = 1
    numerator = m + n
    for i in range(min(m, n)):
        inv_i = low_inverse(i + 1)
        ret = ret * (numerator - i) * inv_i % MOD
    return ret
  
print(low_combination(h, v))

Fixed code:
import numpy as np


MOD = 10**9 + 7

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

if (X + Y) % 3 != 0:
    print(0)

else:
    if (Y < X/2) or (Y > 2*X):
        print(0)
    
    else:
      
        h = (2 * X - Y) // 3
        v = (2 * Y - X) // 3

        def extgcd(a, b):
            if b == 0:
                x = 1
                y = 0
            else:
                y, x = extgcd(b, a%b)
                y -= a//b * x
            return x, y

        def low_inverse(a):
            ret, _ = extgcd(a, MOD)
            return ret

        def low_combination(m, n):
            # calculate (m+n)!/n!m!
            ret = 1
            numerator = m + n
            for i in range(min(m, n)):
                inv_i = low_inverse(i + 1)
                ret = ret * (numerator - i) * inv_i % MOD
            return ret

        print(low_combination(h, v))
Buggy code:
X, Y = list(map(int, input().split()))

def f(x, p):
    a = 1
    for i in range(1, x + 1):
        a *= i
        a %= p
    return a
def nCr(a, b, p):
    if a < 0 or b < 0:
        return 0
    elif a < b:
        return 0
    c = 1
    c *= f(a, p)
    c *= pow(f(b, p), p - 2, p)
    c *= pow(f(a - b, p), p - 2, p)
    return c % p

if (2*X-Y)%3 != 0 or (2*Y-X)%3 != 0 or Y > X*2 or X > Y*2:
  print(0)
else:
  m = (2*X-Y)//3
  n = (2*Y-X)//3
  print(nCr(m+n, n))


Fixed code:
X, Y = list(map(int, input().split()))

def f(x, p):
    a = 1
    for i in range(1, x + 1):
        a *= i
        a %= p
    return a
def nCr(a, b, p):
    if a < 0 or b < 0:
        return 0
    elif a < b:
        return 0
    c = 1
    c *= f(a, p)
    c *= pow(f(b, p), p - 2, p)
    c *= pow(f(a - b, p), p - 2, p)
    return c % p

if (2*X-Y)%3 != 0 or (2*Y-X)%3 != 0 or Y > X*2 or X > Y*2:
  print(0)
else:
  m = (2*X-Y)//3
  n = (2*Y-X)//3
  print(nCr(m+n, n, 10**9+7))
Buggy code:
x,y = map(int,input().split())
mod = 10**9+7
def comb(a,b):
  comb = 1
  chld = 1
  for i in range(b):
    comb = comb*(a-i)%mod
    chld *= (b-i)%mod
  return (comb*pow(chld,mod-2,mod))%mod
if (x+y)%3!=0:
  print(0)
else:
  nm = (x+y)//3
  n = y-nm
  m = x-nm
  print(comb(n+m,m))

Fixed code:
x,y = map(int,input().split())
mod = 10**9+7
def comb(a,b):
  comb = 1
  chld = 1
  for i in range(b):
    comb = comb*(a-i)%mod
    chld = chld*(b-i)%mod
  return (comb*pow(chld,mod-2,mod))%mod
if (x+y)%3!=0:
  print(0)
else:
  nm = (x+y)//3
  n = y-nm
  m = x-nm
  if n>=0 and m>=0:
    print(comb(n+m,m))
  else:
    print(0)
Buggy code:
X,Y=map(int,input().split())
mod=10**9+7
if (X+Y)%3!=0:
    print("0")
else:
    m=int((2*X-Y)/3)
    n=int((2*Y-X)/3)
    bunsi=1
    bunbo=1
    for i in range(0,n):
        bunsi*=(m+1+i)
        bunsi%mod
        bunbo*=1+i
        bunbo%mod
    print((bunsi*pow(bunbo,mod-2,mod))%mod)

Fixed code:
X,Y=map(int,input().split())
mod=pow(10,9)+7
m=(2*X-Y)//3
n=(2*Y-X)//3
if  m==(2*X-Y)/3 and n==(2*Y-X)/3 and m>=0 and n>=0:
    bunsi = 1
    bunbo = 1
    for i in range(0, n):
        bunsi = (bunsi * (m + 1 + i)) % mod
        bunbo = (bunbo * (1 + i)) % mod
    print((bunsi * pow(bunbo, mod - 2, mod)) % mod)

else:
    print(0)
Buggy code:
def cmd(n,r,mod=10*9+7):
    fac = [0] * (n+1)
    finv = [0] * (n+1)
    inv = [0]*(n+1)

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

    if n < r: return 0
    if n < 0 or r < 0: return 0
    return (fac[n]*(finv[r]*finv[n-r]%mod)%mod)

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

if (x+y) % 3 != 0:
    print(0)
    exit()

i = (x+y)//3
j = x-i

print(cmd(i,j))

Fixed code:
def cmd(n,r,mod=10**9+7):
    fac = [0] * (n+1)
    finv = [0] * (n+1)
    inv = [0]*(n+1)

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

    if n < r: return 0
    if n < 0 or r < 0: return 0
    return (fac[n]*(finv[r]*finv[n-r]%mod)%mod)

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

if (x+y) % 3 != 0:
    print(0)
    exit()

i = (x+y)//3
j = x-i

print(cmd(i,j))
Buggy code:
X,Y=map(int,input().split())

def cnb(n,k,p):
  if k>n:
    return 0
  c,d=1,1
  for i in range(k+1,n+1):
    c = (c*i)%p
  for i in range(1,k+1):
    d = (d*i)%p
  return (c*pow(d,p-2,p))%p

p=10**9+7
if X > 2*Y or Y > 2*X:
  pass
elif (X+Y)%3:
  pass
else:
  ans=cnb((X+Y)//3,(-X+2*Y)//3,p)

print(ans)


Fixed code:
X,Y=map(int,input().split())

def cnb(n,k,p):
  if k>n:
    return 0
  if k>n-k:
    k=n-k
  c,d=1,1
  for i in range(n-k+1,n+1):
    c = (c*i)%p
  for i in range(1,k+1):
    d = (d*i)%p
  return (c*pow(d,p-2,p))%p

p=10**9+7
ans=0
if X > 2*Y or Y > 2*X:
  pass
elif (X+Y)%3:
  pass
else:
  ans=cnb((X+Y)//3,(2*Y-X)//3,p)

print(ans)
Buggy code:
X, Y = [int(x) for x in input().split()]
M = 10**9+7
if (X + Y) % 3:
  print(0)
  
x = X - (X+Y)//3
y = Y - (X+Y)//3
#print(x, y)
#x+y c x
#(x+y)!/x!/y!
ans = 1
for j in range(y):
  #print(j)
  #print(x+j+1, j+1)
  ans *= (x+j+1) * pow(j+1, -1, M)
  ans %= M
print(ans)

Fixed code:
X, Y = [int(x) for x in input().split()]
M = 10**9+7
if (X + Y) % 3:
  print(0)
else:
  x = X - (X+Y)//3
  y = Y - (X+Y)//3
  if x < 0 or y < 0:
    print(0)
  else:
    #print(x, y)
    #x+y c x
    #(x+y)!/x!/y!
    ans = 1
    for j in range(y):
      #print(j)
      #print(x+j+1, j+1)
      ans *= (x+j+1) * pow(j+1, -1, M)
      ans %= M
    print(ans)
Buggy code:
x,y=map(int,input().split())
MOD=10**9+7
if (2*y-x)%3!=0 or 2*y-x<0 or 2*x-y<0:
  print(0)
a=(2*x-y)//3
if (a+1)*3<=(2*x-y):
  a+=1
a=(2*x-y)//3
if (a+1)*3<=(2*x-y):
  a+=1
b=(2*y-x)//3
if (b+1)*3<=(2*y-x):
  b+=1
p=1
for i in range(1,a+b+1):
  p=(p*i)%MOD
q=1
for i in range(1,a+1):
  q=(q*i)%MOD
q=pow(q,MOD-2,MOD)
r=1
for i in range(1,b+1):
  r=(r*i)%MOD
r=pow(r,MOD-2,MOD)
print((p*q*r)%MOD)

Fixed code:
import sys
x,y=map(int,input().split())
MOD=10**9+7
if (2*y-x)%3!=0 or 2*y-x<0 or 2*x-y<0:
  print(0)
  sys.exit()
a=(2*x-y)//3
if (a+1)*3<=(2*x-y):
  a+=1
a=(2*x-y)//3
if (a+1)*3<=(2*x-y):
  a+=1
b=(2*y-x)//3
if (b+1)*3<=(2*y-x):
  b+=1
p=1
for i in range(1,a+b+1):
  p=(p*i)%MOD
q=1
for i in range(1,a+1):
  q=(q*i)%MOD
q=pow(q,MOD-2,MOD)
r=1
for i in range(1,b+1):
  r=(r*i)%MOD
r=pow(r,MOD-2,MOD)
print((p*q*r)%MOD)