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

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

def cmb(n,r, mod):
  r = min(r, n - r)
  numerator = 1
  dinominator = 1
  for i in range(r):
    numerator = numerator * (n - i) % mod
  for j in range(1, r + 1):
    dinominator = dinominator * j % mod
  return numerator * pow(dinominator, mod - 2, mod) % mod

if a % 1 == 0 and a >= 0 and b % 1 == 0 and b >= 0:
  print(cmb(int(a + b), int(a), 1000000007))
else:print(0)

Submission status: Wrong Answer

Solution code:
#lにa回、rにb回進む
x,y = map(int,input().split())
#x = a +2b
#y = 2a+b
#x+y = 3a+3b
#a+b = (x+y)/3
#b=x-a+b
b = x-(x+y)/3
a = (x-2*b)
ans = 0
#print("a:{} b:{}".format(a,b))
if a<0 or b<0 or b-int(b)>0.00001 or a-int(a)>0.00001:
  print(ans)
  exit()

MAX = 1000000;
MOD = 1000000007;

fac = [0 for i in range(MAX)]
finv = [0 for i in range(MAX)]
inv = [0 for i in range(MAX)]

#テーブルを作る前処理
def COMinit():
    fac[0],fac[1] = 1,1
    finv[0],finv[1] = 1,1
    inv[1] = 1
    for i in range(2,MAX):
      fac[i] = fac[i - 1] * i % MOD
      inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD
      finv[i] = finv[i - 1] * inv[i] % MOD

#二項係数計算
def COM(n,k):
  if n < k:
    return 0
  if n < 0 or k < 0:
    return 0
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD

COMinit()
print(COM(int(a+b),int(a)))

Submission status: Wrong Answer

Solution code:
def sq(a, b, mod):  # aのb乗を剰余,kは初期値#20191116-D-Knight
    if b == 0:
        return 1
    elif b % 2 == 0:
        return sq(a, b // 2, mod)**2 % mod
    else:
        return sq(a, b - 1, mod) * a % mod


def nCk(n, k, mod=10**9 + 7):
    x = max(k, n - k)
    y = min(k, n - k)
    kkai = 1
    for i in range(2, y + 1):
        kkai = (kkai * i) % mod
    nkkai = 1
    for i in range(x + 1, n + 1):
        nkkai = (nkkai * i) % mod
    answer = sq(kkai, mod - 2, mod) * nkkai % mod
    return answer


from sys import exit
X, Y = map(int, input().split())
if (X + Y) % 3 != 0:
    print(0)
    exit()

if X % 2 == 0:
    syurui = X - (X // 2) + 1
else:
    syurui = X - (X // 2)
for i in range(syurui):
    two = i
    one = X - two * 2
    if (two + one * 2) == Y:
        print(nCk(two + one, two))

Submission status: Wrong Answer

Solution code:
def comb(n, k, mod):
    if k > (n // 2):
        k = n - k
    a = 1
    for i in range(k):
        a = a * (n - i) % mod
    b = 1
    for i in range(k - 1):
        b = b *(k - i) % mod
    a * pow(b, mod - 2, mod) % mod

    return a

X, Y = map(int, input().split())
ans = 0
mod = 10 ** 9 + 7
if X > Y:
    X, Y = Y, X
##Yのほうが大きいとして考える
if not (X + Y) % 3 == 0 or Y > 2 * X:
    ans = 0
else:
    n = (X + Y) // 3
    d = Y - X
    a = 2*n - X
    ans = comb(n, a, mod)
print(ans)

Submission status: Wrong Answer

Solution code:
def comb(n, k, mod):
    if k > (n // 2):
        k = n - k
    a = 1
    for i in range(k):
        a = a * (n - i) % mod
    b = 1
    for i in range(k - 1):
        b = b *(b - i) % mod
    a * pow(b, mod - 2, mod) % mod

    return a

X, Y = map(int, input().split())
ans = 0
mod = 10 ** 9 + 7
if X > Y:
    X, Y = Y, X
##Yのほうが大きいとして考える
if not (X + Y) % 3 == 0 or Y > 2 * X:
    ans = 0
else:
    n = (X + Y) // 3
    d = Y - X
    a = 2*n - X
    ans = comb(n, a, mod)
print(ans)

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


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



if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
def sq(a, b, mod):#aのb乗を剰余,kは初期値#20191116-D-Knight
    if b==0:
        return 1
    elif b%2==0:
        return sq(a, b//2, mod)**2%mod
    else:
        return sq(a, b-1, mod)*a%mod

def nCk(n, k, mod=10 ** 9 + 7):
    x=max(k, n-k)
    y=min(k, n-k)
    kkai=1
    for i in range(2, y+1):
        kkai=(kkai*i)%mod
    nkkai=1
    for i in range(x+1, n+1):
        nkkai=(nkkai*i)%mod
    answer=sq(kkai, mod-2, mod)*nkkai%mod
    return answer
    
import math
c    = [list(map(int, input().split())) for _ in range(1)]
aa=(2*c[0][1]-c[0][0])
bb=(2*c[0][0]-c[0][1])
k=10**9+7

if aa%3!=0 or bb%3!=0:
    print(0)
elif aa<=0 or bb<=0:
    print(0)
else:
    a=aa//3
    b=bb//3
    answer=nCk(a+b,a)%k
    print(answer)

Submission status: Wrong Answer

Solution code:
x,y = map(int,input().split())
a = 1
b = 1
n = (2*y-x)//3
m = (2*x-y)//3

if (x+y)%3 == 0:
  for i in range(n+1,n+m+1):
    a *= i
  for j in range(1,m+1):
    b *= j
  print(a//b)
else:
  print(0)

Submission status: Wrong Answer

Solution code:
def sq(a, b, mod):#aのb乗を剰余,kは初期値#20191116-D-Knight
    if b==0:
        return 1
    elif b%2==0:
        return sq(a, b//2, mod)**2%mod
    else:
        return sq(a, b-1, mod)*a%mod

def nCk(n, k, mod=10 ** 9 + 7):
    x=max(k, n-k)
    y=min(k, n-k)
    kkai=1
    for i in range(2, y+1):
        kkai=(kkai*i)%mod
    nkkai=1
    for i in range(x+1, n+1):
        nkkai=(nkkai*i)%mod
    answer=sq(kkai, mod-2, mod)*nkkai%mod
    return answer
    
import math
c    = [list(map(int, input().split())) for _ in range(1)]
aa=(2*c[0][1]-c[0][0])
bb=(2*c[0][0]-c[0][1])
k=10**9+7

if aa%3!=0 or bb%3!=0:
    print(0)
else:
    a=aa//3
    b=bb//3
    
    answer=nCk(a+b,a)%k
    print(answer)

Submission status: Wrong Answer

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

#print(X,Y)

if (X+Y)%3==0 and (2*Y-X)%3==0:
  N=(X+Y)//3
  m=(2*Y-X)//3
  m=min(m,N-m)
 # print(N,m)
  T=1
  B=1
  mod=10**9+7
  for j in range(m):
    T=(T*(N-j))%mod
    B=(B*(j+1))%mod
  print((T*pow(B,mod-2,mod))%mod)
else:
  print(0)

Submission status: Wrong Answer

Solution code:
import sys

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

inf = 10**9+7

if (x+y)%3 != 0:
    print(0)
    sys.exit()
    
a = (2*x-y)//3
b = (2*y-x)//3

def nCr(n, r):
    r = min(r, n - r)
    if r == 0: return 1;
    if r == 1: return n;
    numerator = [n - r + i + 1 for i in range(r)]
    denominator  = [i + 1 for i 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*numerator[k])%inf
    return int(result)

print(nCr(a+b, a))

Submission status: Wrong Answer

Solution 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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
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 and b>=0:
    print(2**int(min(a,b))%(10**9+7))
  else:
    print(0)

Submission status: Wrong Answer

Solution code:
import math

M = 10 ** 9 + 7

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

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

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

if a > 0 and b > 0 and a % 3 ==  0 and b % 3 == 0:
	a /= 3
	b /= 3
	counter = comb(a+b,a)

result = counter % M
print(counter)
print(result)

Submission status: Wrong Answer

Solution code:
import math

M = 10 ** 9 + 7

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

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

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

if a > 0 and b > 0 and a % 3 ==  0 and b % 3 == 0:
	a /= 3
	b /= 3
	counter = comb(a+b,a)

result = counter % M
print(result)

Submission status: Wrong Answer

Solution code:
import math
# (10**9+7)
def main():
    x,y = map(int, input().split())
    if (x+y)%3 != 0:
        print(0)
    else:
        if 0 <= x/y <= 2 and 0 <= y/x <= 2:
            n = (x+y)//3
            r = min(x,y)%n
            print(n,r)
            print(comb(n,r))
        else:
            print(0)

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


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import math
import numpy as np 

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 =map(int,input().split())
x,y = np.sum(1/3.0*(np.array([[ 2., -1.],[-1.,  2.]])*np.array([X,Y])),axis=1).astype(np.int32)
#print(x)
##x = int(X-(X+Y)//3)
#y = int(Y-(X+Y)//3)
if (X+Y)%3==0 and x>=0 and y>=0:
    print(cmb(x+y,x,mod))
else:
    print(0)

Submission status: Wrong Answer

Solution code:
import math
import numpy as np 

#参照
#https://qiita.com/derodero24/items/91b6468e66923a87f39f#%E7%95%AA%E5%A4%96%E7%B7%A8
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 =map(int,input().split())
x = np.sum(1/3*(np.array([[ 2, -1],[-1,  2]])*np.array([X,Y])),axis=1)
#print(x)
if (X+Y)%3==0 and x[0]>=0 and x[1]>=0:
    print(cmb(int(sum(x)),int(x[0]),mod)%mod)
else:
    print(0)

Submission status: Wrong Answer

Solution code:
import math
import numpy as np 

#参照
#https://qiita.com/derodero24/items/91b6468e66923a87f39f#%E7%95%AA%E5%A4%96%E7%B7%A8
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 =map(int,input().split())
x = np.sum(1/3*(np.array([[ 2., -1.],[-1.,  2.]])*np.array([X,Y])),axis=1).astype(np.int32)
#print(x)
if (X+Y)%3==0:
    print(cmb(sum(x),x[0],mod))
else:
    print(0)

Submission status: Wrong Answer

Solution code:
X,Y=map(int,input().split())
if (X+Y)%3!=0:
    print(0)
    exit()
mod=10**9+7
N=(X+Y)//3
'''
k*(1,2)+(n-k)*(2,1)=(x,y)
(k+2n-2k,2k+n-k)=(x,y)
(2n-k,n+k)=(x,y)
2y=2n+2k
x=2n-k
2y-x=3k
'''
K=(2*Y-X)//3
ans=1
for i in range(1,K+1):
    ans*=(N+1-i)*pow(i,mod-2,mod)
    ans%=mod
print(ans)

Submission status: Wrong Answer

Solution code:
[x,y]=list(map(int,input().split()))
if ((x%3)+(y%3))%3!=0:
	print(0)
else:
	dansu=int((x+y)/3)
	r=y-dansu
	if r>dansu-r:
		r=dansu-r
	mod=1000000007
	d=1
	rr=1
	nr=1
	for i in range(1,dansu+1):
		d=d*(i%mod)
	for i in range(1,r+1):
		rr=rr*(i%mod)
	for i in range(1,dansu-r+1):
		nr=nr*(i%mod)
	rrinv=rr
	nrinv=nr
	for i in range(29):
		rrinv=(rrinv%mod)**2
		nrinv=(nrinv%mod)**2
		if i==26:
			a=rrinv
			b=nrinv
		if i==27:
			c=rrinv
			d=nrinv
	rrinv=rrinv*a*c*rr**60475911
	nrinv=nrinv*a*d*nr**60475911
	kotae=int((d%mod)*(rrinv%mod)*(nrinv%mod))
	kotae=int(kotae%(10**9+7))
	
	print(kotae)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
# https://www.geeksforgeeks.org/compute-ncr-p-set-3-using-fermat-little-theorem/
def comb(n, r, p): 
    num = den = 1 
    for i in range(r): 
        num = (num * (n - i)) % p 
        den = (den * (i + 1)) % p 
    return (num * pow(den,  p - 2, p)) % p 
  
m = 10**9 + 7
x, y = (int(x) for x in input().split())
ans = 0
if (x - 2*y) % 3 == 0:
    beta = (x - 2*y) // -3
    alpha = y - 2*beta
    ans = comb(alpha+beta, min(alpha, beta), m)
print(ans)

Submission status: Wrong Answer

Solution code:
# https://www.geeksforgeeks.org/compute-ncr-p-set-3-using-fermat-little-theorem/
def comb(n, r, p): 
    num = den = 1 
    for i in range(r): 
        num = (num * (n - i)) % p 
        den = (den * (i + 1)) % p 
    return (num * pow(den,  p - 2, p)) % p 
  
m = 10**9 + 7
x, y = (int(x) for x in input().split())
ans = 0
if (x - 2*y) % 3 == 0:
    beta = (x - 2*y) // -3
    alpha = y - 2*beta
    ans = comb(alpha+beta, beta, m)
print(ans)

Submission status: Wrong Answer

Solution 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

if (2*a-b)%3 == 0 and (2*b-a)%3 == 0:
    m = int((2*a - b)/3)
    n = int((2*b - a)/3)

    r += mod_comb(n+m,m)

print(r)

Submission status: Wrong Answer

Solution code:
import numpy as np
#import math

def combination(N,r,mod=10**9+7):
    nn = 1
    for i in range(N-r):
        nn = nn * (N-i)
        nn = nn % mod
    
    return nn

xyi = map(int,input().split())
xy = np.array(list(xyi))

x = xy[0]
y = xy[1]
n = 2 * x - y
m = -x + 2 *y

if not n%3 == 0:
    print(0)
else:
    n = int(n/3)
    m = int(m/3)
    ans = combination(n+m,n)
    #cmb = math.factorial(n+m)//math.factorial(n)
    #ans = cmb % (10**9 +7)
    print(ans)

Submission status: Wrong Answer

Solution code:
from math import factorial

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

for i in range(0,x//2+1):
    if (x-2*i)*2+i == y:
        cnt += factorial(x-i)/(factorial(x-2*i)*factorial(i))

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

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**7)
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

z = 10**9+7

X, Y = map(int, input().split())
x = (-X+2*Y)/3
y = (2*X-Y)/3
if x.is_integer() and y.is_integer() and x>0 and y>0:
    x = int(x)
    y = int(y)
    maximam = max(x,y)
    minimam = min(x,y)
    print(cmb(x+y,minimam)%z)
else:
    print(0)

Submission status: Wrong Answer

Solution code:
x, y = map(int, input().split())
z = x + y
mod = 10 ** 9 + 7
if z % 3 == 0:
  w = z // 3
  a, b = sorted([x - w, y - w])
  inv_mod = [1] * (a + 1)
  num = b + 1
  den = 1
  for i in range(2, a + 1):
    num = num * (b + i) % mod
    inv_mod[i] = -inv_mod[mod % i] * (mod // i) % mod
    den = den * inv_mod[i] % mod
  print(num * den % mod)
else:
  print(0)

Submission status: Wrong Answer

Solution code:
import math

x,y=input().split()

x=abs(int(x))

y=abs(int(y))

d1=(2*x-y)

d2=(2*y-x)

if ((d1%3==0) and (d2%3==0)and(d1!=0)and(d2!=0)):
    f1=d1/3

    f2=d2/3

    num=f1+f2
    
    print(math.factorial(num))
else:
    print("0")

Submission status: Wrong Answer

Solution code:
import math

x,y=input().split()

x=abs(int(x))

y=abs(int(y))

d1=(2*x-y)

d2=(2*y-x)

if ((d1%3==0) and (d2%3==0)):
    f1=d1/3

    f2=d2/3

    num=f1+f2
    
    print(math.factorial(num))
else:
    print("0")

Submission status: Wrong Answer

Solution code:
MOD = 10**9 + 7
def comb(n, k, MOD):
    if n < k or n < 0 or k < 0:
        return 0
    iinv = [1] * (k + 1)
    ans = n
    for i in range(2, k + 1):
        iinv[i] = MOD - iinv[MOD % i] * (MOD // i) % MOD
        ans *= (n + 1 - i) * iinv[i] % MOD
        ans %= MOD
    return ans
X, Y = map(int,input().split())
if (X+Y) % 3 != 0:
    print(0)
    exit()
n = (2*Y-X)//3
m = (2*X-Y)//3
print(comb(n+m,m,MOD))

Submission status: Wrong Answer

Solution code:
MOD = 10**9 + 7
def comb(n, k, MOD):
    if n < k:
        return 0
    k = min(k, n - k)
    if k == 0:
        return 1
    iinv = [1] * (k + 1)
    ans = n
    for i in range(2, k + 1):
        iinv[i] = MOD - iinv[MOD % i] * (MOD // i) % MOD
        ans *= (n + 1 - i) * iinv[i] % MOD
        ans %= MOD
    return ans
X, Y = map(int,input().split())
if (X+Y) % 3 != 0:
    print(0)
    exit()
n = (2*Y-X)//3
m = (2*X-Y)//3
print(comb(n+m,m,MOD))

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline

_x, _y = map(int, input().split())


def nCk(n, k, m=10 ** 9 + 7):
    a = b = 1
    k = min(k, n - k)
    for i in range(k):
        a = (a * (n - i)) % m
        b = (b * (i + 1)) % m

    return (a * pow(b, m - 2, m)) % m


def chker(x, y):
    if x == y:
        if x % 3 != 0:
            print(0)
            return

        b = x // 3
        print(nCk(2 * b, b))
        return

    x, y = (x, y) if x < y else (y, x)

    b = 2 * x - y
    if b % 3 != 0:
        print(0)
        return

    d1, d2 = b // 3, x - 2 * (b // 3)
    u = d1 + d2

    print(nCk(u, d1))


chker(_x, _y)

Submission status: Wrong Answer

Solution code:
def get(n):
    s=1

    for i in range(1,n+1):

        s=s*i

    return s

x,y=input().split()

x=abs(int(x))

y=abs(int(y))

d1=(2*x-y)

d2=(2*y-x)

if ((d1%3==0) and (d2%3==0)):
    f1=d1/3

    f2=d2/3

    num=f1+f2
    
    print(get(int(num)))
else:
    print("0")

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline

_x, _y = map(int, input().split())


def nCk(n, k, m=10 ** 9 + 7):
    a = b = 1
    k = min(k, n - k)
    for i in range(k):
        a = (a * (n - i)) % m
        b = (b * (i + 1)) % m

    return (a * pow(b, m - 2, m)) % m


def chker(x, y):
    if x == y:
        if x % 3 != 0:
            print(0)
            return

        b = x // 3
        print(nCk(2 * b, b))
        return

    x, y = (x, y) if x > y else (y, x)

    b = y - x / 2
    if 2 * b % 3 != 0:
        print(0)
        return

    d1, d2 = int(2 * b // 3), int(x / 2 - b / 3)
    u = d1 + d2

    print(nCk(u, min(d1, d2)))


chker(_x, _y)

Submission status: Wrong Answer

Solution code:

X,Y = map(int,input().split())
b = (2*X -Y) / 3
if b != int(b):
    print(0)
    quit()
b = int(b)
a = X - 2 * b



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


ans = combination(a+b,a)

print(ans)

Submission status: Wrong Answer

Solution code:

X,Y = map(int,input().split())
b = (2*X -Y) // 3
a = X - 2 * b
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


ans = combination(a+b,a)

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline

_x, _y = map(int, input().split())


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 chker(x, y):
    if x == y:
        if x % 3 != 0:
            print(0)
            return

        b = x // 3
        print(combination(2 * b, b))
        return

    x, y = (x, y) if x > y else (y, x)

    b = y - x / 2
    if 2 * b % 3 != 0:
        print(0)
        return

    d1, d2 = int(2 * b // 3), int(x / 2 - b / 3)
    u = d1 + d2

    print(combination(u, min(d1, d2)))


chker(_x, _y)

Submission status: Wrong Answer

Solution code:
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

    iinv = [1] * (k + 1)
    ans = n
    for i in range(2, k + 1):
        iinv[i] = MOD - iinv[MOD % i] * (MOD // i) % MOD
        ans *= (n + 1 - i) * iinv[i] % MOD
        ans %= MOD
    return ans


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

if a < 0 or b < 0:
    ans = 0
elif a % 3 != 0 or b % 3 != 0:
    ans = 0
else:
    a //= 3
    b //= 3
    # print(a, b)
    ans = comb(a + b, a, MOD)

print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/python

import sys
from pprint import pprint

import math

def nCr(n, r):
    v = 10**9 + 7
    return math.factorial(n) // math.factorial(r) // math.factorial(n - r)

from operator import mul
from functools import reduce

def cmb(n,r):
    r = min(n - r, r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under

def cmb_mod(n, r, mod):
    r = min(n - r, r)
    if r == 0:
        return 1
    else:
        denominator = 1
        for i in range(n, n - r, -1):
            denominator = (denominator * i) % mod
        numerator = 1
        for i in range(1, r + 1):
            numerator = (numerator * i) % mod
        return denominator * pow(numerator, mod - 2, mod) % mod 

x, y = map(int, sys.stdin.readline().strip().split(" "))

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

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

# print(n, m)
# print(nCr(n+m, n) % (10**9+7))
print(cmb_mod(n + m, n, 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 and (2*x-y)>0 and (2*y-x)>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:
from operator import mul
from functools import reduce
import sys
x,y = map(float,input().split())
m = (2*x - y)/3
n = (y - m)/2
if n < m:
  print(0)
  sys.exit()
if n < 0 or m < 0:
  print(0)
  sys.exit()
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:
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 #出力の制限x
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 = map(int, input().strip().split())

min_num = min(X,Y)
z = min_num//3

tX = z * 3
tY = z * 3
cA = z
cB = z

rx = X - tX
ry = Y - tY
if rx < 0 or ry < 0:
    raise Exception
if rx == 0 and ry == 0:
    print(cmb(cA+cB, cA, mod))
    exit(0)
if rx * 2 == ry:
    cA += rx
elif ry * 2 == rx:
    cB += ry
else:
    print(0)
    exit(0)
print(cmb(cA+cB, cA, mod))

Submission status: Wrong Answer

Solution code:
X,Y = list(map(int,input().split()))
def nCk(n, k, mod=10 ** 9 + 7):
    if n < k:
        return 0
    k = min(k, n - k)
    numer = 1
    for x in range(n - k + 1, n + 1):
        numer = (numer * x) % mod
    denom = 1
    for x in range(1, k + 1):
        denom = (denom * x) % mod
    return numer * pow(denom, mod - 2, mod) % mod
if (X+Y)%3!=0:
    print(0)
else:
    n = (2*Y - X)//3
    m = (2*X - Y)//3

    print(nCk(n+m, m)%(7+10**9))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import math
X,Y = list(map(int,input().split()))
def nCk(n, k, mod=10 ** 9 + 7):
    if n < k:
        return 0
    k = min(k, n - k)
    numer = 1
    for x in range(n - k + 1, n + 1):
        numer = (numer * x) % mod
    denom = 1
    for x in range(1, k + 1):
        denom = (denom * x) % mod
    return numer * pow(denom, mod - 2, mod) % mod
if X%3!=0 or Y%3!=0:
    print(0)
else:
    n = (2*Y - X)//3
    m = (2*X - Y)//3

    print(nCk(n+m, m)%(7+10**9))

Submission status: Wrong Answer

Solution code:
x, y = map(int, input().split())
z = x + y
if z % 3 == 0:
  w = z // 3
  a, b = sorted([x - w, y - w])
  num = 1
  dem = 1
  for i in range(1, a + 1):
    num *= b + i
    dem *= i
  c = num // dem
  print(c % 1000000007)
else:
  print(0)

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 #出力の制限x
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 = map(int, input().strip().split())

min_num = min(X,Y)
z = min_num//3

tX = z * 3
tY = z * 3
cA = z
cB = z

rx = X - tX
ry = Y - tY
if rx == 0 and ry == 0:
    print(cmb(cA+cB, cA, mod))
    exit(0)
if rx * 2 == ry:
    cA += rx
elif ry * 2 == rx:
    cB += ry
else:
    print(0)
    exit(0)
print(cmb(cA+cB, cA, 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:
from operator import mul
from functools import reduce
import sys
x,y = map(float,input().split())
m = (2*x - y)/3
n = (y - m)/2
if n < 0 or m < 0:
  print(0)
  sys.exit()
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)