qyliang/CodeNanoFix huggingface dataset:
Buggy code:
import sys
input = lambda: sys.stdin.readline().rstrip() 

def resolve():
    X, Y = map(int, input().split())
    p = 10**9+7

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

    if (X+Y)%3==0 and Y<=X*2 and X<=Y*2:
        n = (X+Y)//3
        r = X-(X+Y)//3
        print(combMod(n, r, p))
    else:
        print('0')

Fixed code:
import sys
input = lambda: sys.stdin.readline().rstrip() 

def resolve():
    X, Y = map(int, input().split())
    p = 10**9+7

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

    if (X+Y)%3==0 and Y<=X*2 and X<=Y*2:
        n = (X+Y)//3
        r = X-(X+Y)//3
        print(combMod(n, r, p))
    else:
        print('0')

if __name__ == '__main__':
    resolve()
Buggy code:
#!/usr/bin/env python
# coding: utf-8

# In[8]:


def nCk(n, k, mod):
    a = 1
    for i in range(n, n-k, -1):
        a *= i
        a %= mod
    b = 1
    for i in range(1, k+1):
        b *= i
        b %= mod
    a *= pow(b, mod-2, mod)
    return a


# In[1]:


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


# In[10]:


mod = 10**9+7
if (x+y)%3 != 0:
    ans = 0
else:
    right = x - (x+y)//3
    up = y - (x+y)//3
    ans = nCk(right+up,right,mod)
print(ans)


# In[ ]:






Fixed code:
#!/usr/bin/env python
# coding: utf-8

# In[8]:


def nCk(n, k, mod):
    a = 1
    for i in range(n, n-k, -1):
        a *= i
        a %= mod
    b = 1
    for i in range(1, k+1):
        b *= i
        b %= mod
    a *= pow(b, mod-2, mod)
    return a


# In[12]:


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


# In[14]:


mod = 10**9+7
if (x+y)%3 != 0:
    ans = 0
else:
    right = x - (x+y)//3
    up = y - (x+y)//3
    if right < 0 or up < 0:
        ans = 0
    else:
        ans = nCk(right+up,right,mod)%mod
print(ans)


# In[ ]:
Buggy code:
import numpy as np
import math

def cmb(n, r, mod):
    n_1 = 1
    n_2 = 1

    r = min(r, n-r)
    for i in range(1, r+1):
        n_1 = n_1 * i % mod
        n_2 = n_2 * (n - i + 1) % mod

    return (n_2 * pow(n_1, mod - 2, mod))%mod

mod = 10**9+7

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

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

if x < 0 or y < 0:
    print(0)
else:
    print(cmb(int(x+y), int(x), mod))


Fixed code:
import numpy as np
import math

def cmb(n, r, mod):
    n_1 = 1
    n_2 = 1

    r = min(r, n-r)
    for i in range(1, r+1):
        n_1 = n_1 * i % mod
        n_2 = n_2 * (n - i + 1) % mod

    return (n_2 * pow(n_1, mod - 2, mod))%mod

mod = 10**9+7

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

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


if x.is_integer() == False or y.is_integer() == False or x < 0 or y < 0:
    print(0)
else:
    print(cmb(int(x+y), int(x), mod))
Buggy code:
p = 10**9+7
def pow(x,m):
    if m==0:
        return 1
    if m==1:
        return x%p
    if m%2==0:
        return (pow(x,m//2)**2)%p
    else:
        return (x*(pow(x,(m-1)//2)**2)%p)%p
A = [1 for _ in range(10**6+1)]
for i in range(1,10**6+1):
    A[i] = (A[i-1]*i)%p
B = [1 for _ in range(10**6+1)]
for i in range(2,10**6+1):
    B[i] = pow(A[i],p-2)

X,Y = map(int,input().split())
if (X+Y)%3!=0:
    cnt = 0
else:
    k = (X+Y)//3
    if X>Y:
        X,Y = Y,X
    n = X-k
    cnt = (A[k]*B[n]*B[k-n])%p
print(cnt)

Fixed code:
p = 10**9+7
def pow(x,m):
    if m==0:
        return 1
    if m==1:
        return x%p
    if m%2==0:
        return (pow(x,m//2)**2)%p
    else:
        return (x*(pow(x,(m-1)//2)**2)%p)%p
A = [1 for _ in range(10**6+1)]
for i in range(1,10**6+1):
    A[i] = (A[i-1]*i)%p
B = [1 for _ in range(10**6+1)]
B[10**6] = pow(A[10**6],p-2)
for i in range(10**6-1,1,-1):
    B[i] = (B[i+1]*(i+1))%p

X,Y = map(int,input().split())
if (X+Y)%3!=0:
    cnt = 0
else:
    k = (X+Y)//3
    if X>Y:
        X,Y = Y,X
    n = X-k
    if X<k:
        cnt = 0
    else:
        cnt = (((A[k]*B[n])%p)*B[k-n])%p
print(cnt)
Buggy code:
x,y = map(int,input().split())

mod = 10**9 + 7

if (x+y)%3 != 0:
    print(0)
    
else:
    
    n=(x+y)//3
    
    r = min(x-n,y-n)
    
    p=1
    q=1
    for i in range(r):
       
        p *= n-i
        

        q *= (i+1)
            
    ans = p * pow(q,mod-2,mod)
    ans %= mod
        
    print(ans)


Fixed code:
x,y = map(int,input().split())

mod = 10**9 + 7

if (x+y)%3 != 0:
    print(0)
    
else:
    
    n=(x+y)//3
    
    r = min(x-n,y-n)
    
    if r<0:
        print(0)
        
    else:
    
        p=1
        q=1
        for i in range(r):
           
            p *= n-i
            p %= mod
            
    
            q *= i+1
            q %= mod
                
        ans = p * pow(q,mod-2,mod)
        ans %= mod
            
        print(ans)
Buggy code:
def inv(a,p):
    if a==1:
        return 1
    elif a==0:
        return 0
    return p-(inv(p%a,p)*(p//a))%p
x,y=map(int,input().split())
if (x+y)%3!=0:
    print("0")
    exit()
n=(x+y)//3
r=(2*x-y)//3
p=10**9+7
def fact(n,p):
    a=[[] for _ in range(n+1)]
    a[0]=1
    for i in range(n):
        a[i+1]=(a[i]*(i+1))%p
    return a
f=fact(n,p)
if len(f)>=r:
    print("0")
    exit()
c=f[-1]
d=f[r]
e=f[n-r]
dd=inv(d,p)
ee=inv(e,p)
ans=(c*dd*ee)%p
print(ans)

Fixed code:
def inv(a,p):
    if a==1:
        return 1
    elif a==0:
        return 0
    return p-(inv(p%a,p)*(p//a))%p
x,y=map(int,input().split())
if (x+y)%3!=0:
    print("0")
    exit()
if x==0 and y>0:
    print("0")
    exit()
if y/x>2 or y/x<0.5:
    print("0")
    exit()
n=(x+y)//3
r=(2*x-y)//3
p=10**9+7
def fact(n,p):
    a=[[] for _ in range(n+1)]
    a[0]=1
    for i in range(n):
        a[i+1]=(a[i]*(i+1))%p
    return a
f=fact(n,p)
c=f[-1]
d=f[r]
e=f[n-r]
dd=inv(d,p)
ee=inv(e,p)
ans=(c*dd*ee)%p
print(ans)
Buggy code:
X,Y=map(int,input().split())
N=(X+Y)//3
import sys
sys.setrecursionlimit(10**8)
A=X-N
B=Y-N
No=False
if (X+Y)%3!=0 or X<N or Y<N:
    No=True
ans=1
C=min(A,B)
for i in range(0, C):
    ans*=N-i
    ans%=(10**9+7)
def inv(i, p, q):
    if q==1:
        return i%p
    if q%2==0:
        x=inv(i, p,q//2)
        return (x**2)%p
    else:
        x=inv(i, p,q//2)
        return (x**2*i)%p
tmp=1
for i in range(C):
    tmp*=(i+1)
    tmp%=(10**9+7)
iv=inv(tmp, 10**9+7,10**9+5)
ans=ans*iv%(10**9+7)
if No:
    print(0)
else:
    print("ans",ans)

Fixed code:
X,Y=map(int,input().split())
N=(X+Y)//3
import sys
sys.setrecursionlimit(10**8)
A=X-N
B=Y-N
No=False
if (X+Y)%3!=0 or X<N or Y<N:
    No=True
ans=1
C=min(A,B)
for i in range(0, C):
    ans*=N-i
    ans%=(10**9+7)
def inv(i, p, q):
    if q==1:
        return i%p
    if q%2==0:
        x=inv(i, p,q//2)
        return (x**2)%p
    else:
        x=inv(i, p,q//2)
        return (x**2*i)%p
tmp=1
for i in range(C):
    tmp*=(i+1)
    tmp%=(10**9+7)
iv=inv(tmp, 10**9+7,10**9+5)
ans=ans*iv%(10**9+7)
if No:
    print(0)
else:
    print(ans)
Buggy code:
a, b = map(int, input().split())

aa=int(0)
x=max([a, b])
y=min([a, b])

if (x+y)%3 ==0 and x < y*2:
    aa=int(1)

n=int((x+y)/3)
k=int((n-(x-y))/2)


def comb(n, k, mod=10**9+7):
    numer = denom = 1
    for i in range(k):
        numer = (numer * (n-i)) % mod
        denom = (denom * (i+1)) % mod
    return (numer * pow(denom, mod-2, mod)) % mod


print(comb(n,k))


Fixed code:

a, b = map(int, input().split())

aa=int(0)
x=max([a, b])
y=min([a, b])

if (x+y)%3 ==0 and x <= y*2:
    aa=int(1)

n=int((x+y)/3)
k=int((n-(x-y))/2)


def comb(n, k, mod=10**9+7):
    numer = denom = 1
    for i in range(k):
        numer = (numer * (n-i)) % mod
        denom = (denom * (i+1)) % mod
    return (numer * pow(denom, mod-2, mod)) % mod

if aa==1:
    print(comb(n,k))
else:
    print(aa)
Buggy code:
import random
MOD = 10 ** 9 + 7
fac = [1] * (10 ** 6 * 2 + 2)
for i in range(len(fac) - 1):
    fac[i + 1] = fac[i] * (i + 1) % MOD
x, y = map(int, input().split())
t = min(x, y) // 3
if (2 * x - y) % 3 or (2 * y - x) % 3:
    print(0)
a, b = (2 * x - y) // 3, (2 * y - x) // 3
k = max(a, b)
n = a + b
print((fac[n] * pow(fac[n - k], MOD - 2, MOD)
       * pow(fac[k], MOD - 2, MOD)) % MOD)

Fixed code:
import random
MOD = 10 ** 9 + 7
fac = [1] * (10 ** 6 * 2 + 2)
for i in range(len(fac) - 1):
    fac[i + 1] = fac[i] * (i + 1) % MOD
x, y = map(int, input().split())
t = min(x, y) // 3
if (2 * x - y) % 3 or (2 * y - x) % 3 or 2 * x < y or 2 * y < x:
    print(0)
    exit(0)
a, b = (2 * x - y) // 3, (2 * y - x) // 3
k = min(a, b)
n = a + b
print((fac[n] * pow(fac[n - k], MOD - 2, MOD)
       * pow(fac[k], MOD - 2, MOD)) % MOD)
Buggy code:
import math

def comb(n, k, MOD, N):
    fact = [1]*(N+1)
    rfact = [1]*(N+1)
    r = 1
    for i in range(1, N+1):
        fact[i] = r = r * i % MOD
    rfact[N] = r = pow(fact[N], MOD-2, MOD)
    for i in range(N, 0, -1):
        rfact[i-1] = r = r * i % MOD
    return fact[n] * rfact[k] * rfact[n-k] % MOD

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

diff = abs(x-y)
if (min(x, y) - diff) % 3 != 0:
    print(0)
else:
    count = (min(x, y) - diff) // 3
    print(comb(2*count+diff, count, mod, 10**7))

Fixed code:
import math

def comb(n, k, MOD, N):
    fact = [1]*(N+1)
    rfact = [1]*(N+1)
    r = 1
    for i in range(1, N+1):
        fact[i] = r = r * i % MOD
    rfact[N] = r = pow(fact[N], MOD-2, MOD)
    for i in range(N, 0, -1):
        rfact[i-1] = r = r * i % MOD
    return fact[n] * rfact[k] * rfact[n-k] % MOD

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

diff = abs(x-y)
if (min(x, y) - diff) % 3 != 0 or (min(x, y) - diff) < 0:
    print(0)
else:
    count = (min(x, y) - diff) // 3
    print(comb(2*count+diff, count, mod, 10**6))
Buggy code:
x,y=map(int,input().split())
a=-1
p=10**9+7
for i in range(x//2+1):
  if i+2*(x-2*i)==y:
    a=i
    break
if a==-1:
  print(0)
  exit()
elif a==0:
  print(1)
else:
  gyaku=[0,1]
  for i in range(2,a+1):
    gyaku.append(((p//i)*-gyaku[p%i])%p)
  com=[1]
  for i in range(1,a+1):
    com.append(com[-1]*gyaku[i]*(x-a+1-i)%p)
　　print(com[a])


Fixed code:
x,y=map(int,input().split())
a=-1
p=10**9+7
for i in range(x//2+1):
  if i+2*(x-2*i)==y:
    a=i
    break
if a==-1:
  print(0)
  exit()
elif a==0:
  print(1)
  exit()
else:
  gyaku=[0,1]
  for i in range(2,a+1):
    gyaku.append(((p//i)*-gyaku[p%i])%p)
  com=[1]
  for i in range(1,a+1):
    com.append(com[-1]*gyaku[i]*(x-a+1-i)%p)
print(com[-1])
Buggy code:
# -*- coding: utf-8 -*-
import math

def mod_factorial(n):
    mod = 10**9+7

    if n < 1:
        return 1

    r = n
    for i in range(n-1):
        r = r*(i+1) % mod
    
    return r

def mod_pow(n,m):

    mod = 10**9+7
    r = 1

    while m > 0:
        if m & 1:
            r = r*n % mod
        n = n * n % mod
        m = m>>1

    return(r)



def mod_comb(n, k):
    mod = 10**9+7

    if n+k < 1:
        return 1
    
    a = mod_factorial(n)
    b = mod_pow(mod_factorial(k), mod-2)
    c = mod_pow(mod_factorial(n-k), mod-2)


    return (a * ((b * c) % mod)) % mod


a, b= map(int, input().split())

t = [a,b]

r = 0
mod = 10**9+7

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

if (x%3 == 0 and y%3 == 0) and (x > 0 and y > 0):
    m = int(x/3)
    n = int((y/3)

    r += mod_comb(n+m,m)

print(r)

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

def mod_factorial(n):
    mod = 10**9+7

    if n < 1:
        return 1

    r = n
    for i in range(n-1):
        r = r*(i+1) % mod
    
    return r

def mod_pow(n,m):

    mod = 10**9+7
    r = 1

    while m > 0:
        if m & 1:
            r = r*n % mod
        n = n * n % mod
        m = m>>1

    return(r)



def mod_comb(n, k):
    mod = 10**9+7

    if n+k < 1:
        return 1
    
    a = mod_factorial(n)
    b = mod_pow(mod_factorial(k), mod-2)
    c = mod_pow(mod_factorial(n-k), mod-2)


    return (a * ((b * c) % mod)) % mod


a, b= map(int, input().split())

t = [a,b]

r = 0
mod = 10**9+7

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

if x%3 == 0 and y%3 == 0 and x*y >=0:
    m = int(x/3)
    n = int(y/3)

    r += mod_comb(n+m,m)

print(r)
Buggy code:
mod=10**9+7
def fact(n):
    ans=1
    for i in range(1,n+1):
        ans*=i
        ans%=mod
    return ans

x,y=map(int,input().split())
if (x+y)%3!=0: print(0)
else:
    temp=(x+y)//3
    if x<temp or x>2*temp: print(0)
    else:
        dx=x-temp
        fc_temp=fact(temp)
        fc_dx=fact(dx)
        fc_temp_dx=fact(temp-dx)
        fc_dx=pow(fc_dx,mod-2,mod)
        fc_temp_dx=pow(fc_temp_dx,mod-2,mod)
        ans=fc_temp*fc_dx%mod*fc_temp_dx*mod
        print(ans)

Fixed code:
mod=10**9+7
def fact(n):
    ans=1
    for i in range(1,n+1):
        ans*=i
        ans%=mod
    return ans

x,y=map(int,input().split())
if (x+y)%3!=0: print(0)
else:
    temp=(x+y)//3
    if x<temp or x>2*temp: print(0)
    else:
        dx=x-temp
        fc_temp=fact(temp)
        fc_dx=fact(dx)
        fc_temp_dx=fact(temp-dx)
        fc_dx=pow(fc_dx,mod-2,mod)
        fc_temp_dx=pow(fc_temp_dx,mod-2,mod)
        ans=fc_temp*fc_dx%mod*fc_temp_dx%mod
        print(ans)
Buggy code:
MOD = 7+1000000000

def modinv(a, mod=10**9+7):
    return pow(a, mod-2, mod)
def combination(n, r, mod=10**9+7):
    r = min(r, n-r)
    res = 1
    for i in range(r):
        res = res * (n - i) * modinv(i+1, mod) % mod
    return res

def solve():
  X,Y = map(int,input().split())
  if (X+Y)%3:
    return -1
  if (2*X-Y)%3:
    return -1
  m = (2*X-Y)//3
  n = X - 2*m
  if m < 0 or n < 0:
    return -1
  from itertools import combinations
  return (combination(m+n,m))

print(solve())

Fixed code:
MOD = 7+1000000000

def modinv(a, mod=10**9+7):
    return pow(a, mod-2, mod)
def combination(n, r, mod=10**9+7):
    r = min(r, n-r)
    res = 1
    for i in range(r):
        res = res * (n - i) * modinv(i+1, mod) % mod
    return res

def solve():
  X,Y = map(int,input().split())
  if (X+Y)%3:
    return 0
  if (2*X-Y)%3:
    return 0
  m = (2*X-Y)//3
  n = X - 2*m
  if m < 0 or n < 0:
    return 0
  return (combination(m+n,m))

print(solve())
Buggy code:
def mod_inv(a, m):
    return pow(a, m-2, m)


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

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

n = (X + Y) // 3
nx, ny = X - n, Y - n

if nx < 0 or ny < 0:
    print(0)
    exit()

ans = 1
for i in range(nx + 1, nx + ny + 1):
    ans = ans * mod_inv(i, MOD) % MOD
for i in range(1, ny + 1):
    ans = ans * mod_inv(i, MOD) % MOD

print(ans)


Fixed code:
def mod_inv(a, m):
    return pow(a, m-2, m)


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

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

n = (X + Y) // 3
nx, ny = X - n, Y - n

if nx < 0 or ny < 0:
    print(0)
    exit()

ans = 1
for i in range(nx + 1, nx + ny + 1):
    ans = ans * i % MOD
for i in range(1, ny + 1):
    ans = ans * mod_inv(i, MOD) % MOD

print(ans)
Buggy code:
def combination(n, a):
    mod = pow(10, 9)+7
    x, y = 1, 1
    for i in range(a):
        x = x * (n-i)%mod
        y = y * (a-i)%mod
    return x * pow(y, mod-2, mod)%mod

x, y = map(int, input().split())
n, m = (2*y - x)//3, (2*x - y)//3
if (x + y)%3 != 0 and (n < 0 and m < 0):
    print(0)
else:
    ans2 = combination(n+m, n)
    print(ans2)


Fixed code:
def combination(n, a):
    mod = pow(10, 9)+7
    x, y = 1, 1
    for i in range(a):
        x = x * (n-i)%mod
        y = y * (a-i)%mod
    return x * pow(y, mod-2, mod)%mod

x, y = map(int, input().split())
n, m = (2*y - x)//3, (2*x - y)//3
if (x + y)%3 != 0 or (n < 0 or m < 0):
    print(0)
else:
    ans2 = combination(n+m, n)
    print(ans2)
Buggy code:
x, y = map(int, input().split())

mod = 10 ** 9 + 7


def choose(n, r):
    cx = 1
    cy = 1
    for i in range(r):
        cx = cx * (n - i) % mod
        cy = cy * (i + 1) % mod
    cy = pow(y, mod - 2, mod)
    return cx * cy % mod


if (x + y) % 3 != 0 or x < 0 or y < 0:
    print(0)
    exit()
else:
    n = (x + y) // 3
    x -= n
    y -= n
    print(choose(x + y, x))


Fixed code:
x, y = map(int, input().split())

mod = 10 ** 9 + 7


def choose(n, r):
    cx = 1
    cy = 1
    for i in range(r):
        cx = cx * (n - i) % mod
        cy = cy * (i + 1) % mod
    cy = pow(cy, mod - 2, mod)
    return cx * cy % mod


if (x + y) % 3 != 0:
    print(0)
    exit()
else:
    n = (x + y) // 3
    x -= n
    y -= n
    if x < 0 or y < 0:
        print(0)
        exit()
    print(choose(x + y, x))
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())
for i in range(X):
  if (X-i)%2!=0:
    continue
  n=int((X-i)/2)
  if Y==i*2+n*1:
    ans=cmb(i+n,i)
    print(ans%1000000007)
    exit()
    
print(X,Y)

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())
if (X+Y)%3!=0:
  print(0)
  exit()
for i in range(X+1):
  n=int((X-i)/2)
  if Y==i*2+n*1:
    print(cmb(i+n,i)%1000000007)
    exit()
    
print(0)
Buggy code:
x,y = map(int,input().split())
mod = 10**9+7
if 2*x-y%3!=0 and 2*y-x!=0:
  print(0)
  exit()
n = (2*x-y)//3
m = (2*y-x)//3
#n+mCm
if n==0 or m==0:
  print(1)
  exit()
def ka(x):
  a = 1
  while x!=1:
    a *= x
    x -= 1
    a%= mod
  return a

ans = (ka(n+m)*pow(ka(m),mod-2,mod)*pow(ka(n),mod-2,mod))%mod
print(ans)

Fixed code:
x,y = map(int,input().split())
mod = 10**9+7
if (x+y)%3!=0:
  print(0)
  exit()
if 2*min(x,y)<max(x,y):
  print(0)
  exit()
n = (2*x-y)//3
m = (2*y-x)//3
#n+mCm
if n==0 or m==0:
  print(1)
  exit()
def ka(x):
  a = 1
  while x!=1:
    a *= x
    x -= 1
    a%= mod
  return a

ans = (ka(n+m)*pow(ka(m),mod-2,mod)%mod)*(pow(ka(n),mod-2,mod))%mod
print(ans)
Buggy code:
X, Y = map(int,input().split())

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

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

mod = 10**9+7


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

print(comb(n+m, n, mod))

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

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

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

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

mod = 10**9+7


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

print(comb(n+m, n, mod))
Buggy code:
X, Y = map(int, input().split())

P_MOD = 10 ** 9 + 7

def myinv(arg):
    bit = []
    tmp = P_MOD - 2
    for i in range(64):
        if tmp < 1: break
        bit.append(tmp % 2)
        tmp >>= 1
    N_bit = len(bit)
    #
    ret = 1
    arg_tmp = arg
    for i in range(N_bit):
        if bit[i] == 1:
            ret = (ret * arg_tmp) % P_MOD
        arg_tmp = (arg_tmp * arg_tmp) % P_MOD
    #
    return ret

if ((2 * X - Y) % 3 > 0) or ((2 * Y - X) % 3 > 0):
    print(0)
else:
    num_a = min((2 * Y - X) // 3, (2 * X - Y) // 3)
    num_b = max((2 * Y - X) // 3, (2 * X - Y) // 3)
    #
    ans = 1
    for i in range(num_a):
        ans = (ans * (num_b + i + 1)) % P_MOD
    for i in range(num_a):
        ans = (ans * myinv(i + 1)) % P_MOD
    #
    print(ans)

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

P_MOD = 10 ** 9 + 7

bit = []
tmp = P_MOD - 2
for i in range(64):
    if tmp < 1: break
    bit.append(tmp % 2)
    tmp >>= 1
    
def myinv(arg):
    N_bit = len(bit)
    #
    ret = 1
    arg_tmp = arg
    for i in range(N_bit):
        if bit[i] == 1:
            ret = (ret * arg_tmp) % P_MOD
        arg_tmp = (arg_tmp * arg_tmp) % P_MOD
    #
    return ret

if ((2 * X - Y) % 3 > 0) or ((2 * Y - X) % 3 > 0):
    print(0)
else:
    num_a = min((2 * Y - X) // 3, (2 * X - Y) // 3)
    num_b = max((2 * Y - X) // 3, (2 * X - Y) // 3)
    if num_a < 0 or num_b < 0:
        print(0)
    else:
        ans = 1
        for i in range(num_a):
            ans = (ans * (num_b + i + 1)) % P_MOD
        for i in range(num_a):
            ans = (ans * myinv(i + 1)) % P_MOD
        #
        print(ans)
Buggy code:
m = 10 ** 9 + 7
def cmb(x,y):
    r=1
    for i in range(1,y+1):
        r=(r*(x-i+1)*pow(i,m-2,m))%m
    return r

x, y = map(int, input().split())
if (2 * x - y) % 3 == 0 and (2 * y - x) % 3 == 0:
    print(cmb(int((x + y) / 3), int((2 * y - x) / 3)))

Fixed code:
m = 10 ** 9 + 7
def cmb(x,y):
    r = 1
    for i in range(1, y + 1):
        r = (r * (x - i + 1) * pow(i, m-2, m)) % m
    return r

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

a = (2 * x - y) / 3
b = (2 * y - x) / 3
if (x + y) % 3 == 0 and a >= 0 and b >= 0:
    print(cmb(int((x + y) / 3), int(a)))
else:
    print(0)
Buggy code:
# https://atcoder.jp/contests/abc145/tasks/abc145_d

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

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

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

n = x + y
r = x


mod = 10**9 + 7
f = 1
fac = [f]
for i in range(1, n + 1):
    f = f*i % mod
f = pow(f, mod-2, mod)
facinv = [f]
for i in range(n, 0, -1):
    f = f*i % mod
    facinv.append(f)

print(fac[n] * facinv[r] * facinv[n - r] % mod)

Fixed code:
# https://atcoder.jp/contests/abc145/tasks/abc145_d


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

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

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

if x < 0 or y < 0:
    print(0)
    exit()

n = x + y
r = x


mod = 10**9 + 7
f = 1
for i in range(1, n + 1):
    f = f*i % mod
fac = f
f = pow(f, mod-2, mod)
facinv = [f]
for i in range(n, 0, -1):
    f = f*i % mod
    facinv.append(f)
facinv.append(1)

print(fac * facinv[r] * facinv[n - r] % mod)
Buggy code:
#ABC145D

MOD = 10 ** 9 + 7
import math
x,y = map(int,input().split())
a,b = -1,-1

for i in range(x):
    m = 0
    if (x-i) % 2 == 0:
        m = (x-i) // 2
        if 2*i + m == y:
            if i >= 0 and m >= 0:
                a = i
                b = m
                break
    else:
        continue
MAX_N = 10**6

fact = [1]
fact_inv = [0]*(MAX_N+4)
for i in range(MAX_N+3):
    fact.append(fact[-1]*(i+1)%MOD)

fact_inv[-1] = pow(fact[-1],mod-2,MOD)
for i in range(MAX_N+2,-1,-1):
    fact_inv[i] = fact_inv[i+1]*(i+1)%MOD

def com(n,k,mod):
    return fact[n] * fact_inv[k] % mod * fact_inv[n-k] %mod  
        
        
if a == -1 and b == -1:
    print(0)
else:
    print(com(a+b,a,MOD))

Fixed code:
#ABC145D

MOD = 10 ** 9 + 7
import math
x,y = map(int,input().split())
a,b = -1,-1

for i in range(x+1):
    m = 0
    if (x-i) % 2 == 0:
        m = (x-i) // 2
        if 2*i + m == y:
            if i >= 0 and m >= 0:
                a = i
                b = m
                break
    else:
        continue
        
MAX_N = 10**6

fact = [1]
fact_inv = [0]*(MAX_N+4)
for i in range(MAX_N+3):
    fact.append(fact[-1]*(i+1)%MOD)

fact_inv[-1] = pow(fact[-1],MOD-2,MOD)
for i in range(MAX_N+2,-1,-1):
    fact_inv[i] = fact_inv[i+1]*(i+1)%MOD

def com(n,k,mod):
    return fact[n] * fact_inv[k] % mod * fact_inv[n-k] %mod  
        
        
if a == -1 and b == -1:
    print(0)
else:
    print(com(a+b,a,MOD))