Problem:


Score : 400 points

Problem Statement

There is a knight - the chess piece - at the origin (0, 0) of a two-dimensional grid.

When the knight is at the square (i, j), it can be moved to either (i+1,j+2) or (i+2, j+1).

In how many ways can the knight reach the square (X, Y)?

Find the number of ways modulo 10^9 + 7.

Constraints

1 \leq X \leq 10^6

1 \leq Y \leq 10^6

All values in input are integers.

Input

Input is given from Standard Input in the following format:

X Y

Output

Print the number of ways for the knight to reach (X, Y) from (0, 0), modulo 10^9 + 7.

Sample Input 1

3 3

Sample Output 1

2

There are two ways: (0,0) \to (1,2) \to (3,3) and (0,0) \to (2,1) \to (3,3).

Sample Input 2

2 2

Sample Output 2

0

The knight cannot reach (2,2).

Sample Input 3

999999 999999

Sample Output 3

151840682

Print the number of ways modulo 10^9 + 7.



Sample input:
3 3


Sample output:
2

Submission status: Wrong Answer

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

way = y*2-x
away = x*2-y
if way >= 0 and way%3 == 0 and away >= 0:
    var_y = way//3
    var_x = (x-var_y)//2
    ans = 1
    add = var_y + var_x
    if add%2 == 0:
        var_y += 1
    for i in range(var_y):
        ans *= (i+1)
        ans %= (10**9+7)
    for i in range(var_x):
        ans *= (i+1)
        ans %= (10**9+7)
    print(ans)
else:
    print(0)

Submission status: Wrong Answer

Solution code:
from operator import mul
from functools import reduce
x,y = map(float,input().split())
m = (2*x - y)/3
n = (y - m)/2
mod = 10**9 + 7
def cmb(h, r):
    if h - r < r: r = h - r
    if r == 0: return 1
    if r == 1: return h
    r = int(r)

    humerator = [h - r + k + 1 for k in range(r)]
    dehominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = dehominator[p - 1]
        if pivot > 1:
            offset = (h - r) % p
            for k in range(p-1,r,p):
                k = int(k)
                offset = int(offset)
                humerator[k - offset] /= pivot
                dehominator[k] /= pivot

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

    return result
if (x + y) % 3 != 0:
  print(0)
else:
  print(cmb(n + m,n)%mod)

Submission status: Wrong Answer

Solution code:
X,Y = map(int,input().split())
 
c1 = (2*Y-X)
if (c1%3!=0)or(X-c1<0)or(Y-2*c1<0):
  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)

Submission status: Wrong Answer

Solution 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)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import numpy as np
from operator import mul
from functools import reduce

MOD = 10**9+7
def calc(a,b=MOD-2):
    if b==0: return 1
    elif b%2==0: return (calc(a,b/2)**2)%MOD
    else: return (a*calc(a,b-1))%MOD

X,Y = list(map(int,input().split()))
i, j = (X-2*Y), (-2*X+Y)

if i%3==0 and i<0 and j%3==0 and j<0:
    i,j = -i//3,-j//3
    i,j = min(i,j), max(i,j)
    n,m = 1,1
    for k in range(i): n = (n * (i+j-k))%MOD
    m = calc(np.math.factorial(i))%MOD
    print((n*m)%MOD)
else: print(0)

Submission status: Wrong Answer

Solution code:
X,Y = map(int,input().split())
 
c1 = (2*Y-X)
if c1%3!=0:
  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)

Submission status: Wrong Answer

Solution code:
#D
import numpy as np
import math

def cmb(n, k, mod):
    numerator = 1
    for i in range(k):
        numerator = (numerator * (n-i)) % mod
 
    denominator = 1
    for i in range(1, k+1):
        denominator = (denominator * i) % mod
 
    return (numerator * pow(denominator, mod-2, mod)) % mod
    
    return int((n_frac * n_r_ifrac * r_ifrac) % mod)

mod = 10**9+7
is_ok = True
x,y = map(int, input().split())  
a = np.array([[1,2], [2,1]])
b = np.array([x,y])
res = np.linalg.solve(a,b)

if not (res[0].is_integer() and res[1].is_integer()):
    is_ok = False
    ans = 0
x_res = int(res[0])
y_res = int(res[1])
if is_ok:
    ans = cmb(x_res+y_res, y_res, mod)
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
from operator import mul
from functools import reduce

MOD = 10**9+7
def calc(a,b=MOD-2):
    if b==0: return 1
    elif b%2==0: return (calc(a,b/2)**2)%MOD
    else: return (a*calc(a,b-1))%MOD

X,Y = list(map(int,input().split()))
print(X,Y)
i, j = (X-2*Y), (-2*X+Y)

if i%3==0 and i<0 and j%3==0 and j<0:
    i,j = -i//3,-j//3
    i,j = min(i,j), max(i,j)
    n,m = 1,1
    for k in range(i): n = (n * (i+j-k))%MOD
    m = calc(np.math.factorial(i))%MOD
    print((n*m)%MOD)
else: print(0)

Submission status: Wrong Answer

Solution code:
# D - Knight
M = 1000000007

def getComb(n, k, M):
    if n < k:
        return 0
    if n-k < k:
        k = n-k
    comb = 1
    for x in range(n-k+1, n+1):
        comb = (comb * x) % M
    d = 1
    for x in range(1, k+1):
        d = (d * x) % M
    comb *= pow(d, M-2, M)
    return comb % M

X, Y = map(int, input().split())
a = 2 * X - Y
b = -X + 2 * Y
if a > 0 and b > 0 and a % 3 == 0 and b % 3 == 0:
    a = int(a / 3)
    b = int(b / 3)
    print(getComb(a + b, a, M))
else:
    print(0)

Submission status: Wrong Answer

Solution code:
import math
MOD = 10**9+7

def comb(n, k, MOD):
    if n < k or n < 0 or k < 0:
        return 0
    if k > n - k:
        k = n - k
    ans = 1
    for i in range(1, k + 1):
        ans *= n + 1 - i
        ans %= MOD
        ans *= pow(i, MOD - 2, MOD)  # a //= i
        ans %= MOD
    return ans

x,y = list(map(int, input().split()))
if((x + y) % 3 != 0):
  print(0)
  exit()
sprint = (x + y) // 3
if(sprint <= 0):
  print(0)
  exit()
print((comb(sprint, abs(x - sprint), MOD)) % (10**9 + 7))

Submission status: Wrong Answer

Solution 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)

Submission status: Wrong Answer

Solution 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))

Submission status: Wrong Answer

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

c1 = (2*Y-X)
if c1%3!=0:
  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)

Submission status: Wrong Answer

Solution code:
import numpy as np
import math

def cmb(n, k, mod):
    numerator = 1
    for i in range(k):
        numerator = (numerator * (n-i)) % mod
 
    denominator = 1
    for i in range(1, k+1):
        denominator = (denominator * i) % mod
 
    return (numerator * pow(denominator, mod-2, mod)) % mod
    
    return int((n_frac * n_r_ifrac * r_ifrac) % mod)

mod = 10**9+7
is_ok = True
x,y = map(int, input().split())
#if x > y:
if (x + y) % 3 != 0:
    is_ok = False
    ans = 0
    
a = np.array([[1,2], [2,1]])
b = np.array([x,y])
res = np.linalg.solve(a,b)

#if not (res[0].is_integer() and res[1].is_integer()):
#    is_ok = False
#    ans = 0
x_res = int(res[0])
y_res = int(res[1])
if is_ok:
    ans = cmb(x_res+y_res, y_res, mod)
print(ans)

Submission status: Wrong Answer

Solution code:
mod = 10**9+7

def fact(n):
    ans = 1
    for i in range(2,n+1):
        ans *= i
        ans %= mod
    return ans
    
X,Y = list(map(int,input().split()))

# a+2b = X
# 2a+b = Y を解く
# -> a = (2Y-X)/3, b = (2X-Y)/3
# (i+1,j+2) の移動が a 回
# (i+2,j+1) の移動が b 回

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

if not a.is_integer() or not b.is_integer():
    print(0)
    exit(0)

# a回とb回の移動の組み合わせは (a+b)!/a!b!
print(fact(int(a+b)) * pow(fact(int(a)),mod-2,mod) * pow(fact(int(b)),mod-2,mod) % mod)

Submission status: Wrong Answer

Solution code:
import math
MOD = 10**9+7

def comb(n, k, MOD):
    if n < k or n < 0 or k < 0:
        return 0
    if k > n - k:
        k = n - k
    ans = 1
    for i in range(1, k + 1):
        ans *= n + 1 - i
        ans %= MOD
        ans *= pow(i, MOD - 2, MOD)  # a //= i
        ans %= MOD
    return ans

x,y = list(map(int, input().split()))
if((x + y) % 3 != 0):
  print(0)
  exit()
sprint = (x + y) // 3
print((comb(sprint, abs(x - sprint), MOD)))

Submission status: Wrong Answer

Solution code:
def c_mod(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())
l=int(2*x-y)
k=int(2*y-x)
if l%3==0 and k%3==0 and k>0 and l>0:
  ans=c_mod((l+k)//3,k//3)

else:
  ans=0
print(ans)

Submission status: Wrong Answer

Solution code:
def nCk(n, k, mod=10 ** 9 + 7):
    def xgcd(a, b):
        if b == 0:
            return (a, 1, 0)
        g, x, y = xgcd(b, a % b)
        return (g, y, x - (a // b) * y)
    p, q = 1, 1
    for i in range(n - k + 1, n + 1):
        p = (p * i) % mod
    for i in range(2, k + 1):
        q = (q * i) % mod
    return p * (xgcd(q, mod)[1] % mod) % mod


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

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

if X % 3 != 0 or Y % 3 != 0 or a < 0 or b < 0:
    print(0)
else:
    print(nCk(a + b, a))

Submission status: Wrong Answer

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

if (X+Y) % 3:
    print(0)
else:
    n = (2*X - Y) // 3
    m = (2*Y - X) // 3
    if n<0 or m<0:
        print(0)
    else:
        from math import factorial
        ret = factorial(n + m) // factorial(n)
        print(ret % (10**9+7))

Submission status: Wrong Answer

Solution code:
def c_mod(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 (2*x-y)%3==0 and (2*y-x)%3==0:
  l=int((2*x-y)/3)
  k=int((2*y-x)/3)
  ans=c_mod(l+k,k)

else:
  ans=0
print(ans)

Submission status: Wrong Answer

Solution code:
import math

def cmb(n, r):
    mod = 10**9 + 7

    if n - r < r:
        r = n - r
    if r == 0:
        return 1
    if r == 1:
        return n
    
    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

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

"""
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 = 10**6
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 )
"""
X, Y = [int(i) for i in input().split()]

if (2*Y - X) % 3 != 0:
    print(0)
elif (2*X - Y) % 3 != 0:
    print(0)
else:
    x = (2*X - Y) // 3
    y = (2*Y - X) // 3
    print(cmb(x+y, x))

Submission status: Wrong Answer

Solution code:
MOD = 1000000007

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

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

x,y=min(x,y),max(x,y)
if (x+y)%3:
	print(0)
else:
	level = (x+y)//3
	r=x-level
	print(NCR(level,r))

Submission status: Wrong Answer

Solution code:
import math

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

if (x+y)%3 != 0:
    ans = 0
else:
    m = (2*x - y) //3
    n = x - 2*m
    print(m,n)
    if m <0 or n < 0 :
        ans = 0
    else:
        ans = math.factorial(n+m) // (math.factorial(n+m - m) * math.factorial(m))

print(ans%(10**9+7))

Submission status: Wrong Answer

Solution code:
import numpy as np
import math

def cmb(n, k, mod):
    numerator = 1
    for i in range(k):
        numerator = (numerator * (n-i)) % mod
 
    denominator = 1
    for i in range(1, k+1):
        denominator = (denominator * i) % mod
 
    return (numerator * pow(denominator, mod-2, mod)) % mod
    
    return int((n_frac * n_r_ifrac * r_ifrac) % mod)

mod = 10**9+7
is_ok = True
x,y = map(int, input().split())
if (x + y) % 3 != 0:
    is_ok = False
    ans = 0
    
a = np.array([[1,2], [2,1]])
b = np.array([x,y])
res = np.linalg.solve(a,b)

#if not (res[0].is_integer() and res[1].is_integer()):
#    is_ok = False
#    ans = 0
x_res = int(res[0])
y_res = int(res[1])
if is_ok:
    ans = cmb(x_res+y_res, x_res, mod)
print(ans)

Submission status: Wrong Answer

Solution code:
import math
X,Y = map(int,input().split())
N = min(X,Y)
i = 0
ans = 0
while((N-2*i)>=0):
    x = 1*(N-2*i)+2*i
    y = 2*(N-2*i)+1*i
    if x==X and y==Y:
        ans = math.factorial(N-i)//(math.factorial(N-2*i)*math.factorial(i))
    i += 1
print(ans%(1000000000+7))

Submission status: Wrong Answer

Solution code:
X, Y = map(int, input().split())
factorial = [1, 1]

for i in range(2, (X+Y)+1):
    factorial.append(factorial[-1] * i % 1000000007)

if (X+Y) % 3 != 0:
    print(0)
else:
    m = (2*X-Y)//3
    n = X - 2*m
    if n < 0 or m < 0:
        print(0)
        exit()
    print(factorial[n+m] // (factorial[m]*factorial[n]))

Submission status: Wrong Answer

Solution code:
import math
x, y = map(int, input().split())
if x * 2 < y or y * 2 < x:
    print("0")
elif (x + y) % 3 != 0:
    print("0")
else:
    x1 = x - (x + y)/3
    y1 = y - (x + y)/3
    root = math.factorial(x1 + y1)/(math.factorial(x1)*math.factorial(y1))
    answer = root % (10**9 + 7)
    print(answer)

Submission status: Wrong Answer

Solution code:
X, Y = map(int, input().split())
factorial = [1, 1]

for i in range(2, (X+Y)+1):
    factorial.append(factorial[-1] * i % 1000000007)

if (X+Y) % 3 != 0:
    print(0)
else:
    m = (2*X-Y)//3
    n = X - 2*m
    print(factorial[n+m] // (factorial[m]*factorial[n]))

Submission status: Wrong Answer

Solution code:
X, Y = map(int, input().split())
comb = [1, 1]

for i in range(2, (X+Y)+1):
    comb.append(comb[-1]*i%1000000007)

if (X+Y) % 3 != 0:
    print(0)
else:
    m = (2*X-Y)//3
    n = X - 2*m
    print(int(comb[n+m] / (comb[m]*comb[n])))

Submission status: Wrong Answer

Solution code:
#互いに素なa,bについて、a*x+b*y=1の一つの解
def extgcd(a,b):
    r = [1,0,a]
    w = [0,1,b]
    while w[2]!=1:
        q = r[2]//w[2]
        r2 = w
        w2 = [r[0]-q*w[0],r[1]-q*w[1],r[2]-q*w[2]]
        r = r2
        w = w2
    #[x,y]
    return [w[0],w[1]]

# aの逆元(mod m)を求める。(aとmは互いに素であることが前提)
def mod_inv(a,m):
    if a%m!=0:
      x = extgcd(a,m)[0]
      return (m+x%m)%m
      

#nCk mod m を計算する(デフォルトの引数は10**9+7)
def c_mod(n,k,m=10**9+7):
  res = 1
  for i in range(1,n+1):
      if (i%m)!=0:
        res = res*i%m
      else:
        res=res/i%m
  for i in range(1,k+1):
      if (i%m)!=0:
        res = res*mod_inv(i,m)%m
      else:
        res=res/i%m
  for i in range(1,n-k+1):
      if (i%m)!=0:
        res = res*mod_inv(i,m)%m
      else:
        res=res/i%m
  return res


x,y=map(int,input().split())
if (2*x-y)%3==0 and (2*y-x)%3==0:
  l=int((2*x-y)/3)
  k=int((2*y-x)/3)
  ans=c_mod(l+k,k)

else:
  ans=0
print(ans)

Submission status: Wrong Answer

Solution code:
def combinations_count(n, k, M):
    if k == 0:
        return 1
    fn = 0
    fk = 0
    fnk = 0
    cur = 1
    M = int(1e9+7)
    for i in range(1, n+1):
        cur = (cur * i) % M
        if i == n:
            fn = cur
        if i == n-k:
            fnk = cur
        if i == k:
            fk = cur
 
    return (fn * (modpow(fk , (M-2), M)) * modpow(fnk , (M-2), M))%M

def modpow(a,b,M):
    if b == 1:
        return a % M
    if b % 2 == 1:
        return (modpow(a,(b-1)//2,M)**2 * a)%M
    return (modpow(a,b//2,M) ** 2) % M 

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

max_value=max(x,y)
min_value=min(x,y)

base_max=max_value//2
base_min=max_value%2

diff_value=min_value-base_min*2-base_max

base_max-=diff_value//3
base_min+=diff_value//3*2

print(combinations_count(base_max+base_min,min(base_max,base_min),10**9+7))

Submission status: Wrong Answer

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

i = int((2*y-x)/3) if (2*y-x)%3==0 else 0
j = int((2*x-y)/3) if (2*x-y)%3==0 else 0
if i == 0 and j == 0:
    print(0)
else:
    times = i if i > j else j
    ans = 1
    for n in range(times+1,i+j+1):
        ans = (ans * n) % (10**9+1)
    print(ans)

Submission status: Wrong Answer

Solution code:
from numpy.linalg import solve
def cmb(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:
  print(0)
else:
  left = [[1, 2],
          [2, 1]]
  right = [x, y]
  n, m = map(int, solve(left, right))
  c = cmb(n+m, n)
  print(c)

Submission status: Wrong Answer

Solution code:
#D
import numpy as np
import math

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

def ifrac_mod(n, mod, f_inv=1):
    for i in range(n, 1, -1):
        f_inv = (f_inv * pow(i, mod-2, mod)) % mod
    return f_inv

def cmb_mod(n, r, mod):
    n_frac = frac_mod(n, mod)
    n_r_ifrac = ifrac_mod(n-r, mod)
    r_ifrac = ifrac_mod(r, mod)
    
def cmb(n, k, mod):
    numerator = 1
    for i in range(k):
        numerator = (numerator * (n-i)) % mod
 
    denominator = 1
    for i in range(1, k+1):
        denominator = (denominator * i) % mod
 
    return (numerator * pow(denominator, mod-2, mod)) % mod
    
    return int((n_frac * n_r_ifrac * r_ifrac) % mod)
mod = 10**9+7
x,y = map(int, input().split())
a = np.array([[1,2], [2,1]])
b = np.array([x,y])
res = np.linalg.solve(a,b)
is_ok = True
if not (res[0].is_integer() and res[1].is_integer()):
    is_ok = False
    ans = 0
x_res = int(res[0])
y_res = int(res[1])
if is_ok:
    ans = cmb(x_res+y_res, x_res, mod)
print(ans)

Submission status: Wrong Answer

Solution code:
x,y = [int(x) for x in input().split()]

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

if (a==int(abs(a)) and b==int(abs(b))):
    n=1
    for i in range(1,int(a+b+1)):
        n=(n*i)%(10**9+7)
    print(n)
else:
    print(0)

Submission status: Wrong Answer

Solution 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
        if X > Y*2:
            flag = True
    elif Y > X:
        diff = Y - X
        all_num = (X+Y)//3
        count_2 = (X+Y)//2 - diff//2
        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)

Submission status: Wrong Answer

Solution code:
X, Y = map(int, input().split())
kaizyo = [1, 1]

for i in range(2, (X+Y)+1):
    kaizyo.append(kaizyo[-1]*i%1000000007)

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

    print(int( kaizyo[n+m] / (kaizyo[m]*kaizyo[n])%1000000007 ) )

Submission status: Wrong Answer

Solution code:
import sys
import math
from statistics import mean
from functools import reduce, lru_cache
from itertools import permutations


def main(x, y):
    if (x+y) % 3 != 0:
        return 0

    # ret = reachable((0, 0), (x, y))
    n, m = solve(x, y)
    # print(n, m)

    if n != int(n) or m != int(m):
        return 0

    if n < 0 or m < 0:
        return 0

    # p = n! / (n - r)!
    ret = math.factorial(n+m) // math.factorial(n)

    return ret % (10**9 + 7)


def solve(x, y):
    return (
        (2*y - x) / 3,
        (2*x - y) / 3
    )


def reachable(current, target):
    if current == target:
        return 1
    elif (current[0]>target[0]) or (current[1]>target[1]):
        return 0
    else:
        return reachable((current[0]+1, current[1]+2), target) + reachable((current[0]+2, current[1]+1), target)


if __name__ == '__main__':
    p = input().split(' ')
    print(main(int(p[0]), int(p[1])))

Submission status: Wrong Answer

Solution code:
import numpy as np
import math

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

def ifrac_mod(n, mod, f_inv=1):
    for i in range(n, 1, -1):
        f_inv = (f_inv * pow(i, mod-2, mod)) % mod
    return f_inv

def cmb_mod(n, r, mod):
    n_frac = frac_mod(n, mod)
    n_r_ifrac = ifrac_mod(n-r, mod)
    r_ifrac = ifrac_mod(r, mod)
    
    return int((n_frac * n_r_ifrac * r_ifrac) % mod)
mod = 10**9+7
x,y = map(int, input().split())
a = np.array([[1,2], [2,1]])
b = np.array([x,y])
res = np.linalg.solve(a,b)
is_ok = True
if not (res[0].is_integer() and res[1].is_integer()):
    is_ok = False
    ans = 0
x_res = int(res[0])
y_res = int(res[1])
if is_ok:
    ans = cmb_mod(x_res+y_res, x_res, mod)
print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3

import sys
sys.setrecursionlimit(300000)

MOD = 1000000007  # type: int

def get_z(y, x): # y/x (mod 1000000007)
    inv_x = pow(x, MOD - 2, MOD)
    return y * inv_x % MOD

def comb_mod(n, k):
    if n == 0:
        return 0
    k = min(k, n - k)
    a = 1
    b = 1
    for i in range(k):
        a = a * (n - i) % MOD
        b = b * (i + 1) % MOD
    ret = get_z(a, b)
    return ret


def solve(X: int, Y: int):
    d = X - Y
    s = (X + Y) // 3
    x = (s + d) // 2
    y = (s - d) // 2
    if (X + Y) % 3 or (s + d) % 2 or x * 2 + y != X or x + y * 2 != Y:
        print(0)
        return
    ret = comb_mod(x + y, min(x, y))
    print(ret)
    return

def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    X = int(next(tokens))  # type: int
    Y = int(next(tokens))  # type: int
    solve(X, Y)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
X, Y = map(int, input().split())
kaizyo = [1, 1]

for i in range(2, (X+Y)+1):
    kaizyo.append(kaizyo[-1]*i%1000000007)

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

    print(int( kaizyo[n+m] / (kaizyo[m]*kaizyo[n]) ) )

Submission status: Wrong Answer

Solution 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())
t = x-y
a = 0
if t > 0:
  a = t
  x -= a*2
  y -= a
elif t < 0:
  a = t
  x -= a
  y -= a*2
if x<0 or x%3 != 0:
  ans = 0
else:
  b = x//3
  a += b
  ans = cmb(a+b,b)
print(ans%1000000007)

Submission status: Wrong Answer

Solution code:
#%%
import sys
def input():
    return sys.stdin.readline().rstrip()

def xgcd(a, b):
    x0, y0, x1, y1 = 1, 0, 0, 1
    while b != 0:
        q, a, b = a//b, b, a%b
        x0, x1 = x1, x0 -q*x1
        y0, y1 = y1, y0 -q*y1
    return a, x0, y0

def modinv(a, m):
    g, x, y = xgcd(a, m)
    if g != 1:
        raise Exception('modular inverse does not exist')
    else:
        return x %m

def main():
    X, Y = map(int, input().split())

    divider = 10**9 + 7

    m = 2 * X - Y
    n = 2 * Y - X

    if m%3 != 0 and n%3 != 0:
        print(0)
        return
    m //= 3
    n //= 3

    if m < n:
        m, n = n, m

    ans = 1
    for i in range(m+n, m, -1):
        ans *= i
        ans %= divider

    for i in range(n, 0, -1):
        ans *= modinv(i, divider)
        ans %= divider

    print(ans)

# %%
if __name__ == '__main__':
    main()

# %%
# from atcoder_test import doTest
# doTest("abc145","d",main)

Submission status: Wrong Answer

Solution 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


X, Y = (int(i) for i in input().split())

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

if(  i < 0 or j < 0  ):
    print(0)
else:
    print(cmb(i+j, i) % 1000000007)

Submission status: Wrong Answer

Solution code:
#互いに素なa,bについて、a*x+b*y=1の一つの解
def extgcd(a,b):
    r = [1,0,a]
    w = [0,1,b]
    while w[2]!=1:
        q = r[2]//w[2]
        r2 = w
        w2 = [r[0]-q*w[0],r[1]-q*w[1],r[2]-q*w[2]]
        r = r2
        w = w2
    #[x,y]
    return [w[0],w[1]]

# aの逆元(mod m)を求める。(aとmは互いに素であることが前提)
def mod_inv(a,m):
    x = extgcd(a,m)[0]
    return (m+x%m)%m

#nCk mod m を計算する(デフォルトの引数は10**9+7)
def c_mod(n,k,m=10**9+7):
  res = 1
  for i in range(1,n+1):
      res = res*i%m
  for i in range(1,k+1):
      res = res*mod_inv(i,m)%m
  for i in range(1,n-k+1):
      res = res*mod_inv(i,m)%m
  return res


x,y=map(int,input().split())
if (2*x-y)%3==0 and (2*y-x)%3==0:
  l=int((2*x-y)/3)
  k=int((2*y-x)/3)
  ans=c_mod(l+k,k)

else:
  ans=0
print(ans)

Submission status: Wrong Answer

Solution 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


X, Y = (int(i) for i in input().split())

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

if(  ((2*X-Y)%3)!=0 or (2*Y-X)%3!=0  ):
    print(0)
else:
    print(cmb(i+j, i) % 1000000007)

Submission status: Wrong Answer

Solution code:
import sys
G = list(map(int, input().split()))
total = G[0] + G[1]
if total % 3 != 0:
  print(0)
  sys.exit(0)

total //= 3
dis = G[0] - total

mod = 10 ** 9 + 7
fact = [1]
fact_inv = [1]
for i in range(10**6+4):
    new_fact = fact[-1]*(i+1)%mod
    fact.append(new_fact)
    fact_inv.append(pow(new_fact,mod-2,mod))

def mod_comb_k(n,k,mod):
    return fact[n] * fact_inv[k] % mod * fact_inv[n-k] %mod

print(mod_comb_k(total, total-min(G), mod))

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3

import sys
sys.setrecursionlimit(300000)

MOD = 1000000007  # type: int

def get_z(y, x): # y/x (mod 1000000007)
    inv_x = pow(x, MOD - 2, MOD)
    return y * inv_x % MOD

def comb_mod(n, k):
    if n == 0:
        return 0
    k = min(k, n - k)
    a = 1
    b = 1
    for i in range(k):
        a = a * (n - i) % MOD
        b = b * (i + 1) % MOD
    ret = get_z(a, b)
    return ret


def solve(X: int, Y: int):
    def comb(n, k):
        ret = 1
        for i in range(k):
            ret *= n - i
            ret //= i + 1
        return ret
    d = X - Y
    s = (X + Y) // 3
    x = (s + d) // 2
    y = (s - d) // 2
    if (X + Y) % 3 != 0 or x * 2 + y != X or x + y * 2 != Y:
        print(0)
        return
    ret = comb_mod(x + y, min(x, y))
    print(ret)
    return

def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    X = int(next(tokens))  # type: int
    Y = int(next(tokens))  # type: int
    solve(X, Y)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
import math
from statistics import mean
from functools import reduce, lru_cache
from itertools import permutations


def main(x, y):
    if (x+y) % 3 != 0:
        return 0

    # ret = reachable((0, 0), (x, y))
    n, m = solve(x, y)

    if n % 1 != 0 or m % 1 != 0:
        return 0

    if n < 0 or m < 0:
        return 0

    # p = n! / (n - r)!
    ret = math.factorial(n+m) // math.factorial(n)

    return ret % (10**9 + 7)


def solve(x, y):
    return (
        (x - 2*y) / 3,
        (y - 2*x) / 3
    )


def reachable(current, target):
    if current == target:
        return 1
    elif (current[0]>target[0]) or (current[1]>target[1]):
        return 0
    else:
        return reachable((current[0]+1, current[1]+2), target) + reachable((current[0]+2, current[1]+1), target)


if __name__ == '__main__':
    p = input().split(' ')
    print(main(int(p[0]), int(p[1])))

Submission status: Wrong Answer

Solution code:
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 = 10**6+1
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 )

x,y=map(int,input().split())
if (x+y)%3==0:
    a=abs(2*y-x)//3
    b=abs(y-2*x)//3
    ans=1
    a=int(a)
    b=int(b)
    print(cmb(a+b,min(a,b),mod))
else:print(0)