qyliang/CodeNanoFix huggingface dataset:
Buggy code:
#coding:utf-8
x, y = map(int, input().split())

mod = 10**9 + 7
f = [1]
for i in range(10**6):
    f.append(f[-1] * (i+1) % mod)
    
def nCr(n, r):
    return f[n] * pow(f[r], f[r] ** (mod-2), mod) * pow(f[n-r] ** (mod-2), mod) % mod

def main():
    if (x + y) % 3 != 0 or (x + y) // 3 < abs(x - y):
        print(0)
        return

    n = (x + y) // 3
    r = n - abs(x - y)
    print(nCr(n, r))
    return
    
main()

Fixed code:
#coding:utf-8
x, y = map(int, input().split())

mod = 10**9 + 7
f = [1]
for i in range(10**6):
    f.append(f[-1] * (i+1) % mod)
    
def nCr(n, r):
    return f[n] * pow(f[r], mod-2, mod) * pow(f[n-r], mod-2, mod) % mod

def main():
    if (x + y) % 3 != 0 or (x + y) // 3 < abs(x - y):
        print(0)
        return
    
    n = (x + y) // 3
    r = n // 2 - abs(x-y) // 2
    print(nCr(n, r))
    return
    
main()
Buggy code:
def com(n,k,mod):
    r=min(k,n-k)
    s=1
    inv=[1,1]
    for c in range(1,r+1):
        inv.append((-(mod//c)*inv[mod%c])%mod)
        s=(((s*(n+1-c))%mod)*inv[c])%mod
    return s

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

Fixed code:


def com(n,k):
    if k==0:
        return 1
    s=n
    p=10**9+7
    inv=[0,1]
    for c in range(2,k+1):
        inv.append((-(p//c)*inv[p%c])%p)
        s=(((s*(n+1-c))%p)*inv[c])%p
    return s


x,y=map(int,input().split())
if (x+y)%3!=0 or 2*y<x or 2*x<y:
    print(0)
else:
    r=min(2*y-x,2*x-y)//3
    print(com((x+y)//3,r))
Buggy code:
mod=10**9+7
N,K=list(map(int,input().split()))
if (N+K)%3==0 and N*2>K and K*2>N:
   A=max(N,K)-min(N,K)
   low=(min(N,K)-A)//3
   all_pt=low*2+A
up,down=1,1
for i in range(low):
   up=up*(all_pt-i)%mod
   down=down*(i+1)%mod
base=pow(down,mod-2,mod)
print(up*base%mod)

Fixed code:
mod=10**9+7
N,K=list(map(int,input().split()))
if (N+K)%3==0 and N*2>=K and K*2>=N:
   A=max(N,K)-min(N,K)
   low=(min(N,K)-A)//3
   all_pt=low*2+A
else:
   print(0)
   exit()
up,down=1,1
for i in range(low):
   up=up*(all_pt-i)%mod
   down=down*(i+1)%mod
base=pow(down,mod-2,mod)
print(up*base%mod)
Buggy code:
MOD=10**9+7

def cmb(n, r):
    if n < r: return 0 #date added
    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])
            result = result%MOD

    return result

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

print(a, b)

if a.is_integer() and b.is_integer() and a>=0 and b>=0:
    print(cmb(int(a+b), int(a)))
else:
    print(0)


Fixed code:
MOD=10**9+7

def cmb(n, r):
    if n < r: return 0 #date added
    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])
            result = result%MOD

    return result

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

#print(a, b)

if a.is_integer() and b.is_integer() and a>=0 and b>=0:
    print(cmb(int(a+b), int(a)))
else:
    print(0)
Buggy code:
mod = 10 ** 9 + 7
x, y = [int(i) for i in input().split()]
if (2*x - y) % 3 != 0 or (2*y - x) % 3 != 0:
  print(0)
a = (2*x - y) // 3
b = (2*y - x) // 3
def mygcd(a_b, b, mod):
    b = min(a_b, b)
    cnt = 1
    for i in range(b):
        cnt = cnt * (a_b - i) * pow(i+1, mod-2, mod) % mod
    return cnt
print(mygcd(a+b, b, mod))

Fixed code:
mod = 10 ** 9 + 7
x, y = [int(i) for i in input().split()]
if (2*x - y) % 3 != 0 or (2*y - x) % 3 != 0:
  print(0)
  exit()
a = (2*x - y) // 3
b = (2*y - x) // 3
if a < 0 or b < 0:
  print(0)
  exit()
def mygcd(a_b, b, mod):
    b = min(a_b, b)
    cnt = 1
    for i in range(b):
        cnt = cnt * (a_b - i) * pow(i+1, mod-2, mod) % mod
    return cnt
print(mygcd(a+b, b, mod))
Buggy code:
def comb(n, k, mod):
    if k == 0:
        return 1
    else:
        x, y = n, k
        for i in range(1, k):
            x = x * (x - i) % mod
            y = y * (y - i) % mod
        c = x * pow(y, mod - 2, mod) % mod
        return c


x, y = map(int, input().split())
mod = 10 ** 9 + 7
n = (x + y) // 3
if (x + y) % 3 != 0 or not (n <= x <= 2 * n):
    ans = 0
else:
    k = min(x - n, 2 * n - x)
    ans = comb(n, k, mod)
print(ans)

Fixed code:
def comb(n, k, mod):
    if k == 0:
        return 1
    else:
        x, y = 1, 1
        for i in range(k):
            x = x * (n - i) % mod
            y = y * (k - i) % mod
        c = x * pow(y, mod - 2, mod) % mod
        return c


x, y = map(int, input().split())
mod = 10 ** 9 + 7
n = (x + y) // 3
if not((x + y) % 3 == 0 and n <= x <= 2 * n):
    ans = 0
else:
    k = min(x - n, 2 * n - x)
    ans = comb(n, k, mod)
print(ans)
Buggy code:
def combination(n, r, mod=10**9+7):
    n1, r = n+1, min(r, n-r)
    numer = denom = 1
    for i in range(1, r+1):
        numer = numer * (n1-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 or not(X <= 2*Y and Y <= 2*X):
    print(0)
    exit()
else:
    s = (x+y)//3
 
t = min((x-s),(y-s))

print(combination(s,t))

Fixed code:
def combination(n, r, mod=10**9+7):
    n1, r = n+1, min(r, n-r)
    numer = denom = 1
    for i in range(1, r+1):
        numer = numer * (n1-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 or not(x <= 2*y and y <= 2*x):
    print(0)
    exit()
else:
    s = (x+y)//3
 
t = min((x-s),(y-s))

print(combination(s,t))
Buggy code:
def cmb(n, r, prime):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n % prime

    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] = numerator[k - offset] // pivot
                denominator[k] = denominator[k] // pivot

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


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

ans = 0

#if (x + y) % 3 == 0 and (2*x - y) % 3 == 0:
a = (x + y) // 3
b = (2*x - y) // 3
if a >= 0 and b >= 0:
    ans = cmb(a,b, pow(10,9) + 7)
#ans = mod_combination(a,b,pow(10,9) + 7)


print(ans)


Fixed code:
def cmb(n, r, prime):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n % prime

    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] = numerator[k - offset] // pivot
                denominator[k] = denominator[k] // pivot

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


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

ans = 0

if (x + y) % 3 == 0 and 2*x - y >= 0 and 2*y - x >= 0:
    a = (x + y) // 3
    b = (2*x - y) // 3
    ans = cmb(a,b, pow(10,9) + 7)
    #ans = mod_combination(a,b,pow(10,9) + 7)

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

import sys
if X + Y % 3 == 0:
    print(0)
    sys.exit()
offset = (X+Y)//3
X, Y = X-offset, Y-offset

if X<0 or Y<0:
    print(0)
    sys.exit()
    
X, Y = max(X, Y), min(X, Y)

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

print(C(X+Y, Y, mod))

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

import sys
if (X + Y) % 3 != 0:
    print(0)
    sys.exit()
offset = (X+Y)//3
X, Y = X-offset, Y-offset

if X<0 or Y<0:
    print(0)
    sys.exit()
    
X, Y = max(X, Y), min(X, Y)

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

print(C(X+Y, Y, mod))
Buggy code:
class Combination():
    def __init__(self, n, mod=10**9+7):
        self.mod = mod
        self.fac = [1]*(n+1)
        for i in range(1,n+1):
            self.fac[i] = self.fac[i-1] * i % self.mod
        self.invfac = [1]*(n+1)
        self.invfac[n] = pow(self.fac[n], self.mod - 2, self.mod)
        for i in range(n-1, 0, -1):
            self.invfac[i] = self.invfac[i+1] * (i+1) % self.mod

    def combination(self, n, r):
        return self.fac[n] * self.invfac[r] % self.mod * self.invfac[n-r] % self.mod

    def permutation(self, n, r):
        return self.factorial(n) * self.invfactorial(n-r) % self.mod

    def factorial(self, i):
        return self.fac[i]

    def invfactorial(self, i):
        return self.invfac[i]

def main():
    import sys

    def input(): return sys.stdin.readline().rstrip()

    x, y= map(int, input().split())
    if 2*x-y < 0 or (2*x-y)%3 != 0 or (x+2*y)%3 != 0:
        print(0)
        return
    l = (2*x-y)//3
    k = (x+2*y)//3
    c = Combination(l+k)
    print(c.combination(l+k, l))

    


if __name__ == '__main__':
    main()

Fixed code:
class Combination():
    def __init__(self, n, mod=10**9+7):
        self.mod = mod
        self.fac = [1]*(n+1)
        for i in range(1,n+1):
            self.fac[i] = self.fac[i-1] * i % self.mod
        self.invfac = [1]*(n+1)
        self.invfac[n] = pow(self.fac[n], self.mod - 2, self.mod)
        for i in range(n-1, 0, -1):
            self.invfac[i] = self.invfac[i+1] * (i+1) % self.mod

    def combination(self, n, r):
        return self.fac[n] * self.invfac[r] % self.mod * self.invfac[n-r] % self.mod

    def permutation(self, n, r):
        return self.factorial(n) * self.invfactorial(n-r) % self.mod

    def factorial(self, i):
        return self.fac[i]

    def invfactorial(self, i):
        return self.invfac[i]

def main():
    import sys

    def input(): return sys.stdin.readline().rstrip()

    x, y= map(int, input().split())
    if 2*x-y < 0 or 2*y-x < 0 or (2*x-y)%3 != 0 or (2*y-x)%3 != 0:
        print(0)
        return
    l = (2*x-y)//3
    k = (2*y-x)//3
    c = Combination(l+k)
    print(c.combination(l+k, l))

    


if __name__ == '__main__':
    main()
Buggy code:
mod=10**9+7

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

x-=z
y-=z

n=x+y
r=x


lst=[0]+[1]
for i in range(2,n+10):
  lst.append((lst[-1]*i)%mod)


xxx=lst[n]
xxx*=pow(lst[n-r],10**9+5,mod)
xxx%=mod
xxx*=pow(lst[r],10**9+5,mod)
xxx%=mod

print(xxx)

Fixed code:
mod=10**9+7

x,y=map(int,input().split())
if (x+y)%3!=0:
  print(0)
  exit()
  
if x*2<y or y*2<x:
  print(0)
  exit()
  
z=(x+y)//3

x-=z
y-=z

n=x+y
r=x

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

lst=[0]+[1]
for i in range(2,n+10):
  lst.append((lst[-1]*i)%mod)


xxx=lst[n]
xxx*=pow(lst[n-r],10**9+5,mod)
xxx%=mod
xxx*=pow(lst[r],10**9+5,mod)
xxx%=mod

print(xxx)
Buggy code:
X,Y = map(int,input().split())
 
c1 = (2*Y-X)
if (c1%3!=0)or(X-c1<0)or(Y-2*c1):
  print(0)

else:
 
  c1 = c1//3
  c2 = Y-2*c1
  c3 = c1+c2+1
  mod = 10**9+7
  c4 = min(c1,c2)
  x = 1
  y = 1
  for i in range(1,c4+1):
    x = x * (c3-i) % mod
    y = y * i % mod
    
  result = x * pow(y,mod-2,mod) % mod
 
  print(result)

Fixed code:
X,Y = map(int,input().split())
 
c1 = (2*Y-X)
rest = c1%3
c1 = c1//3
if (rest!=0)or((X-c1)<0)or((Y-2*c1)<0)or(c1<0):
  print(0)

else:
  c2 = Y-2*c1
  c3 = c1+c2+1
  mod = 10**9+7
  c4 = min(c1,c2)
  x = 1
  y = 1
  for i in range(1,c4+1):
    x = x * (c3-i) % mod
    y = y * i % mod
    
  result = x * pow(y,mod-2,mod) % mod
 
  print(result)
Buggy code:
import sys
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
a,b=map(int,input().split())
c=int((2*a-b)/3)
if c<0 or a+b>c:
    print('0')
    sys.exit()
if (a+b)%3!=0:
    print('0')
    sys.exit()
print(cmb((a+b)//3,c)%1000000007)

Fixed code:
import sys
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
a,b=map(int,input().split())
c=int((2*a-b)/3)
if (a+b)%3!=0:
    print('0')
    sys.exit()
if c<0 or (a+b)//3<c:
    print('0')
    sys.exit()
print(cmb((a+b)//3,c)%1000000007)
Buggy code:
def ext_gcd(p, a):
  #require a, m be relative prime
  #m > a  
  if a == 0:
    return 1, 0
  else:
    x1, y1 = ext_gcd(a, p%a)
    y = x1 - y1 * int(p/a)
    x = y1
    return x, y

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

n = (-1/3)*x + (2/3)*y
m = (-1/3)*y + (2/3)*x
f = 1
if f == 0:
  ans = 0
else:
   n = int(n)
   m = int(m)
   if n < m :
      c = m
      m = n
      n = c
   # (n+m!)/(n!)(m!) mod (1e9+7)
   ans = 1
   prime = 1000000007 
   for i in range(n+1,m+n+1):
        ans = int(ans * i) 
        ans = (ans % prime)
   for i in range(1, m+1):
      ori_inv = int(ext_gcd(prime, i)[1])
      while ori_inv < 0 :
        ori_inv += prime
      ans = int(ans * ori_inv)  
      ans = (ans % prime)
print(ans)


Fixed code:
def ext_gcd(p, a):
  #require a, m be relative prime
  #m > a  
  if a == 0:
    return 1, 0
  else:
    x1, y1 = ext_gcd(a, p%a)
    y = x1 - y1 * int(p/a)
    x = y1
    return x, y

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

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

if n != int(n) or m != int(m) or n<0 or m<0:
  ans = 0
else:
   n = int(n)
   m = int(m)
   if n < m :
      c = m
      m = n
      n = c
   # (n+m!)/(n!)(m!) mod (1e9+7)
   ans = 1
   prime = 1000000007 
   for i in range(n+1,m+n+1):
        ans = int(ans * i) 
        ans = (ans % prime)
   for i in range(1, m+1):
      ori_inv = int(ext_gcd(prime, i)[1])
      while ori_inv < 0 :
        ori_inv += prime
      ans = int(ans * ori_inv)  
      ans = (ans % prime)
print(ans)
Buggy code:
x,y=map(int,input().split())
a=(2*x-y)/3
b=(-x+2*y)/3
if (2*x-y)%3!=0:
    print(0)
    exit()
a=int(a)
b=int(b)
if a<0 or b<0:
  print(0):
    exit()
mod=10**9+7
if a==0 or b==0:
  print((a+b)%mod)
  exit()
def comb(x,y):
    s=x
    t=1
    for i  in range(1,y):
        s=(s*(x-i))%mod
    for j  in range(1,y+1):
        t=(t*j)%mod
    return (s*pow(t,mod-2,mod))%mod
print(comb(a+b,min(a,b)))

Fixed code:
x,y=map(int,input().split())
if (2*x-y)%3!=0 or (x-2*y)%3!=0:
  print(0)
  exit()
a=(2*x-y)//3
b=(2*y-x)//3
if a<0 or b<0:
  print(0)
  exit()
mod=10**9+7
def comb(x,y):
    s=1
    t=1
    for i in range(1,y+1):
        s=s*(x-i+1)%mod
        t=t*(i)%mod
    return (s*pow(t,mod-2,mod))%mod
print(comb(a+b,min(a,b)))
Buggy code:
x,y=map(int,input().split())
if (x+y)%3!=0:
    print(0)
    exit()
if x<y:
    y=x
    x,y=y,x
if 2y<x:
    print(0)
    exit()
mod=10**9+7
a=(2y-x)//3
b=(2x-y)//3
mx=10**6*2
k=[1]*(mx+1)
def inv(n):
    return pow(n,mod-2,mod)
for i in range(mx):
    k[i+1]=k[i]*(i+1)%mod
ans=(k[w+h]*inv(k[w])*inv(k[h]))%mod
print(ans)

Fixed code:
x,y=map(int,input().split())
if (x+y)%3!=0:
    print(0)
    exit()
if x<y:
    x,y=y,x
if 2*y<x:
    print(0)
    exit()
mod=10**9+7
a=(2*y-x)//3
b=(2*x-y)//3
mx=10**6
k=[1]*(mx+1)
def inv(n):
    return pow(n,mod-2,mod)
for i in range(mx):
    k[i+1]=k[i]*(i+1)%mod
ans=(k[a+b]*inv(k[a])*inv(k[b]))%mod
print(ans)
Buggy code:
X, Y = map(int, input().split())
MOD = 10 ** 9 + 7


S = -X + 2 * Y
T = 2 * X - Y

if S < 0 or T < 0:
    print(0)
    exit()
if S % 3 != 0 or T % 3 != 0:
    print(0)
    exit()

S //= 3
T //= 3


def cmb(n, r, p):
    r = min(n - r, r)
    if r == 0:
        return 1
    over = 1
    for i in range(n, n - r, -1):
        over = over * i % p
    under = 1
    for i in range(1, r + 1):
        under = under * i % p
    inv = pow(under, p - 2, p)
    return over * inv % p


print(S, T)
ans = cmb(S + T, S, MOD) % MOD
print(ans % MOD)


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


S = -X + 2 * Y
T = 2 * X - Y

if S < 0 or T < 0:
    print(0)
    exit()
if S % 3 != 0 or T % 3 != 0:
    print(0)
    exit()

S //= 3
T //= 3


def cmb(n, r, p):
    r = min(n - r, r)
    if r == 0:
        return 1
    over = 1
    for i in range(n, n - r, -1):
        over = over * i % p
    under = 1
    for i in range(1, r + 1):
        under = under * i % p
    inv = pow(under, p - 2, p)
    return over * inv % p


# print(S, T)
ans = cmb(S + T, S, MOD) % MOD
print(ans % MOD)
Buggy code:
import math
import sys
sys.setrecursionlimit(10**7)
INTMAX = 9223372036854775807
INTMIN = -9223372036854775808
MOD = 1000000007
def POW(x, y): return pow(x, y, MOD)
def INV(x, m=MOD): return pow(x, m - 2, m)
def DIV(x, y, m=MOD): return (x * INV(y, m)) % m
def LI(): return [int(x) for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()
def II(): return int(input())

X,Y=LI()

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

FACT = [1]*1000001
# FCTINV = [1]*1000001
for i in range(1, 1000001):
    FACT[i] = (FACT[i-1]*i)%MOD

if a > 0 and b > 0 and (2*X - Y)%3 == 0 and (2*Y - X)%3 == 0:
    print(FACT[a+b]*INV(FACT[a])*INV(FACT[b]))
else:
    print(0)

Fixed code:
import math
import sys
sys.setrecursionlimit(10**7)
INTMAX = 9223372036854775807
INTMIN = -9223372036854775808
MOD = 1000000007
def POW(x, y): return pow(x, y, MOD)
def INV(x, m=MOD): return pow(x, m - 2, m)
def DIV(x, y, m=MOD): return (x * INV(y, m)) % m
def LI(): return [int(x) for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()
def II(): return int(input())

X,Y=LI()

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

FACT = [1]*1000001
for i in range(1, 1000001):
    FACT[i] = (FACT[i-1]*i)%MOD

if (2*X - Y)%3 == 0 and (2*Y - X)%3 == 0 and a >= 0 and b >= 0:
    print(DIV(DIV(FACT[a+b], FACT[a]), FACT[b]))
else:
    print(0)
Buggy code:
X,Y = map(int,input().split())
if(X+Y)%3:
    print(0)
    exit()
n = (X+Y)//3
if X < n:
    print(0)
    exit()

MOD = 10**9+7
r = X-n

print(n,r)

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

def ncr(n,r):
    if n < r: return 0
    if n < 0 or r < 0: return 0
    return fac[n] * (finv[r] * finv[n-r] % MOD) % MOD

print(ncr(n,r))

Fixed code:
X,Y = map(int,input().split())
if X>Y:
    X,Y = Y,X
if(X+Y)%3:
    print(0)
    exit()
n = (X+Y)//3
if X < n:
    print(0)
    exit()

MOD = 10**9+7
r = X-n

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

def ncr(n,r):
    if n < r: return 0
    if n < 0 or r < 0: return 0
    return fac[n] * (finv[r] * finv[n-r] % MOD) % MOD

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

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

if (x+y)%3!=0:
    print(0)
else:
    n=(x+y)//3
    m=(-x+2*y)/3
    if n<0 or m<0:
        print(0)
        exit()
    else:
        print(mod_combinations_cont(n,m,mod)%mod)


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

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

if (x+y)%3!=0:
    print(0)
else:
    n=(x+y)//3
    m=(-x+2*y)//3
    if n<0 or m<0 or n<m:
        print(0)
        exit()
    else:
        print(mod_combinations_count(n,m,mod)%mod)
Buggy code:


a, b = map(int, input().split())
MOD = (1e9 + 7)

def calc(x, y):
    right = above = 0
    while x>0 and y>0:
        if x>y:
            x -= 2
            y -= 1
            right += 1
        else:
            x -= 1
            y -= 2
            above += 1

    return (True, right, above) if x==0 and y==0 else (False, None, None)


def res(n, k):
    # print(n, k)
    total = 1
    if k < n-k:
        k = n-k
    for i in range(k+1, n+1):
        total = (total * i)# % MOD
    d = 1
    for i in range(1, n-k+1):
        d = (d*i) #% MOD
    return total // d

r, right, above = calc(a, b)
if not r:
    print(0)
else:
    print(int(res(above+right, right) % MOD))


Fixed code:


a, b = map(int, input().split())
MOD = int(1e9 + 7)

def calc(x, y):
    right = above = 0
    while x>0 and y>0:
        if x>y:
            x -= 2
            y -= 1
            right += 1
        else:
            x -= 1
            y -= 2
            above += 1

    return (True, right, above) if x==0 and y==0 else (False, None, None)


def res(n, k):
    # print(n, k)
    total = 1
    if k < n-k:
        k = n-k
    for i in range(k+1, n+1):
        total = (total * i)% MOD
        total *= pow(i-k, MOD-2, MOD)
    return total

r, right, above = calc(a, b)
if not r:
    print(0)
else:
    print(int(res(above+right, right) % MOD))