qyliang/CodeNanoFix huggingface dataset:
Buggy code:
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])

    return result

X, Y = map(int, input().split(' '))
a = 0
b = 0

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



if a < 0 or b < 0:
    ans = 0
else:
    ans = cmb(a+b, b)
print(ans % 1000000007)

Fixed code:
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])

    return result
     
X, Y = map(int, input().split(' '))
a = -1
b = -1
 
if (2*Y-X)%3 == 0 and (2*X-Y)%3 == 0:
    a = (2*X-Y)//3
    b = (2*Y-X)//3
 
 
 
if a < 0 or b < 0:
    ans = 0
else:
    ans = cmb(a+b, b)
print(ans % 1000000007)
Buggy code:
def multiple_of_n(x, y, n=3):
    return (x - y) % n == 0

def combination(g1, g2, inverse, n, r, mod):
    if (r < 0 or r > n):
        return 0
    r = min([r, n - r])
    print(g1[n] * g2[r] * g2[n - r] % mod)

def make_inv(mod, N):
    g1 = [1, 1]
    g2 = [1, 1]
    inverse = [0, 1]
    for i in range(2, N + 1):
        g1.append((g1[-1] * i) % mod)
        inverse.append((- inverse[mod % i] * (mod // i)) % mod)
        g2.append((g2[-1] * inverse[-1]) % mod)
    return g1, g2, inverse

mod = 10 ** 9 + 7

x, y = map(int, input().split())
if multiple_of_n(2 * x, y) and multiple_of_n(2 * y, x):
    vertical = (2 * y - x) // 3
    horizontal = (2 * x - y) // 3
    total = vertical + horizontal
    g1, g2, inverse = make_inv(mod, total)
    combination(g1, g2, inverse, total, horizontal, mod)

Fixed code:
def multiple_of_n(x, y, n=3):
    return (x - y) % n == 0

def combination(g1, g2, inverse, n, r, mod):
    if (r < 0 or r > n):
        return 0
    r = min([r, n - r])
    return g1[n] * g2[r] * g2[n - r] % mod

def make_inv(mod, N):
    g1 = [1, 1]
    g2 = [1, 1]
    inverse = [0, 1]
    for i in range(2, N + 1):
        g1.append((g1[-1] * i) % mod)
        inverse.append((- inverse[mod % i] * (mod // i)) % mod)
        g2.append((g2[-1] * inverse[-1]) % mod)
    return g1, g2, inverse

mod = 10 ** 9 + 7

x, y = map(int, input().split())
if multiple_of_n(2 * x, y) and multiple_of_n(2 * y, x):
    vertical = (2 * y - x) // 3
    horizontal = (2 * x - y) // 3
    total = vertical + horizontal
    g1, g2, inverse = make_inv(mod, total)
    print(combination(g1, g2, inverse, total, horizontal, mod))
else:
    print(0)
Buggy code:
X,Y=map(int,input().split())
MOD=10**9+7

def modinv(a):
    return pow(a,MOD-2,MOD)

x=(2*Y-X)//3
y=(2*X-Y)//3

if x%3!=0 or y%3!=0 or x<0 or y<0:
	print(0)
else:
	r=1
	n=x+y
	k=min(x,y)
	for i in range(k):
		r*=(n-i)
		r*=modinv(i+1)
		r%=MOD
	print(r)


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

def modinv(a):
	return pow(a,MOD-2,MOD)

x=(2*Y-X)//3
y=(2*X-Y)//3

if (2*Y-X)%3!=0 or (2*X-Y)%3!=0 or x<0 or y<0:
	print(0)
else:
	r=1
	n=x+y
	k=min(x,y)
	for i in range(k):
		r*=(n-i)
		r*=modinv(i+1)
		r%=MOD
	print(r)
Buggy code:
#ABC145D
def main():
    import sys, math
    X, Y = map(int, sys.stdin.readline().split())
    '''
    i +2*j ==X
    2*i +j ==Y
    '''
    if (2*Y-X)%3==0:
        i = (2*Y-X)//3
        j = Y-2*i
    else:
        ans =0
    #print(i, j)
    mod = 10**9+7
    def calc(n):
        ans = 1
        for i in range(n, 1, -1):
            ans *= i
            ans %= mod
        return ans
    
    ans = calc(i+j)
    #print(calc(-1))
    #print(ans)
    
    #calc2(calc(i), mod-2)
    gg1 = pow(calc(i), mod-2, mod)
    gg2 = pow(calc(j), mod-2, mod)
    
    if i<0 or j<0:
        print(0)
    elif i==0 and j==0:
        print(0)
    else:
        print(ans*gg1*gg2%mod)

if __name__=='__main__':
    main()

Fixed code:
#ABC145D
def main():
    import sys, math
    X, Y = map(int, sys.stdin.readline().split())
    '''
    i +2*j ==X
    2*i +j ==Y
    '''
    if (2*Y-X)%3==0:
        i = (2*Y-X)//3
        j = Y-2*i
    else:
        i,j=0,0
    #print(i, j)
    mod = 10**9+7
    def calc(n):
        ans = 1
        for i in range(n, 1, -1):
            ans *= i
            ans %= mod
        return ans
    
    ans = calc(i+j)
    #print(calc(-1))
    #print(ans)
    
    #calc2(calc(i), mod-2)
    gg1 = pow(calc(i), mod-2, mod)
    gg2 = pow(calc(j), mod-2, mod)
    
    if i<0 or j<0:
        print(0)
    elif i==0 and j==0:
        print(0)
    else:
        print(ans*gg1*gg2%mod)

if __name__=='__main__':
    main()
Buggy code:
def factorial_mod(n, mod):
    a = 1
    for i in range(1, n + 1):
        a *= i
        a %= mod
    return a


def comb_mod(n, k, mod):
    if k > n or k < n:
        return 0
    fact_n = factorial_mod(n, mod)
    fact_k = factorial_mod(k, mod)
    fact_n_k = factorial_mod(n - k, mod)
    return (fact_n * pow(fact_k, mod - 2, mod) * pow(fact_n_k, mod - 2, mod)) % mod


def main():
    x, y = map(int, input().split())
    MOD = 10 ** 9 + 7
    if (2 * x - y) % 3 != 0 or (2 * y - x) % 3 != 0:
        print(0)
        exit()
    i = (2 * x - y) // 3
    j = (2 * y - x) // 3
    print(comb_mod(i + j, i, MOD))


if __name__ == '__main__':
    main()


Fixed code:
def factorial_mod(n, mod):
    a = 1
    for i in range(1, n + 1):
        a *= i
        a %= mod
    return a


def comb_mod(n, k, mod):
    if k > n or k < 0:
        return 0
    fact_n = factorial_mod(n, mod)
    fact_k = factorial_mod(k, mod)
    fact_n_k = factorial_mod(n - k, mod)
    return (fact_n * pow(fact_k, mod - 2, mod) * pow(fact_n_k, mod - 2, mod)) % mod


def main():
    x, y = map(int, input().split())
    MOD = 10 ** 9 + 7
    if (2 * x - y) % 3 != 0 or (2 * y - x) % 3 != 0:
        print(0)
        exit()
    i = (2 * x - y) // 3
    j = (2 * y - x) // 3
    print(comb_mod(i + j, i, MOD))


if __name__ == '__main__':
    main()
Buggy code:
x, y = map(int, input().split())
tmp = 2*y - x
if tmp%3 != 0:
    print(0)
    exit()
up = tmp // 3
total = y - up*2 + up

n = total
k = up
mod = 10**9 + 7

print(n)
print(k)
print()

if k <= 0:
    print(1)
    exit()
#try:
modinv_table = [-1] * (k+1)
modinv_table[1] = 1
for i in range(2, k+1):
    modinv_table[i] = (-modinv_table[mod % i] * (mod // i)) % mod
#except:
    #k = total - up
    #modinv_table = [-1] * (k + 1)
    #modinv_table[1] = 1
    #for i in range(2, k + 1):
        #modinv_table[i] = (-modinv_table[mod % i] * (mod // i)) % mod

def binomial_coefficients(n, k):
    ans = 1
    for i in range(k):
        ans *= n-i
        ans *= modinv_table[i + 1]
        ans %= mod
    return ans

print(binomial_coefficients(n, k))

Fixed code:
x, y = map(int, input().split())
tmp = 2*y - x
if tmp%3 != 0:
    print(0)
    exit()
up = tmp // 3
total = y - up*2 + up

n = total
k = up
mod = 10**9 + 7

#print(n)
#print(k)

if k == 0:
    print(1)
    exit()
try:
    modinv_table = [-1] * (k+1)
    modinv_table[1] = 1
    for i in range(2, k+1):
        modinv_table[i] = (-modinv_table[mod % i] * (mod // i)) % mod
except:
    k = total - up
    modinv_table = [-1] * (k + 1)
    modinv_table[1] = 1
    for i in range(2, k + 1):
        modinv_table[i] = (-modinv_table[mod % i] * (mod // i)) % mod

def binomial_coefficients(n, k):
    ans = 1
    for i in range(k):
        ans *= n-i
        ans *= modinv_table[i + 1]
        ans %= mod
    return ans

print(binomial_coefficients(n, k))
Buggy code:
# 73

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

a = 2*y - x
b = 2*x - y

fac_l = [0] * (int((a + b) / 3) + 1)
inv_l = [0] * (int((a + b) / 3) + 1)
finv_l = [0] * (int((a + b) / 3) + 1)


def com_init():
    fac_l[1] = 1
    inv_l[0] = 1
    inv_l[1] = 1
    finv_l[0] = 1
    finv_l[1] = 1
    for i in range(2, a+b+1):
        fac_l[i] = (fac_l[i-1] * i) % MOD
        inv_l[i] = MOD - (inv_l[MOD % i] * int(MOD / i)) % MOD
        finv_l[i] = finv_l[i-1] * inv_l[i]


def ncr(n, r):
    return (((fac_l[n] * finv_l[r]) % MOD) * finv_l[n-r]) % MOD


if a % 3 != 0 or b % 3 != 0:
    print("0")
else:
    a = int(a/3)
    b = int(b/3)

    com_init()
    print(ncr(a+b, a))


Fixed code:
# 73

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

a = 2*y - x
b = 2*x - y

fac_l = [0] * (int((a + b) / 3) + 1)
inv_l = [0] * (int((a + b) / 3) + 1)
finv_l = [0] * (int((a + b) / 3) + 1)


def com_init():
    fac_l[1] = 1
    inv_l[0] = 1
    inv_l[1] = 1
    finv_l[0] = 1
    finv_l[1] = 1
    for i in range(2, a+b+1):
        fac_l[i] = (fac_l[i-1] * i) % MOD
        inv_l[i] = MOD - (inv_l[MOD % i] * int(MOD / i)) % MOD
        finv_l[i] = (finv_l[i-1] * inv_l[i]) % MOD

def ncr(n, r):
    return (fac_l[n] * (finv_l[r] * finv_l[n-r]) % MOD) % MOD


if a % 3 != 0 or b % 3 != 0 or a < 0 or b < 0:
    print("0")
else:
    a = int(a/3)
    b = int(b/3)

    com_init()
    print(ncr(a+b, a))
Buggy code:
mod = 10 ** 9 + 7
x, y = map(int,  input().split())

def nCm_mod(A, B, mod):
    mul_one = 1
    mul_two = 1

    for i in range(B):
        mul_one *= A - i
        mul_two *= i + 1
        mul_one %= mod
        mul_two %= mod
    
    return (mul_one * pow(mul_two, mod-2, mod)) % mod

if (x + y) % 3 != 0:
    print(0)
else:
    n = (2 * y - x) // 3
    m = (2 * x - y) // 3

    print(n, m)
    # exit()

    comb_num = nCm_mod(n+m, min(n,m), mod)
    print(comb_num)
    

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

def nCm_mod(A, B, mod):
    mul_one = 1
    mul_two = 1

    for i in range(B):
        mul_one *= A - i
        mul_two *= i + 1
        mul_one %= mod
        mul_two %= mod
    
    return (mul_one * pow(mul_two, mod-2, mod)) % mod

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

if (x + y) % 3 != 0 or n < 0 or m < 0:
    print(0)
else:
    comb_num = nCm_mod(n+m, min(n,m), mod)
    print(comb_num)
Buggy code:
X,Y=map(int, input().split())
MOD=10**9+7

if (2*Y-X)%3 or (2*X-Y)%3:
    print(0)
    exit()

i=(2*Y-X)//3
j=(2*X-Y)//3

def m_pow(n,m):
    ret = 1
    while m:
        if m&1:
            ret*=ret*n%MOD
        n=n*n%MOD
        m>>=1
    return ret

def m_fact(n):
    if n==0:
        return 1
    ret = 1
    for i in range(1,n+1):
        ret=ret*i%MOD
    return ret

def m_comb(n,k):
    return m_fact(n) * m_pow(m_fact(k), MOD-2) * m_pow(m_fact(n-k), MOD-2) %MOD

print(m_comb(i+j,min(i,j)))

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

if 2*Y<X or 2*X<Y or (2*Y-X)%3 or (2*X-Y)%3:
    print(0)
    exit()

i=(2*Y-X)//3
j=(2*X-Y)//3

def m_pow(n,m):
    ret = 1
    while m:
        if m&1:
            ret=ret*n%MOD
        n=n*n%MOD
        m>>=1
    return ret

def m_fact(n):
    if n==0:
        return 1
    ret = 1
    for i in range(1,n+1):
        ret=ret*i%MOD
    return ret

def m_comb(n,k):
    return m_fact(n) * m_pow(m_fact(k), MOD-2) * m_pow(m_fact(n-k), MOD-2) %MOD

print(m_comb(i+j,min(i,j)))
Buggy code:
x,y=map(int,input().split())
mod = 10**9+7
flflag=True

if (2*x-y)%3==0:
  a=(2*x-y)//3
else:
  flflag=False
if (2*y-x)%3==0:
  b=(2*y-x)//3
else:
  flflag=False

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

N=a+b
R=min(a,b)
ans=0
if a>=0 and b>=0 and flflag==True:
  ans=kaijou(N)
  ans1= (kaijou(N-R)*kaijou(R))%mod
  print((ans*pow(ans1,mod-2,mod))%mod)
else:
  print(0)

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

if (2*x-y)%3==0:
  a=(2*x-y)//3
else:
  flflag=False
if (2*y-x)%3==0:
  b=(2*y-x)//3
else:
  flflag=False

def kaijou(n):
  ans = 1
  for i in range(1,n+1):
    ans*=i%mod
    ans%=mod  
  return ans
if flflag:
  N=a+b
  R=min(a,b)
ans=0
if flflag==True and a>=0 and b>=0:
  ans=kaijou(N)
  ans1= (kaijou(N-R)*kaijou(R))%mod
  print((ans*pow(ans1,mod-2,mod))%mod)
else:
  print(0)
Buggy code:
    MOD = 10 ** 9 + 7
     
    X, Y = map(int, input().split())
     
    a = (2 * X - Y) // 3
    b = (2 * Y - X) // 3
     
    if not ((2 * X - Y) % 3 == 0 and (2 * Y - X) % 3 == 0 and a >= 0 and b >= 0):
        print(0)
        exit()
     
    maxf = a + b + 1
    f = [1 for _ in range(maxf)]
    invf = [1 for _ in range(maxf)]
     
    for i in range(1, maxf):
        f[i] = (i * f[i - 1]) % MOD
    invf[maxf - 1] = pow(f[maxf - 1], MOD - 2, MOD)
     
    for i in range(maxf - 1, 0, -1):
        invf[i - 1] = (i * invf[i]) % MOD
     
     
    def comb(a, b):
        return (f[a + b] * invf[a] * invf[b]) % MOD
     
     
    print(comb(a, b))

Fixed code:
MOD = 10 ** 9 + 7

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

a = (2 * X - Y) // 3
b = (2 * Y - X) // 3

if not ((2 * X - Y) % 3 == 0 and (2 * Y - X) % 3 == 0 and a >= 0 and b >= 0):
    print(0)
    exit()

maxf = a + b + 1
f = [1 for _ in range(maxf)]
invf = [1 for _ in range(maxf)]

for i in range(1, maxf):
    f[i] = (i * f[i - 1]) % MOD
invf[maxf - 1] = pow(f[maxf - 1], MOD - 2, MOD)

for i in range(maxf - 1, 0, -1):
    invf[i - 1] = (i * invf[i]) % MOD


def comb(a, b):
    return (f[a + b] * invf[a] * invf[b]) % MOD


print(comb(a, b))
Buggy code:
x,y = map(int,input().split())
M = 10**9+7

def pow(a,b,M):
    if b == 0:
        return 1
    else:
        if b % 2 == 0:
            return pow((a**2)%M,b//2,M) % M
        else:
            return (a * pow((a**2)%M,b//2,M)) % M

def inv(a,M):
    return pow(a,M-2,M)

def comb(n,k,M):
    nume,deno = 1,1
    for i in range(1,k+1):
        deno = (deno * (n-i+1)) % M
        nume = (nume * i) % M
    return (deno * inv(nume,M)) % M

if (x+y) % 3 != 0 and (2*x < y or 2*y < x):
    print(0)
else:
    mov = (x+y)//3
    x,y = x-mov,y-mov
    print(comb(mov,x,M))


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

def pow(a,b,M):
    if b == 0:
        return 1
    else:
        if b % 2 == 0:
            return pow((a**2)%M,b//2,M) % M
        else:
            return (a * pow((a**2)%M,b//2,M)) % M

def inv(a,M):
    return pow(a,M-2,M)

def comb(n,k,M):
    nume,deno = 1,1
    for i in range(1,k+1):
        deno = (deno * (n-i+1)) % M
        nume = (nume * i) % M
    return (deno * inv(nume,M)) % M

if (x+y) % 3 != 0 or (2*x < y or 2*y < x):
    print(0)
else:
    mov = (x+y)//3
    x,y = x-mov,y-mov
    print(comb(mov,x,M))
Buggy code:
import math
mod = (10**9) + 7

def kaijo(n):
    result = 1
    for i in reversed(range(1,n+1)):
        result = (result * i) % mod
    return result
def combinations_count(n, r):
    return (kaijo(n)) //(kaijo(n - r) * kaijo(r))

def nCk(n, k):
    ret = 1
    mo = 10**9 + 7
    for i in range(k):
        ret = ret * (n - i) * pow(i + 1, mo - 2, mo) % mo
    return ret


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

if (X+Y)%3 == 0:
    flag = False
    if X > Y:
        diff = X - Y
        all_num = (X+Y)//3
        count_2 = (X+Y)//2 - diff//2 - all_num
        if X > Y*2:
            flag = True
    elif Y > X:
        diff = Y - X
        all_num = (X+Y)//3
        count_2 = (X+Y)//2 - diff//2　- all_num
        if Y > X*2:
            flag = True
    else:
        all_num = (X+Y)//3
        count_2 = all_num//2
    if flag:
        print(0)
    else:
        print(nCk(all_num,count_2))
else:
    print(0)


Fixed code:
import math
mod = (10**9) + 7

def kaijo(n):
    result = 1
    for i in reversed(range(1,n+1)):
        result = (result * i) % mod
    return result
def combinations_count(n, r):
    return (kaijo(n)) //(kaijo(n - r) * kaijo(r))

def nCk(n, k):
    ret = 1
    mo = 10**9 + 7
    for i in range(k):
        ret = ret * (n - i) * pow(i + 1, mo - 2, mo) % mo
    return ret


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

if (X+Y)%3 == 0:
    flag = False
    if X > Y:
        diff = X - Y
        all_num = (X+Y)//3
        count_2 = Y - all_num
        if X > Y*2:
            flag = True
    elif Y > X:
        diff = Y - X
        all_num = (X+Y)//3
        count_2 = X - all_num
        if Y > X*2:
            flag = True
    else:
        all_num = (X+Y)//3
        count_2 = all_num//2
    if flag:
        print(0)
    else:
        print(nCk(all_num,count_2))
else:
    print(0)
Buggy code:
X, Y = list(map(int,input().split()))

from functools import reduce

def cmb(n, r, p = 10 ** 9 + 7):
    r = min(n - r, r)
    if r == 0:  return 1
    numer = reduce(lambda x, y: (x * y) % p, range(n, n - r, -1))
    denom = reduce(lambda x, y: (x * y) % p, range(1, r + 1))
    return (numer * pow(denom, p - 2, p)) % p

temp1 = 2 * X - Y
temp2 = 2 * Y - X
if temp1 % 3 or temp2 % 3:  print(0)
elif temp1 < 0 or temp2 < 0:  print(0)
else:
    a = temp1 // 3
    b = temp2 // 3
    print(a, b)
    print(cmb(a + b, a, 10 ** 9 + 7))

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

from functools import reduce

def cmb(n, r):
    INF = 10 ** 9 + 7
    r = min(n - r, r)
    if r == 0:  return 1
    numer = reduce(lambda x, y: (x * y) % INF, range(n, n - r, -1))
    denom = reduce(lambda x, y: (x * y) % INF, range(1, r + 1))
    return (numer * pow(denom, INF - 2, INF)) % INF

temp1 = 2 * X - Y
temp2 = 2 * Y - X
if temp1 % 3 or temp2 % 3:  print(0)
elif temp1 < 0 or temp2 < 0:  print(0)
else:
    a = temp1 // 3
    b = temp2 // 3
    print(cmb(a + b, a))
Buggy code:
x, y = map(int, input().split())

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

diff = abs(x - y)
ref = (min(x, y) - diff)//3
total = ref*2 + diff
mod = 10**9 + 7
ans = 1

for i in range(min(ref, total - ref)):
    ans = ans*(total - i)%mod
    ie = pow((i + 1), (mod - 2))%mod
    ans = ans*ie%mod

print(ans)

Fixed code:
x, y = map(int, input().split())
diff = abs(x - y)
ref = (min(x, y) - diff)//3
total = ref*2 + diff
mod = 10**9 + 7
ans = 1

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


for i in range(min(ref, total - ref)):
    ans = ans*(total - i)%mod
    ie = pow((i + 1), (mod - 2), mod)
    ans = ans*ie%mod

print(ans)
Buggy code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
mod = 10**9+7
X,Y = map(int,readline().split())
if X > Y:
    X,Y = Y,X
Z = X+Y
if Z % 3 == 0 and X <= Y <= 2*X:
    N = Z//3
    r = min(Y-X+1,N-Y+X-1)
else:
    print(0)
    sys.exit()
f = [1]*(N+1)
for i in range(1,N+1):
    f[i] = i * f[i-1] % mod
a = pow(f[r],mod-2,mod)
b = pow(f[N-r],mod-2,mod)
ans = f[N] * a * b % mod
print(ans)
    
    

Fixed code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
mod = 10**9+7
X,Y = map(int,readline().split())
if X > Y:
    X,Y = Y,X
Z = X+Y
if Z % 3 == 0 and X <= Y <= 2*X:
    N = Z//3
    r = (N-(Y-X)) // 2
else:
    print(0)
    sys.exit()
f = [1]*(N+1)
for i in range(1,N+1):
    f[i] = i * f[i-1] % mod
a = pow(f[r],mod-2,mod)
b = pow(f[N-r],mod-2,mod)
ans = f[N] * a * b % mod
print(ans)
Buggy code:
def comb(a,b,m):
	if b == 0 or b == a:
		ret = 1
	else:
		ret = 1
		for i in range(a-b+1,a+1):
			ret = (ret * i) % m
		for i in range(1,b+1):
			ret = (ret * pow(i,m-2,m) ) % m
	return ret

mod = 10**9+7
x, y = [ int(v) for v in input().split() ]
x, y = (2*x-y) // 3, (2*y-x) // 3

print(comb(x+y,y,mod))

Fixed code:
def comb(a,b,m):
	if b == 0 or b == a:
		ret = 1
	else:
		ret = 1
		for i in range(a-b+1,a+1):
			ret = (ret * i) % m
		for i in range(1,b+1):
			ret = (ret * pow(i,m-2,m) ) % m
	return ret % m

mod = 10**9+7
x, y = [ int(v) for v in input().split() ]

ans = 0
if (2*x-y) % 3 == 0 and (2*y-x) % 3 == 0:
    x, y = (2*x-y) // 3, (2*y-x) // 3
    if x >= 0 and y >= 0:
    	ans = comb(x+y,y,mod)
print(ans)
Buggy code:
def make_tables(m):
    fac=[1,1]
    finv=[1,1]
    inv=[0,1]
    for i in range(2,m+1):
        fac.append((fac[-1]*i)%mod)
        inv.append((-inv[mod%i]*(mod//i))%mod)
        finv.append(finv[i-1]*inv[i]%mod)
    return fac,finv
 calc_nCk(n,k,fac,finv):
    if n<k or (n<0 or k<0):
        return 0
    k=min(k,n-k)
    return fac[n]*(finv[k]*finv[n-k]%mod)%mod

x,y=map(int,input().split())
mod=10**9+7
n=(y-0.5*x)/1.5
if int(n)!=n:
    print(0)
else:
    m=(y+x)//3
    l=int(n)
    fac,finv=make_tables(m)
    ans = calc_nCk(m,l,fac,finv)
    print(ans)


Fixed code:
def make_tables(m):
    fac=[1,1]
    finv=[1,1]
    inv=[0,1]
    for i in range(2,m+1):
        fac.append((fac[-1]*i)%mod)
        inv.append((-inv[mod%i]*(mod//i))%mod)
        finv.append(finv[i-1]*inv[i]%mod)
    return fac,finv

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

x,y=map(int,input().split())
mod=10**9+7
n=(y-0.5*x)/1.5
if int(n)!=n:
    print(0)
else:
    m=(y+x)//3
    l=int(n)
    fac,finv=make_tables(m)
    ans = calc_nCk(m,l,fac,finv)
    print(ans)
Buggy code:
mod = 1000000007
def power(x, y):
    if   y == 0     : 
        return 1
    elif y == 1     : 
        return x % mod
    elif y % 2 == 0 : 
        return power(x, y//2)**2 % mod
    else            : 
        return power(x, y//2)**2 * x % mod
X,Y = (int(i) for i in input().split())

Z = X + Y
A = max(X,Y)
B = min(X,Y)
C = A - B

if Z % 3 != 0:
    print(0)
else:
    N = Z // 3
    if (N - C) % 2 != 0:
        print(0)
    else:
        M = (N - C) // 2


        a = 1
        b = 1
        for i in range(M):
            a = (a * (i + 1)) % mod
            c = power(a, mod-2)
        for i in range(M):
            b = (b * (N-i)) % mod
        ans = b * c % mod

        print(ans)

Fixed code:
mod = 1000000007
def power(x, y):
    if   y == 0     : 
        return 1
    elif y == 1     : 
        return x % mod
    elif y % 2 == 0 : 
        return power(x, y//2)**2 % mod
    else            : 
        return power(x, y//2)**2 * x % mod
X,Y = (int(i) for i in input().split())

Z = X + Y
A = max(X,Y)
B = min(X,Y)
C = A - B

if Z % 3 != 0:
    print(0)
elif A > 2*B :
    print(0)
else:
    N = Z // 3
    if (N - C) % 2 != 0:
        print(0)
    else:
        M = (N - C) // 2


        a = 1
        b = 1
        for i in range(M):
            a = (a * (i + 1)) % mod
            b = (b * (N-i)) % mod
        c = power(a, mod-2)
        ans = b * c % mod

        print(ans)
Buggy code:
MOD = 10**9 + 7
X, Y = map(int, input().split())


def f(n):
    res = n
    for i in range(1, n):
        res *= i
        res %= MOD
    return res


def solve():
    ans = 0
    if (X + Y) % 3 == 0:
        n = (2 * X - Y) // 3
        m = (2 * Y - X) // 3
    if n > 0 and m > 0:
        ans += (f(n + m) * pow(f(n), MOD - 2, MOD) * pow(f(m), MOD - 2, MOD)) % MOD

    print(ans)


if __name__ == "__main__":
    solve()

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


def f(n):
    res = n
    for i in range(1, n):
        res *= i
        res %= MOD
    return res


def solve():
    ans = 0
    if (X + Y) % 3 == 0:
        n = (2 * X - Y) // 3
        m = (2 * Y - X) // 3
        if n == 0 or m == 0:
            ans += 1
        elif n > 0 and m > 0:
            ans += (f(n + m) * pow(f(n), MOD - 2, MOD) * pow(f(m), MOD - 2, MOD)) % MOD

    print(ans)


if __name__ == "__main__":
    solve()
Buggy code:
999999 999999x, y = map(int, input().split())
if (x + y) % 3 != 0:
    print(0)
    exit()
a = (x + y) // 3
x -= a
y -= a
mod = 10 ** 9 + 7
def combination(n, r):
    x = 1
    y = 1
    for i in range(r):
        x = x * (n - i) % mod
        y = y * (r - i) % mod
    return (x * pow(y, mod-2, mod)) % mod
print(combination(x+y, min(x, y)))

Fixed code:
x, y = map(int, input().split())
if (x + y) % 3 != 0:
    print(0)
    exit()
a = (x + y) // 3
x -= a
y -= a
if x < 0 or y < 0:
    print(0)
    exit()
mod = 10 ** 9 + 7
def combination(n, r):
    x = 1
    y = 1
    for i in range(r):
        x = x * (n - i) % mod
        y = y * (r - i) % mod
    return (x * pow(y, mod-2, mod)) % mod
print(combination(x+y, min(x, y)))