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:


def kai(a, b, c=0, mod=0 ):
    K = 1
    if c == 1:
        for k in range(a):
            if k == 0:
                t = b
            K *= t
            K %= mod
            t -= 1
            
    else:
        for k in range(a):
            if k == 0:
                t = b
            K *= t
            t -= 1
    return K

X, Y = map(int, input().split())
diff = X - Y
D = (min(X, Y)- abs(diff))
ans = 0
mod = 10**9 + 7
if D%3 != 0:
    print(0)
else:
    m1 = abs(diff) + (D//3)
    m2 = D//3
    s  = m1 + m2

    ans = kai(m2, s,1,mod)%mod * (1/kai(m2, m2))%mod

    print(ans%mod)

Submission status: Wrong Answer

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


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

# A=(+1,+2)をM回、B=(+2,+1)をN回
# X=M+2N, Y=2M+N => (X+Y)/3 = M+N
ans = 0
if (X+Y)%3==0:
    Z = int((X+Y)/3)
    for m in range(X+1):
        n = Z-m
        if X==m+2*n and Y==2*m+n:
            # これが遅い
            # ans = math.factorial(n+m) // (math.factorial(n)*math.factorial(m)) % (10**9+7)

            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 )

            ans = cmb(n+m,min(n,m),mod)

            print(int(ans))
            break
else:
    print(ans)

Submission status: Wrong Answer

Solution code:
def solve():
    X, Y = map(int, input().split())
    if (2 * Y - X) % 3 > 0 or (2 * X - Y) % 3 > 0: print(0)
    else:
        a = (2 * Y - X) // 3
        b = (2 * X - Y) // 3
        mod = 7 + 10 ** 9
        fact = [0] * (2 * 10 ** 6 + 1)
        revfact = [0] * (2 * 10 ** 6 + 1)
        fact[1] = 1
        for i in range(2, 2 * 10 ** 6 + 1):
            fact[i] = (i * fact[i-1]) % mod
        revfact[2 * 10 ** 6] = pow(fact[2 * 10 ** 6], mod - 2, mod)
        for i in reversed(range(2 * 10 ** 6)):
            revfact[i] = ((i + 1) * revfact[i + 1]) % mod

        print((fact[a + b] * revfact[a] * revfact[b]) % mod)
        
    

    return 0

if __name__ == "__main__":
    solve()

Submission status: Wrong Answer

Solution code:
import itertools
import math
X,Y = map(int,input().split())
if (X+Y)%3 != 0:
    print(0)
else:
    lr = (X+Y)//3
    if X == Y:
        left = lr//2
        right = lr//2
    else:
        if X-Y > 0:
            left = math.ceil(lr)
            right = math.ceil(lr)-(X-Y)
        elif X-Y < 0:
            left = math.ceil(lr)-(Y-X)
            right = math.ceil(lr)
    if left*right == 0:
        print(1)
    else:
        print((1*3**(lr//2-1)*2**(lr//2))%(10**9+7))

Submission status: Wrong Answer

Solution code:
import math
x,y = map(int,input().split())
if (x+y)%3 != 0 or min(x,y)*2 < max(x,y):
    ans = 0
else:
    if x > y:
        x,y = y,x
    n = (x+y)//3 +1
    k = x - (n-1)+1
    if k*2 > n:
        k = n - k
    ans = math.factorial(n-1) // (math.factorial(k-1)*math.factorial(n-k))
print(ans%(10**9+7))

Submission status: Wrong Answer

Solution code:
x, y = [int(x) for x in input().split()]
if (x % 2 == 0) or (y % 2 == 0) or ((x < 3) and (y < 3)):
    print(0)
else:
    ans = 1 + x//2
    z = [1] * (x//2)
    for i in range(0, y//2):
        for j in range(1, x//2):
            z[j] = z[j] + z[j-1]
            ans += z[j]
            
    ans /= 10**9+7
    print(ans)

Submission status: Wrong Answer

Solution code:
x,y = map(int,input().split())
ans = 0
if max(x,y)-min(x,y)%3!=0:
  ans = (2**(max(x,y)-min(x,y)))%(10**9+7) 
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10000000)


MOD = 10 ** 9 + 7

def main():
    X, Y = map(int, input().split())
    if (X + Y) % 3 != 0:
        print(0)
        sys.exit()
    elif X < (X + Y) / 3 or Y < (X + Y) / 3:
        print(0)
        sys.exit()
    else:
        x_num, y_num = 0, 0
        while(X > (X + Y) / 3 and Y > (X + Y) / 3):
            if X == Y:
                break
            x_num += 1
            y_num += 1
            X -= 3
            Y -= 3
        if X < Y:
            y_num += Y // 2
        elif Y < X:
            x_num += X // 2
        else:
            x_num += X / 3
            y_num += Y / 3
    
    from math import factorial
    # print(x_num, y_num)
    num = x_num + y_num
    y = 1
    ans = 1
    set_y = set([i for i in range(1, int(y_num) + 1)])
    print(factorial(x_num + y_num) // (factorial(x_num) * factorial(y_num)))
    # for i in range(int(y_num)):
    #     ans *= (num - i)
    #     old_set = set_y.copy()
    #     for j in old_set:
    #         if ans % j == 0:
    #             ans = ans // j
    #             set_y.remove(j)
    #     if len(set_y) == 0:
    #         ans %= MOD
    # print(ans)
        




if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import itertools
import sys
from math import factorial
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())
  
i = (2/3)*X - (1/3)*Y
j = (2/3)*Y - (1/3)*X

if i%1 != 0 or j%1 != 0 or i < 0 or j < 0:
  print(0)
  sys.exit()

if i == 0 or j == 0:
  print(1)
  sys.exit()
  
  
n = i + j

a = cmb(int(n),int(i))#factorial(n) / factorial(i) / factorial(n - i)
print(int(a)%1000000007)

Submission status: Wrong Answer

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

# print(x, y)
count_x1 = 0
count_x2 = 0
count_y1 = 0
count_y2 = 0 

ans = 0

while True:
  if x > y:
    x -= 2
    y -= 1
    count_x2 += 1
    count_y1 += 1
  else:
    x -= 1
    y -= 2
    count_x1 += 1
    count_y2 += 1
  
  if x < 1 or y < 1:
    break

if x == 0 and y == 0:
  if count_x1 == 0 or count_x2 == 0:
    print(1)
    sys.exit()
  
  if count_x1 == count_x2:
    ans = count_x1 * 2
  else:
    min_count = min(count_x1, count_x2)
    ans = 2 ** min_count + 1
else:
  ans = 0

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

Submission status: Wrong Answer

Solution code:
import math
import sys
sys.setrecursionlimit(10**9)

X, Y = map(int, input().split())
a = 2*Y-X
b = 2*X-Y
factorial = math.factorial

if a<0 or b<0 or a%3!=0 or b%3!=0:
    print(0)
    exit()

count = (a+b)//3

ans = 1
MOD = 10**9+7
for i in range(count,0):
    ans *= i%MOD
    ans %= MOD

ans = ans//(factorial(a//3)*factorial(b//3))
print(ans)

Submission status: Wrong Answer

Solution code:
import math
from decimal import Decimal
x,y = list(map(int, input().split()))
mod = 7 + (10**9)
ans = 0
factorial = [1]*(x+y)
for i in range(1,max(x,y)):
    factorial[i] = (factorial[i - 1] * i) % mod
for i in range(y + 1):
    if (2 * x) - ( y) == 3 * i:
        k = x - 2 * i
        ans += factorial[k + i] / (factorial[k] * factorial[i])

print(int(ans))

Submission status: Wrong Answer

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

import math
res = []

def fct(i):
	return math.factorial(i)

qx = x//2

for i in range(qx+1):
	mx = x - 2 * i
	if (y-i)%2 == 0:
		j = (y-i)//2
		if mx == j:
			res.append(fct(i+j) // fct(i) * fct(j))
	else:
		res.append(0)

p = sum(res) % (10**9+7)
print(int(p))

Submission status: Wrong Answer

Solution code:
class Combination:
    """
    O(n)の前計算を1回行うことで，O(1)でnCr mod mを求められる
    n_max = 10**6のとき前処理は約950ms (PyPyなら約340ms, 10**7で約1800ms)
    使用例：
    comb = Combination(1000000)
    print(comb(5, 3))  # 10
    """
    def __init__(self, n_max, mod=10**9+7):
        self.mod = mod
        self.modinv = self.make_modinv_list(n_max)
        self.fac, self.facinv = self.make_factorial_list(n_max)

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

    def make_factorial_list(self, n):
        # 階乗のリストと階乗のmod逆元のリストを返す O(n)
        # self.make_modinv_list()が先に実行されている必要がある
        fac = [1]
        facinv = [1]
        for i in range(1, n+1):
            fac.append(fac[i-1] * i % self.mod)
            facinv.append(facinv[i-1] * self.modinv[i] % self.mod)
        return fac, facinv

    def make_modinv_list(self, n):
        # 0からnまでのmod逆元のリストを返す O(n)
        modinv = [0] * (n+1)
        modinv[1] = 1
        for i in range(2, n+1):
            modinv[i] = self.mod - self.mod//i * modinv[self.mod%i] % self.mod
        return modinv


def solve(a, b):
    n = a + b
    r = min(a, b)
    comb = Combination(1000000)
    return comb(n, r)


def main(x, y):
    if (2 * x - y) % 3 != 0 or (2 * y - x) % 3 != 0:
        return 0
    a = (2 * x - y) // 3
    b = (2 * y - x) // 3
    return solve(a, b)


if __name__ == '__main__':
    x, y = map(int, input().split())
    print(main(x, y))

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10 ** 7)
X,Y = list(map(int,input().split()))
next_ = [[2,1],[1,2]]
cnt = 0
A = [2]*Y
B = []
for _ in range(X):
    B.append(A)
def dfs(x,y):
    global X
    global Y
    global cnt
    flag = 0
    if B[x][y] == 1:
        cnt += 1
        cnt %= 7+10**9
    elif B[x][y] != 0:
        for i in next_:
            x1 = x+i[0]
            y1 = y+i[1]
            if x1<X and y1<Y:
                dfs(x1,y1)
            elif x1 == X and y1 == Y:
                cnt += 1
                cnt %= 7+10**9
                B[x][y] = 1
                flag = 1
            else:
                B[x][y] = 0
    if flag:
        B[x][y] = 1
    else:
        B[x][y] = 0
dfs(0,0)
print(cnt)

Submission status: Wrong Answer

Solution code:
a = list(map(int,input().split()))
import math
if (2*a[0]-a[0])%3!=0 or (2*a[1]-a[0])%3!=0:
  print(0)
else:
  x=(2*a[0]-a[1])//3
  y=(2*a[1]-a[0])//3
 
  print(math.factorial(x+y)//math.factorial(x)//math.factorial(y))

Submission status: Wrong Answer

Solution code:
import math

x, y = map(int, input().split())
div_num = 10e9+7

def my_fact(n):
    f = 1
    for i in range(1, n+1):
        #print(f)
        f = f*i%div_num

    return f%div_num

if x%3 == 0 and y%3 == 0:
    nx = int(x/3)
    ny = int(y/3)
    print(my_fact(nx+ny))
    #print(math.factorial(nx+ny)%div_num)
else:
    print(0)

Submission status: Wrong Answer

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

if (x+y)%3==0 and x<=2*y and y<=2*x:
    a=(x+y)/3
    b=(2*x-y)/3
    a=int(a)
    b=int(b)
    for i in range(int(b)): #aCbが答
        ans*=(a-i)/(i+1)
        ans=int(ans)
        #print(ans)
        if ans>10**9+7:
            ans=ans%(10**9+7)
else:
    ans=0
print(int(ans))

Submission status: Wrong Answer

Solution code:
import math

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

if((2*Y-X)%3 != 0 or (2*X-Y)%3 != 0):
    print("0")
else:
    a =  int((2*Y-X) / 3)
    b =  int((2*X-Y) / 3)

    if(a <= 0 or b <= 0):
        print("0")
    else:
        numerator = [b + k + 1 for k in range(a)]
        denominator = [k + 1 for k in range(a)]

        for p in range(2,a+1):
            pivot = denominator[p - 1]
            if pivot > 1:
                offset = (b) % p
                for k in range(p-1,a,p):
                    numerator[k - offset] /= pivot
                    denominator[k] /= pivot

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

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

Submission status: Wrong Answer

Solution code:
x, y = map(int, input().split())
mod_val = 10**9 + 7
if x % 2 == 0:
  print(0)
else:
  dp = [0] * ((x+1)//2+2)
  dp[1] = 1
  for i in range(2, ((x+1)//2)+2):
    dp[i] = dp[i-1] + dp[i-2]
    dp[i] %= mod_val
  print(dp[(x+1)//2+1])

Submission status: Wrong Answer

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


def main():
    sc = Scan()
    x, y = sc.intarr()
    if (x + y) % 3 != 0:
        print('0')
        exit()
    if x > y:
        a, b = x, y
    else:
        a, b = y, x
    if a == b:
        pass
    elif b * 2 > a:
        print('0')
        exit()
    if a == 2 and b == 1:
        print('1')
        exit()

    jump = 0
    if a == b:
        jump = a // 3
    else:
        while True:
            a -= 3
            b -= 3
            jump += 1
            if a < b:
                break
    print((2**(jump+1) - 2) % 1000000007)


class Scan():

    def intarr(self):
        line = input()
        array = line.split(' ')
        num_array = [int(n) for n in array]
        return num_array

    def strarr(self):
        line = input()
        array = line.split(' ')
        array[-1] = array[-1].strip('\n')
        return array


main()

Submission status: Wrong Answer

Solution code:
import math
x, y = map(int, input().split())
f = 0
if (x+y)%3 != 0:
	print(f)
else:
	n = (x+y)/3
	k = (math.floor(n/2))*2- math.floor(abs((x-y)/2))
	a = (math.factorial(n) // math.factorial(n - k))%1000000007
	print(a)

Submission status: Wrong Answer

Solution code:
x,y=map(int,input().split())
a=(10**9)+7
li=[]
def c(n,k): 
  return 1 if(k<=0 or n<=k) else c(n-1, k-1) + c(n-1, k)
if (x+y)%3==0:
    z=int((x+y)/3)
    if max((x-y),(y-x))<=z:
        w=int((z-max((x-y),(y-x)))/2)
        for i in range(z+1):
            li.append([c(i,j)%a for j in range(i+1)])
        print((li[z])[w])
else:
    print(0)

Submission status: Wrong Answer

Solution code:
X,Y = map(int,input().split())
ans = 0
if Y//2 > X:
  na_max = X+1
else:
  na_max = Y//2+1
if X//2 > Y:
  nb_max = Y+1
else:
  nb_max = X//2+1
  
if (2*X-Y)%3==0:
  nb = (2*X-Y)//3
  for na in range(0,na_max):
    if na == (Y-nb)//2:
      ans+=1
  print(ans//10**9+7);exit()
print(0)

Submission status: Wrong Answer

Solution code:
import sys,itertools
def input():
    return sys.stdin.readline()[:-1]

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

S = X+Y

# def comb(n,R):
#     nCr = 1
#     for r in range(n):
#         nCr_1 = nCr * (n - r) // (r + 1)
#         nCr = nCr_1
#         nCr %= u
#         if r==R-1:
#             break
#     return nCr%u
def com(n,r):
    ans = 1
    print(n-r)
    for i in range(n,n-r,-1):
        ans *= i
        ans %= u
        # print(ans)
    k = 1
    for j in range(1,r+1):
        # print(j)
        if ans%j==0:
            ans //= j
    return ans

if not S%3==0:
    print(0)
    exit()
else:
    small = S//3
    s_elm = min(X,Y)
    if s_elm<small:
        print(0)
        exit()
    print('a')
    r = s_elm - small
    print(small,r)
    ans = com(small,r)
    ans %= u
print(ans)

Submission status: Wrong Answer

Solution code:
import math 
atai = list(map(int,input().split()))
X = atai[0]
Y = atai[1]
P = [0,0]
Q = [X,Y]
way_P = [P]
way_Q = [Q]
way_a = 0
way_b = 0
ans = 0
for i in range(0,max(X,Y)//2+1):
    P[0] = P[0] + 2
    P[1] = P[1] + 1
    Q[0] = Q[0] - 1
    Q[1] = Q[1] - 2
    way_P += [P]
    way_Q += [Q]
for i in range(0,len(way_P)):
    if way_P[i] in way_Q:
        way_a = way_P[i][1]
        way_b = X - way_P[i][0]
        ans = (math.factorial(way_a + way_b)//(math.factorial(way_a)*math.factorial(way_b))) % (10**9 + 7)
print(ans)

Submission status: Wrong Answer

Solution code:

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

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

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

ans1=1

for i in range(1,a+b+1):
    if i<=a and i<=b:
        ans1=(ans1*i)//(i**2)
        ans1=ans1%mod
    elif i<=a and i>b:
        ans1=(ans1*i)//i
        ans1=ans1%mod
    elif i>a and i<=b:
        ans1=(ans1*i)//i
        ans1=ans1%mod
    else:
        ans1=ans1*i
        ans1=ans1%mod

ans=ans1%mod

print(ans)

Submission status: Wrong Answer

Solution code:
import math


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(math.factorial(i+j)/math.factorial(i)/math.factorial(j))

Submission status: Wrong Answer

Solution code:
# coding: utf-8


def solve(*args: str) -> str:
    x, y = map(int, args[0].split())
    ret = 0
    mod = 1000000007

    if (2*y-x) % 3 == 0 and (2*x-y) % 3 == 0:
        ret = 1
        a = (2*y-x)//3
        b = (2*x-y)//3
        for n in range(2, a+b+1):
            ret = (ret * (n % mod)) % mod

    return str(ret)


if __name__ == "__main__":
    print(solve(*(open(0).read().splitlines())))

Submission status: Wrong Answer

Solution code:

X,Y=map(int,input().split())
import math
def f2(r):

    return inv_t
def co(n,r):
    lim = 10**9 +7
    ans =1
    for i in range(1,r+1):
        ans = (ans * (n+i-1)) % lim
        
    P = 10**9 + 7
    N = r+1
    inv_t = [0]+[1]
    for i in range(2,N):
        inv_t += [inv_t[P % i] * (P - int(P / i)) % P]
        
    for i in range(1,r+1):
        ans = (ans * inv_t[i])  % lim
    return ans
def c(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
if (X+Y)%3==0:
    Z=X+Y
    if min(X,Y)-Z//3 >-1:
        #print(1)
        print(co(Z//3,min(X,Y)-Z//3))
    else:
        print(0)
else:
    print(0)

Submission status: Wrong Answer

Solution code:
a, b=(int(x) for x in input().split())

if (a + b / 3 != 0):
    print(0)
else:
    t = pow(pow(a - b, 2), 0.5)
    if (a - t < 0 or b - t < 0):
        print(0)
    else:
        print(a + b / 3)

Submission status: Wrong Answer

Solution code:
import numpy as np
e = 1000000000 + 7
N = 1000000

def binominal(n, k):
	if k == 0 or k == n:
		return 1
	else:
		ans = 1
		for i in range(0, k):
			ans = (ans * (n - i) / (k - i)) % e 
		return ans

# def pascal(n, k):
# 	pre = np.zeros(N)
# 	pre[0] = 1
# 	for _ in range(n):
# 		tmp = pre + np.roll(pre, 1)
# 		pre = tmp % e
# 	return int(pre[k])


if __name__ == "__main__":
	X, Y = map(int, input().split())
	if (X + Y) % 3 != 0:
		print("0")
	else:
		n = (X + Y) // 3
		k = Y - n
		print(binominal(n, k))

Submission status: Wrong Answer

Solution code:
import math
X, Y = list(map(int, input().split()))
k = (2*Y-X)//3
l = Y - 2*k
flag = 0
if (2*Y-X)%3 != 0:
    flag = 1
if k < 0:
    flag = 1
if l < 0:
    flag = 1
# 行けない場合はflagが1になる
# print(int((math.factorial(k+l)/math.factorial(k)/math.factorial(l))%(10**9+7)))
if flag == 1:
    print(0)
else:
    ans = 1
    for ii in range(k):
        ans = (ans*(k+l-ii)/(k-ii))%(10**9+7)
    print(int(ans))

Submission status: Wrong Answer

Solution code:
X,Y=map(int,input().split())
x=2*X-Y
y=2*Y-X
over=1
under=1
i=x+y
if x%3!=0 or y%3!=0:
    print(0)
else:
    x=x//3
    y=y//3
    n=x+y
    r=min(x,y)
    for i in range(r):
        if under%(n-i)==0:
            under//=(n-i)
            under*=(r-i)
        else:
            over*=(n-i)
            under*=(r-i)
    ans=over//under
    print(ans%(10**9+7))

Submission status: Wrong Answer

Solution code:
def main():
    X,Y=map(int,input().split())
    a=X+Y
    if a%3==0:
        b=a//3
        c=10**9+7
        print(b%c)

if __name__=='__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**7)
import math


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():
    x = int(x)
    y = int(y)
    maximam = max(x,y)
    minimam = min(x,y)
    bunbo = 1
    for i in range(1,minimam+1):
        bunbo = bunbo * (maximam + i) / i % z
    print(int(bunbo))
else:
    print(0)

Submission status: Wrong Answer

Solution code:
import numpy as np
i8 = np.int64
MOD = 1000000007


def init(fac, inv, finv):
    fac[0] = fac[1] = 1
    finv[0] = finv[1] = 1
    inv[1] = 1
    for i in range(2, fac.shape[0]):
        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, fac, finv):
    if n < k:
        return 0
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD

def main2():
    X, Y = map(int, input().split())
    a = X + Y
    if a % 3:
        print(0)
    else:
        d = a // 3
        if X < d or Y < d:
            print(0)
        else:
            # 2高係数 d C X-d が計算できればいい
            fac = np.empty(d + 1, i8)
            inv = np.empty(d + 1, i8)
            finv = np.empty(d + 1, i8)
            init(fac, inv, finv)
            ans = com(d, X - d, fac, finv)
            print(ans)

main2()

Submission status: Wrong Answer

Solution code:
import sys

mod = 10**9+7

def abc(num):
    ret = 1
    for i in range(1,num+1):
        ret *= i

    return ret

def abcd(num1,num2):
    ret = 1
    for i in range(num1+1,num2+1):
        ret *= i
    return ret


x,y = map(int,input().split())
n = abs(x-y)
if n != 0:
    if x > y:
        x -= 2*n
        y -= n
    else:
        y -= 2*n
        x -= n
if x%3:
    print(0)
    sys.exit()

a = x*2//3 + n
b = x*1//3

ans = abcd(a,b) // (abc(a-b))

print(ans%mod)

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(a) and b==int(b)):
    n=1
    for i in range(1,int(a+b+1)):
        n*=i
    print(i%(1000000000+7))
else:
    print(0)

Submission status: Wrong Answer

Solution code:
import sys
x, y = map(int, input().split())
MOD = 10**9+7
MAX = 10**6
fac, finv, inv = [0]*MAX, [0]*MAX, [0]*MAX

fac[0] = fac[1] = 1
finv[0] = finv[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 nck(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

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

cnt = (x+y)//3
one = (cnt - abs(x-y))//2 - abs(x-y)
lim = max(cnt, one)
print( int(nck(cnt, one)%MOD) )

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 = all_num//2 + diff//2
        if X > Y*2:
            flag = True
    elif Y > X:
        diff = Y - X
        all_num = (X+Y)//3
        count_2 = all_num//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:
import scipy
from scipy.misc import comb
X,Y = map(int,input().split())
T = X + Y
if T % 3 != 0:
    print(0)
elif X > 2*Y:
    print(0)
elif Y > 2*X:
    print(0) 
else:
    Z = comb(T/3,X-T/3) % 1000000007
    print(Z)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
X,Y=map(int,input().split())
number=int(str(X)+str(Y))
cnt1=0
cnt2=0
if (number%21)%12==0:
  cnt1=cnt1+number//21
  cnt2=cnt2+(number%21)//12
  print((cnt1+cnt2)%(10**9+7))
else:
  print("0")

Submission status: Wrong Answer

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


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

if (X + Y) % 3 != 0 or abs(X-Y) >= (max(X, Y)+1)//2:
    print(0)
else:
    print(cmb((X+Y)//3, (X+Y)//3 - abs(X-Y)//2) % (10**9+7))

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])
            result % (10**9+7)

    return result % (10**9+7)
    
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(cmb(int(a+b),int(a)))

Submission status: Wrong Answer

Solution code:
import sys
import math
from decimal import Decimal
X, Y = map(int,sys.stdin.readline().split())
ans = 0
amari = 10**9 +7
i = (2*X  -Y)/3
j = (2*Y-X)/3
#print(i, j)

def calc(num):
    A =1
    for k in range(int(num), 0,-1):
        A *=k
        if A >= amari:
            A = A%amari
    return A

if i.is_integer() and j.is_integer():
    ans = (calc(i+j))/(calc(i)*calc(j))
    print(int(ans))
else:
    print(0)

Submission status: Wrong Answer

Solution code:
X,Y = [int(i) for i in input().split()]
def check(x,y):
    if x/2 == y:
        return 0
    elif x/2 < y:
        return 1
    else:
        return 9
cnt = 0
possible = True

def mod_inv(a,m):
    x = extgcd(a,m)[0]
    return (m+x%m)%m
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]]

def cmb(n,r):
    m = 10**9+7
    res = 1
    for i in range(1,n+1):
        res = res*i%m
    for i in range(1,r+1):
        res = res*mod_inv(i,m)%m
    for i in range(1,n-r+1):
        res = res*mod_inv(i,m)%m
    return res

while True:
    check_num =  check(X,Y)
    if check_num == 0:
        break
    elif check_num == 1:
        X += 1
        Y -= 1
        cnt += 1
    else:
        possible = False
        break
if possible == True:
    n = int(X / 2 )
    r = cnt
    print(cmb(n,r))
else:
    print(0)

Submission status: Wrong Answer

Solution code:
import sys

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

n1 = (2 * X - Y)
n2 = (2 * Y - X)

if n1 % 3 == 0 and n2 % 3 == 0:
    n1 = n1 // 3
    n2 = n2 // 3
else:
    print(0)
    sys.exit()

P = 10 ** 9 + 7
N = 10 ** 6 + 1
inv_t = [0]+[1]
for i in range(2, N):
    inv_t += [inv_t[P % i] * (P - int(P / i)) % P]

m = 10 ** 9 + 7
res = 1
for i in range(2, n1 + n2 + 1):
    res = res * i % m
for i in range(1, n2 + 1):
    res = res * inv_t[i] % m
for i in range(1, n1 + 1):
    res = res * inv_t[i] % m
print(res)

Submission status: Wrong Answer

Solution code:
x,y = list(map(int, input().split()))
if (x+y) % 3 != 0:
    print(0)
else:
    if (x+y)/3 < 10**9+7:
        print((x+y)/3)
    else:
        mod = (x+y)/3 % (10**9+7)
        print(mod)

Submission status: Wrong Answer

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

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(1000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

x,y = LI()
if (x + y) % 3 != 0:
    print(0)
    quit()

if x//2 > y or y//2 > x:
    print(0)
    quit()

fact = [1]*(x+y+1)
for i in range(1,x+y+1):
    fact[i] = i*fact[i-1]
    fact[i] %= mod

if x*2 == y or y*2 == x:
    print(1)
    quit()
ans = 0
s,t = x//3,y//3
if x % 3 == 0 and y % 3 == 0:
    ans = fact[s+t]*pow(fact[s],mod-2,mod)*pow(fact[t],mod-2,mod)
    ans %= mod
    print(ans)
else:
    if x > y:
        s += 1
    else:
        t += 1
    ans = fact[s+t]*pow(fact[s],mod-2,mod)*pow(fact[t],mod-2,mod)
    ans %= mod
    print(ans)

Submission status: Wrong Answer

Solution code:
from operator import mul
from functools import reduce

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

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

def com(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 % (1000000000 + 7)
  
if a % 1 != 0 or b % 1 != 0:
  print(0)
else:
  print(com(int(a + b), int(a)))