qyliang/CodeNanoFix huggingface dataset:
Buggy code:
#coding: utf-8
import math
import heapq

MOD = 10**9+7

def combination(n, r):
    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


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

if (X+Y)%3!=0:
    print(0)
else:
    a = 2*X-Y
    b = 2*Y-X
    if a<0 or b<0:
        print(0)
    else:
        print(combination(a+b, a))


Fixed code:
#coding: utf-8
import math
import heapq

MOD = 10**9+7

def combination(n, r):
    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


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

if (X+Y)%3!=0:
    print(0)
else:
    a = (2*X-Y)//3
    b = (2*Y-X)//3
    if a<0 or b<0:
        print(0)
    else:
        print(combination(a+b, a))
Buggy code:
X, Y = map(int, input().split())

a, b = divmod(2*X-Y, 3)
c, d = divmod(2*Y-X, 3) 
if (not b == d == 0) or (2*a < b) or (2*b < a):
  print(0)
else:
  m, n = 1, 1
  mod = 10**9+7
  for i in range(1, min(a, c)+1):
    m = (m * (a+c-i+1)) % mod
    n = (n * i) % mod
  ans = (m * pow(n, mod-2, mod)) % mod
  print(ans)

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

a, b = divmod(2*X-Y, 3)
c, d = divmod(2*Y-X, 3) 
if (not b == d == 0) or (2*X < Y) or (2*Y < X):
  print(0)
else:
  m, n = 1, 1
  mod = 10**9+7
  for i in range(1, min(a, c)+1):
    m = (m * (a+c-i+1)) % mod
    n = (n * i) % mod
  ans = (m * pow(n, mod-2, mod)) % mod
  print(ans)
Buggy code:
import math
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



mod=1000000007
X,Y=map(int,input().split())
flag=0
count=0
for i in range(min(X,Y)//3):
    if min(X,Y)*2==max(X,Y):
        flag=1
        count2=min(X,Y)
        break
    X-=3
    Y-=3
    count+=1
    #print(X,Y)

if min(X,Y)*2==max(X,Y):
    flag=1

if flag==0:
    print('0')
    exit(0)

print(cmb(count*2+count2,count)%mod)



Fixed code:
import math
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


count2=0
mod=1000000007
X,Y=map(int,input().split())
flag=0
count=0
for i in range(min(X,Y)//3):
    if min(X,Y)*2==max(X,Y):
        flag=1
        count2=min(X,Y)
        break
    X-=3
    Y-=3
    count+=1
    #print(X,Y)

if min(X,Y)*2==max(X,Y):
    flag=1

if flag==0:
    print('0')
    exit(0)

print(cmb(count*2+count2,count)%mod)
Buggy code:
def com(n,r,mod):
    k=min(r,n-r)
    C=1
    for i in range(1,k+1):
        C=(C*(n+1-i)*pow(i,mod-2,mod))%mod
    return C

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

m = 2 * x - y
n = 2 * y - x
if m > 0 and n > 0 and m % 3 == 0 and n % 3 == 0:
    print(com((n + m) // 3, n // 3, mod))

Fixed code:
def com(n,r,mod):
    k=min(r,n-r)
    C=1
    for i in range(1,k+1):
        C=(C*(n+1-i)*pow(i,mod-2,mod))%mod
    return C

x, y = map(int,input().split())
mod = 10 ** 9 + 7
n = (2 * y - x) // 3 if (2 * y - x) % 3 == 0 else -1
m = (2 * x - y) // 3 if (2 * x - y) % 3 == 0 else -1

if n >= 0 and m >= 0:
    print(com(n + m, n, mod))
else:
    print(0)
Buggy code:
import numpy as np
v=np.array(list(map(int, input().split())) )
mod = 10**9 +7
import math
def cmb(n, r,mod):
    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 = (result*int(numerator[k]))%mod

    return result
  
A = np.array([[2,1],[1,2]])
inv_A = np.linalg.inv(A)

k = np.dot(inv_A,v)
if abs(round(k[0]+ k[1])-(k[0]+k[1]))<10**(-6):
  print(cmb(int(k[0]+k[1]),int(k[0]),mod))
else:
  print(0)

Fixed code:
import numpy as np
v=np.array(list(map(int, input().split())) )
mod = 10**9 +7
import math
def cmb(n, r,mod):
    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 = (result*int(numerator[k]))%mod

    return result
  
A = np.array([[2,1],[1,2]])
inv_A = np.linalg.inv(A)

k = np.dot(inv_A,v)

if abs(round(k[0])-k[0])<10**(-10) and abs(round(k[1])-k[1])<10**(-10) and k[0]* k[1] >=0:
  print(int(cmb(int(round(k[0]+k[1])),int(round(k[0])),mod)))
else:
  print(0)
Buggy code:
def C(n, r, m):
    num, den = 1, 1
    for i in range(1, r + 1):
        num = num * (n - i + 1) % m
        den = den * i % m
    return (num * pow(den, m - 2, m)) % m

x, y = map(int, input().split())
m = (2*x - y) // 3
n = (-x + 2*y) // 3
if x + y % 3 != 0 or m < 0 or n < 0:
    print(0)
else:
    print(C(n + m, n, 10**9 + 7))

Fixed code:
def C(n, r, m):
    num, den = 1, 1
    for i in range(1, r + 1):
        num = num * (n - i + 1) % m
        den = den * i % m
    return (num * pow(den, m - 2, m)) % m

x, y = map(int, input().split())
m = (2*x - y) // 3
n = (-x + 2*y) // 3
if (x + y) % 3 != 0 or m < 0 or n < 0:
    print(0)
else:
    print(C(n + m, n, 10**9 + 7))
Buggy code:
def fact(n,mod):
  ret=1
  for i in range(2,n+1):
    ret=(ret*i)%mod
  return ret

def pCq(p,q,mod):
  pCq=1
  for i in range(q):
    pCq*=p-i
    pCq=pCq%mod
    den=fact(q,mod)
    inv=pow(den,mod-2,mod)
    pCq=(pCq*inv)%mod
  return pCq

X,Y=map(int,input().split())
MOD=10**9+7
ans=0
n,m=2*X-Y,2*Y-X
if n%3==0 and m%3==0:
  n//=3
  m//=3
  ans+=pCq(m+n,m,MOD)
print(ans)

Fixed code:
def fact(n,mod):
    ret=1
    for i in range(2,n+1):
        ret=(ret*i)%mod
    return ret

def pCq(p,q,mod):
  pCq=1
  for i in range(q):
    pCq*=p-i
    pCq=pCq%mod
  den=fact(q,mod)
  inv=pow(den,mod-2,mod)
  pCq=(pCq*inv)%mod
  return pCq

X,Y=map(int,input().split())
MOD=10**9+7
ans=0
n,m=2*X-Y,2*Y-X
if n%3==0 and m%3==0:
  n//=3
  m//=3
  ans=pCq(m+n,max(m,n),MOD)
print(ans)
Buggy code:
import sys

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 = (int(x) for x in input().split())

if (X+Y) % 3 != 0:
  print(0)
  sys.exit()
  
n = (2*Y-X) / 3
m = (2*X-Y) / 3
if n < 0 or m < 0:
  print(0)
  sys.exit()
  
print(int(cmb(n+m,n)))

Fixed code:
import sys

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 = (int(x) for x in input().split())

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

if (2*Y-X) % 3 == 0:
  n = (2*Y-X) // 3  
else:
  n = -1

if (2*X-Y) % 3 == 0:
  m = (2*X-Y) // 3
else:
  m = -1

if n < 0 or m < 0:
  print(0)
  sys.exit()
print(int(cmb(n+m,n)) % (10**9 +7))
Buggy code:
X, Y = map(int,input().split())

if (X+Y)%3 != 0 or abs(X-Y) > (X+Y)//3:
    print(-1)
    exit(0)
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
MOD = 10**9 + 7

print(cmb((X+Y)//3,min(X,Y)-(X+Y)//3)%MOD)


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

if (X+Y)%3 != 0 or abs(X-Y) > (X+Y)//3:
    print(0)
    exit(0)
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
MOD = 10**9 + 7

print(cmb((X+Y)//3,min(X,Y)-(X+Y)//3)%MOD)
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())
s=(2*y-x)/3
t=(2*x-y)/3
if (2*y-x)%3!=0 or (2*x-y)%3!=0:
    print(0)
else:
    a = cmb(s+t, t)
    print(a%(10**9+7))

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())
s=int((2*y-x)/3)
t=int((2*x-y)/3)
if (2*y-x)%3!=0 or (2*x-y)%3!=0:
    print(0)
elif s<0 or t<0:
    print(0)
else:
    a = cmb(s+t, t)
    print(a%(10**9+7))
Buggy code:
import sys
mod = 10**9+7
X, Y = map(int, input().split())
if (X+Y) % 3 != 0:
	print(0)
	sys.exit()

tot = (X+Y) // 3

y = abs(tot-X)
x = tot - y

if Y > 2*x or X > 2*y:
	print(0)
	sys.exit()

if x == 0 or y == 0:
	print(1)
	sys.exit()

ans = 1
for i in range(y+1, tot+1):
	ans *= i
	ans %= mod

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

print(ans)

Fixed code:
import sys
mod = 10**9+7
X, Y = map(int, input().split())
if (X+Y) % 3 != 0:
	print(0)
	sys.exit()

tot = (X+Y) // 3

x = X - tot
y = tot - x

if x < 0:
	print(0)
	sys.exit()

if x == 0 or y == 0:
	print(1)
	sys.exit()

ans = 1
for i in range(y+1, tot+1):
	ans *= i
	ans %= mod

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

print(ans%mod)
Buggy code:
import math
MOD = 1000000000+7
X, Y = map(int, input().split())




if ((2*Y-X)%3 != 0) or ((2*X-Y)%3 != 0):
    print(0)
else:
    x = (2*Y-X) // 3
    y = (2*X-Y) // 3
    fac_list = [None for _ in range(x+y+2)]
    inv_fac_list = [None for _ in range(x+y+2)]

    fac_list[0] = 1
    for i in range(1, x+y+2):
        print(i)
        fac_list[i] = i * fac_list[i-1] % MOD

    inv_fac_list[x+y+1] = pow(fac_list[x+y+1],(MOD - 2), MOD)
    for i in range(x+y, 0, -1):
        inv_fac_list[i] = inv_fac_list[i+1] * (i+1) % MOD

    print((fac_list[x+y] * inv_fac_list[x] * inv_fac_list[y]) % MOD)

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

if ((2*Y-X)%3 != 0) or ((2*X-Y)%3 != 0) or (2*Y-X) < 0 or (2*X-Y) < 0:
    print(0)
elif 2 *Y == X or 2 * X == Y:
    print(1)
else:
    x = (2*Y-X) // 3
    y = (2*X-Y) // 3
    fac_list = [None for _ in range(x+y+2)]
    inv_fac_list = [None for _ in range(x+y+2)]

    fac_list[0] = 1
    for i in range(1, x+y+2):
        fac_list[i] = i * fac_list[i-1] % MOD

    inv_fac_list[x+y+1] = pow(fac_list[x+y+1],(MOD - 2), MOD)
    for i in range(x+y, 0, -1):
        inv_fac_list[i] = inv_fac_list[i+1] * (i+1) % MOD

    print((fac_list[x+y] * inv_fac_list[x] * inv_fac_list[y]) % MOD)
Buggy code:
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools
sys.setrecursionlimit(10**8)
mod = 10**9+7
mod2 = 998244353
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

# def conb(n,r): 
#     return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
from scipy.special import comb
x,y = inpl()
x,y = max(x,y),min(x,y)
if (x+y)%3 or y*2 < x:
    print(0)
    quit()
n = (x+y)//3 + 1
k = x-n+2


def cmd(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

a = cmd(n-1,k-1)%mod
print(a)


Fixed code:
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools
sys.setrecursionlimit(10**8)
mod = 10**9+7
mod2 = 998244353
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

# def conb(n,r): 
#     return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

x,y = inpl()
x,y = max(x,y),min(x,y)
if (x+y)%3 or y*2 < x:
    print(0)
    quit()
n = (x+y)//3 + 1
k = x-n+2


def cmd(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

a = cmd(n-1,k-1)%mod
print(a)
Buggy code:
import sys
import math
from itertools import permutations
from itertools import combinations

#input = sys.stdin.readline
sys.setrecursionlimit(10**9)
X, Y = map(int, input().split())

if (X + Y) % 3:
    print(0)
    exit()

n = (2*X - Y) // 2
m = (-X + 2*Y) // 2

def cmb(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

mod = 10**9 + 7
N = (n + m)
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 )

a = cmb(n+m, m, mod)

print(a)


Fixed code:
import sys
import math
from itertools import permutations
from itertools import combinations
#input = sys.stdin.readline
sys.setrecursionlimit(10**9)

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

if (X + Y) % 3:
    print(0)
    exit()

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

def cmb(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

mod = 10**9 + 7
N = (n + m)
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 )

a = cmb(n+m, m, mod)

print(a)
Buggy code:
def main():
    X, Y = map(int, input().split())
    a = (X+Y)//3
    ans = 0
    mod = 10**9+7

    f = [1]
    for i in range(a):
        f.append(f[i]*(i+1)%mod)

    if (X+Y)%3 == 0:
        for i in range(a+1):
            print('i, a-i',i, a-i)
            x = i + 2 * (a - i)
            y = (2 * i) + (a - i)
            if X == x and Y == y:
                 ans += f[a] * pow(f[i], mod-2, mod)%mod * pow(f[a-i], mod-2, mod)%mod
                                                             
    print(ans)

if __name__ == '__main__':
    main()

Fixed code:
def main():
    X, Y = map(int, input().split())
    a = (X+Y)//3
    ans = 0
    mod = 10**9+7

    f = [1]
    for i in range(a):
        f.append(f[i]*(i+1)%mod)

    if (X+Y)%3 == 0:
        for i in range(a+1):
            x = i + 2 * (a - i)
            y = (2 * i) + (a - i)
            if X == x and Y == y:
                 ans += f[a] * pow(f[i], mod-2, mod)%mod * pow(f[a-i], mod-2, mod)%mod
                                                             
    print(ans)

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

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

if (X + Y) % 3 != 0 or X > 2 * Y:
    print(0)
    exit()

n = 0
m = 0

for n in range(X + 1):
    if (X - n) % 2 != 0:
        continue
    else:
        m = (X - n) // 2
        if 2 * n + m == Y:
            break

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

print(n, m)

p = 1
q = 1
mod = 10 ** 9 + 7

for i in range(m):
    p *= (n + m - i)
    p %= mod
    q *= (m - i)
    q %= mod

ans = p * pow(q, mod - 2, mod)

print(ans % mod)


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

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

if (X + Y) % 3 != 0 or X > 2 * Y:
    print(0)
    exit()

n = 0
m = 0

for n in range(X + 1):
    if (X - n) % 2 != 0:
        continue
    else:
        m = (X - n) // 2
        if 2 * n + m == Y:
            break

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

# print(n, m)

p = 1
q = 1
mod = 10 ** 9 + 7

for i in range(m):
    p *= (n + m - i)
    p %= mod
    q *= (m - i)
    q %= mod

ans = p * pow(q, mod - 2, mod)

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

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

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

def power(n, r, mod):
    if r == 0: return 1
    if r%2 == 0:
        return power(n*n % mod, r//2, mod) % mod
    if r%2 == 1:
        return n * power(n, r-1, mod) % mod

def comb(n, k, mod):
    a=framod(n, mod)
    b=framod(k, mod)
    c=framod(n-k, mod)
    return (a * power(b, mod-2, mod) * power(c, mod-2, mod)) % mod

Z=((X+Y)//3)

if (X+Y)%3==0 and abs(X-Y)<=Z:
  ans=(comb(Z, X-Z,(10**9+7)
  print(ans)
else:
  print(0)

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

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

def power(n, r, mod):
    if r == 0: return 1
    if r%2 == 0:
        return power(n*n % mod, r//2, mod) % mod
    if r%2 == 1:
        return n * power(n, r-1, mod) % mod

def comb(n, k, mod):
    a=framod(n, mod)
    b=framod(k, mod)
    c=framod(n-k, mod)
    return (a * power(b, mod-2, mod) * power(c, mod-2, mod)) % mod

Z=((X+Y)//3)

if (X+Y)%3==0 and abs(X-Y)<=Z:
  ans=(comb(Z, X-Z,(10**9+7)))
  print(ans)
else:
  print(0)
Buggy code:
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 code:
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 code:
N,T=map(int,input().split())
L=[]
for i in range(N):
  a,b=map(int,input().split())
  L.append((a,b))
L.sort()

DP=[[0 for i in range(T)] for j in range(N+1)]

for i in range(N):
  for j in range(T):
    if j-L[i][0]>=0 and i>0:
      DP[i][j]=max(DP[i-1][j-L[i-1][0]]+L[i-1][1],DP[i-1][j])
ans=0
for i in range(N):
  if i!=N:
    ans=max(ans,DP[i][T-1]+L[i][1])
  else:
    ans=max(ans,DP[i][T-1])

print(ans)

Fixed code:
N,T=map(int,input().split())
L=[]
for i in range(N):
  a,b=map(int,input().split())
  L.append((a,b))
L.sort()

DP=[[0 for i in range(T)] for j in range(N+1)]

for i in range(1,N+1):
  for j in range(T):
    if i>0 and j-L[i-1][0]>=0:
      DP[i][j]=max(DP[i-1][j-L[i-1][0]]+L[i-1][1],DP[i-1][j])
    else:
      DP[i][j]=DP[i-1][j]
ans=0
for i in range(N+1):
  if i!=N:
    ans=max(ans,DP[i][T-1]+L[i][1])
  else:
    ans=max(ans,DP[i][T-1])

print(ans)
Buggy code:
N, T = map(int, input().split())
fs = [tuple(map(int, input().split())) for _ in range(N)]
fs = sorted(fs)
dp = [0] * 6005

for a, b in fs:
    for t in range(T + a, a - 1, -1):
        dp[t] = max(dp[t - a] + b, dp[t])
print(max(dp))


Fixed code:
N, T = map(int, input().split())
fs = [tuple(map(int, input().split())) for _ in range(N)]
fs = sorted(fs)
dp = [0] * 6005

for a, b in fs:
    for t in range(T + a - 1, a - 1, -1):
        dp[t] = max(dp[t - a] + b, dp[t])
print(max(dp))