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: Runtime Error

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**4
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 = 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),mod))

Submission status: Runtime Error

Solution code:
import math
x , y = map(int,input().split())
flag = False
MOD = 10**9 + 7
for s in range(max(x,y)):
    if 2 * x - 3 * s == y:
        flag = True
        break
t = x - 2 * s
if flag:
    print(math.factorial(t+s)//(math.factorial(t) * math.factorial(s)) % MOD)
else:
    print(0)

Submission status: Runtime Error

Solution code:
n, t = map(int, input().split())

a = [0]*3333
b = [0]*3333
dp = [0]*6666


for i in range(1, n+1):
	a[i], b[i] = map(int, input().split())

for i in range(1, n+1):
	for j in range(6000, 0, -1):
		if ((a[i] <= j) and ((j-a[i])<t)):
			dp[j] = max(dp[j], dp[j - a[i]] + b[i])

#print(dp)
print(max(dp))

Submission status: Runtime Error

Solution code:
import math

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

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

if a.is_integer() and b.is_integer():
    ans = 1
    a = int(a)
    b = int(b)
    ans = math.factorial(a+b) / (math.factorial(a) * math.factorial(b) )
    ans = int(ans)
else:
    ans = 0

print(ans)

Submission status: Runtime Error

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

MOD = 10**9+7


if (X+Y)%3 != 0:
    ans = 0
else:
    N = int((X+Y)/3)

    if X >= Y:
        #K = N - (X - Y) + 1
        K = N/2 - (X - Y) + 1

    else:
        K = N - (Y - X) + 1

    #ans = factorial(N-1)/(factorial(N-K)*factorial(K-1))
    ans = factorial(N+1-1)/(factorial(N-K+1)*factorial(K-1))
    ans %= MOD


#print(N)
#print(K)
print(ans)

Submission status: Runtime Error

Solution code:
from scipy import special

class Combination:
    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):
        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):
        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

i = list(map(int, input().split()))
x = i[0]
y = i[1]

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

if a.is_integer() and b.is_integer():
    a = int(a)
    b = int(b)
    comb = Combination(a+b)
    ans = comb(a+b,a)
else:
    ans = 0

print(ans)

Submission status: Runtime Error

Solution code:
mod1 = 10**9 + 7
def mul(a, b):
    return ((a % mod1) * (b % mod1)) % mod1

def power(x, y):
    if   y == 0     :
      return 1
    elif y == 1     :
      return x % mod1
    elif y % 2 == 0 :
      return power(x, y/2)**2 % mod1
    else            :
      return power(x, y/2)**2 * x % mod1

def div(a, b):
    return mul(a, power(b, mod1-2))


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

if (2*Y - X)%3 != 0 or (2*X - Y)%3 != 0:
  print(0)
else:
  x = int((2*Y - X)/3)
  y = int((2*X - Y)/3)
  kazu = x + y
  result1 = 1
  result2 = 1
  for i in range(kazu-y):
    result1 *= (y+i+1)
    result1 %= mod1
    
  for i in range(x):
    result2 *= (i+1)
    result2 %=mod1
    
  result = div(result1,result2)
  print(result)

Submission status: Runtime Error

Solution code:
from operator import mul
from functools import reduce

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

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)

if (x+y)%3 != 0:
    print(0)
    exit()
else:
    s = (x+y)//3

t = min((x-s),(y-s))


print(cmb(s,t)%mod)

Submission status: Runtime Error

Solution code:
mod = 10**9+7

from math import factorial
def cmb(n, r):
    ''' 組み合わせ '''
    return factorial(n) // (factorial(n - r) * factorial(r))


def solve(a, b):
    n = a + b
    r = min(a, b)
    return cmb(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) % mod)

Submission status: Runtime Error

Solution code:
import numpy as np


def main():
    obj = input().strip().split(' ')
    X = int(obj[0])
    Y = int(obj[1])


    # X = a + 2b
    # Y = 2a + b

    if (X + Y) % 3 != 0:
        print(0)
        return
    else:
        if 2 * X - Y > 0 and (2 * X - Y) % 3 == 0:
            b = (2 * X - Y) // 3
            a = X - 2 * b

            # for calc combination
            MAX = a + b + 1
            MOD = 10**9 + 7
            fac = np.zeros(MAX)
            finv = np.zeros(MAX)
            inv = np.zeros(MAX)
            fac[0] = 1
            fac[1] = 1
            finv[0] = 1
            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

            count = fac[a + b] * (finv[a] * finv[b] % MOD) % MOD

            print(int(count))
            return

if __name__ == '__main__':
    main()

Submission status: Runtime Error

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

def rec(i,j):
    if(i==0 and j==0):
        return 1
    elif(i<0 or j<0):
        return 0
    else:
        return rec(i-1,j-2)+rec(i-2,j-1)
ans=rec(x,y)
print(int(ans%(1e+9+7)))

Submission status: Runtime Error

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


def dfs(u, v):
    if u > x:
        return 0
    if v > y:
        return 0

    if u == x and v == y:
        return 1

    return dfs(u+1, v+2) + dfs(u+2, v+1)


print(dfs(0, 0) % (10**9 + 7))

Submission status: Runtime Error

Solution code:
import math

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

if (x + y) % 3 != 0:
    ans = 0
else:

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

    a_b = math.factorial(a+b)
    ab = math.factorial(a)* math.factorial(b)
    

    ans = (a_b // ab) % 1000000007

    # answer = (a+b)! / a!b! mod 10^9+7

    
print(ans)

Submission status: Runtime Error

Solution code:
import math
import numpy as np

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

A = np.array([[1, 2],
             [2, 1]])

b = np.array([x, y])
 
sol_auto = np.linalg.solve(A, b)


if sol_auto[0].is_integer() == True and sol_auto[1].is_integer() == True:
    k = math.factorial(sol_auto[0]+sol_auto[1])/(math.factorial(sol_auto[0])*math.factorial(sol_auto[1]))

    print(int(k%1000000007))
else:
    print(0)

Submission status: Runtime Error

Solution code:
import math
a = input().split()
x = int(a[0])
y = int(a[1])
i = (2* y - x) / 3
j = (2* x - y) / 3
if (i - int(i)) > 0 or (j - int(j)) > 0:
  print(0)
else:
  print(
    int((
      math.factorial(i+j) / (math.factorial(i) * math.factorial(j))
    ) % (pow(10, 9) + 7))
  )

Submission status: Runtime Error

Solution code:
import math
MOD = 10**9 + 7
X, Y = [int(x) for x in input().split()]
if (X+Y) % 3 != 0:
    print(0)
    exit()
r = (X+Y) // 3
k = X - r
fact = [1] * (r+2)
print(math.factorial(r)//(math.factorial(r-k)*math.factorial(k)) %MOD)

Submission status: Runtime Error

Solution code:
import sys
import math
def kotae(dai, syou):
    sub = 1
    for i in range(syou,dai+1):
        sub*=i
    return sub % (10**9 + 7)
x, y = map(int, input().split())
a = (2*y-x)/3
b = -2*a + y
if a % 1 != 0:
    print(0)
    sys.exit(0)
a = int(a)
b = int(b)
#print("a, b",a,b)
#print("kotae(a+b,a)",kotae(a+b,a))
#if a > b:
    #print(kotae(a+b, a) // kotae(b,1)%(10**9+7)
print(math.factorial(a+b) // (math.factorial(a) * math.factorial(b))%(10**9+7))
#else:
    #print(kotae(a+b, b) // kotae(a,1)%(10**9+7))
#    print(math.factorial(a+b) // (math.factorial(333333) * math.factorial(333333))%(10**9+7))

Submission status: Runtime Error

Solution code:
def powermod(a, p, mod):
    if p == 0:
        return 1
    elif p % 2 == 0:
        return (powermod(a, p//2, mod) ** 2) % mod
    else:
        return ((powermod(a, (p-1)//2, mod) ** 2) % mod) * a % mod

def combinationmod(n,r):
    mod = 10 ** 9 + 7
    factorial = 1
    for i in range(n):
        factorial = (factorial * (i+1)) % mod
        if i+1 == r:
            fact_1 = factorial
        if i+1 == n-r:
            fact_2 = factorial
        if i+1 == n:
            fact_0 = factorial
    return fact_0 * powermod(fact_1,mod-2,mod) % mod * powermod(fact_2,mod-2,mod) % mod
    
X,Y = map(int,input().split())
if (X + Y) % 3 == 0:
    turns = (X + Y) // 3
    print(combinationmod(turns, min(X,Y) - turns))
else:
    print(0)

Submission status: Runtime Error

Solution code:
import math
X,Y = map(int,input().split())
a,b = (2*Y-X)/3,(2*X-Y)/3
n = 10**9+7
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**4
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 )
def count():
  if not (a//1 == a and b//1==b):
    return 0
  else:
    ahat = int(a%n)
    bhat = int(b%n)
    return cmb(ahat+bhat,ahat)


print(int(count())%(10**9+7))

Submission status: Runtime Error

Solution code:
import sys
import numpy as np

INPUT = lambda: sys.stdin.readline().rstrip()
MAP = lambda: map(int, INPUT().split())

sys.setrecursionlimit(10 ** 9)
mod = 10 ** 9 + 7


def main():
    X, Y = MAP()
    if (X + Y) % 3 != 0: print(0)
    s = (2*X - Y)//3
    t = (2*Y - X)//3
    MAX_NUM = max(X, Y)
    dp = np.zeros((MAX_NUM, MAX_NUM), np.int)
    for i in range(MAX_NUM):
        if i == 0:
            for j in range(len(dp[0])):
                if j == 0: dp[i][j] = 0
                else: dp[i][j] = 1
        else:
            for j in range(len(dp[0]-1)):
                if j == 0: dp[i][j] = 1
                else: dp[i][j] = dp[i-1][j] + dp[i][j-1]

    print(dp[s][t] % mod)


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
x, y = map(int,input().split())
if (x+y)%3!=0:
  print(0)
  exit()
n = (x+y)//3
if 0 > x-n or 0 > y-n:
  print(0)
  exit()

m = min(x-n,y-n)
mod = 1000000007
ans = 1
for i in range(m):
  ans = (ans *(n-i) // i) % mod
print(ans)

Submission status: Runtime Error

Solution code:
from sys import stdin
mod = 10**9+7
X,Y = [int(x) for x in stdin.readline().rstrip().split()]

def mul(a, b):
    return ((a % mod) * (b % mod)) % mod

def power(x, n):
    """
    O(log n)
    """
    if n == 0:
        return 1

    K = 1
    while n > 1:
        if n % 2 != 0:
            K *= x % mod
        x *= x % mod
        n //= 2

    return K * x % mod

def div(a, b):
    return mul(a, power(b, mod-2))

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

flag = True
if X == 0 or Y == 0:
    flag = False
x = 0
y = 0
x += min(X//3,Y//3)
y += min(X//3,Y//3)
tmp = min(X//3,Y//3)
X = X-tmp*3
Y = Y-tmp*3
if X == 0 and Y == 0:
    X = X
    Y = Y
elif (Y % (X*2) == 0):
    y += (Y//2)

elif (X % (Y*2) == 0):
    x += (X//2)
else:
    flag = False

if flag:
    ans = fact(x+y)
    ans = div(ans,fact(x))
    ans = div(ans,fact(y))
    print(ans%mod)
    
else:
    print(0)

Submission status: Runtime Error

Solution code:
x, y = map(int, input().split())
a = (2*y-x)//3
b = (2*x-y)//3
c = a+b
flag = 10**9+7
if a<0 or b<0:
  print(0)
elif a<=0 and b<=0:
  print(0)
else:
  total=1
  total_a=1
  for i in range(a):
    total*=(i+b+1)
    total_a*=(i+1)
print(total/total_a%flag)

Submission status: Runtime Error

Solution code:
from scipy.special import comb

def pas(n):
    if n<1 :
        return [1]
    p = pas(n-1)
    return list(map(lambda a,b:a+b, [0]+p, p+[0]))

x,y = map(int,input().split())
if (x+y) % 3 != 0:
    print("0")
else:
    t = (x+y) // 3
    if x >= t and y >= t:
        ans = pas(t)
        print(ans[x-t])
    else:
        print("0")

Submission status: Runtime Error

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

if X>Y:
    if (2*Y-X)%3==0:
        print((math.factorial((2*X-Y)//3+X-Y)/math.factorial((2*X-Y)//3)*math.factorial(X-Y))%(10**9+7))
    else:
        print(0)
elif X<Y:
    if (2*X-Y)%3==0:
        print((math.factorial((2*Y-X)//3+Y-X)/math.factorial((2*Y-X)//3)*math.factorial(Y-X))%(10**9+7))
    else:
        print(0)
else:
    if X%3==0:
        print(int(math.factorial(X//3*2)/math.factorial(X//3)**2%((10**9)+7)))
    else:
        print(0)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
#import numpy as np
import math
from scipy.special import comb

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

if(a % 3 != 0 or b % 3 != 0):
  print(0)
else:
  a = int(a/3)
  b = int(b/3)
  ans = comb(a+b, a, exact=True) 
  #ans = float(math.factorial(a+b))/(math.factorial(a)*math.factorial(b))
  ans = int(ans)%(1000000000 + 7)
  print(ans)

Submission status: Runtime Error

Solution code:
from math import factorial
import sys
mod = 1000000007
def modinv(a, mod=10**9+7):
    return pow(a, mod-2, mod)

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

a = (2*Y-X) / 3
b = Y - 2*a
if a.is_integer() & b.is_integer():
    i = factorial(a+b) % mod
    j = factorial(a) % mod
    k = factorial(b) % mod
    tmp = (i * modinv(j, mod)) % mod
    print(tmp * modinv(k, mod) % mod)
else:
    print(0)

Submission status: Runtime Error

Solution code:
from scipy import special

class Combination:
    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):
        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):
        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

i = list(map(int, input().split()))
x = i[0]
y = i[1]

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

if a.is_integer() and b.is_integer():
    a = int(a)
    b = int(b)
    comb = Combination(a+b)
    ans = comb(a+b,a)
else:
    ans = 0

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

Submission status: Runtime Error

Solution code:
MOD = 10**9 + 7
X, Y = map(int, input().split())
  
if (X+Y)%3!=0:
  print(0)
  quit()
  
if X < Y:
  X, Y = Y, X

sub = X - Y
tan = Y - sub

X = sub + tan//3 + 3
Y = tan//3 + 3
dp = [[0]*X for _ in range(Y)]

dp[2][1] = 1
for i in range(2, Y):
  for j in range(2, X):
    dp[i][j] = (dp[i][j-1] + dp[i-1][j]) % MOD

print(dp[Y-1][X-1])

Submission status: Runtime Error

Solution code:
from math import factorial
import math
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
mod = 10**9+7 #出力の制限

X,Y = map(int,input().split())
n = (2*Y-X)//3
m = (2*X-Y)//3
if (2*Y-X)%3 == 0 and (2*X-Y)%3 == 0:
    ans = cmb(n+m,n)%mod
else:
    ans = 0
print(ans)

Submission status: Runtime Error

Solution code:
from math import factorial
import sys

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

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

if n1 == 0 and n2 == 0:
    print(0)
    sys.exit()

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



P = 10**9 + 7
N = 333335
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(1, 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: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
#import numpy as np
import math
from scipy.special import comb

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

if(a % 3 != 0 or b % 3 != 0):
  print(0)
else:
  a = int(a/3)
  b = int(b/3)
  #ans = comb(a+b, a, exact=True) 
  ans = float(math.factorial(a+b))/(math.factorial(a)*math.factorial(b))
  ans = int(ans)%(1000000000 + 7)
  print(ans)

Submission status: Runtime Error

Solution code:
if __name__=='__main__':
    x,y = map(int,input().split())
    x0 = (2.0*x-y)/3.0
    y0 = (2.0*y-x)/3.0
    if x0<0 or y0<0 or not x0.is_integer() or not y0.is_integer():
        ans = 0
    elif x0==0 and y0==0:
        ans = 1
    else:
        ans = 1
        for i in range(max(x0,y0)+1,x0+y0+1):
            ans = ans*i//(i-max(x0,y0))
    print(int(ans%(10e9+7)))

Submission status: Runtime Error

Solution code:
from sys import stdin
mod = 10**9+7
X,Y = [int(x) for x in stdin.readline().rstrip().split()]

def mul(a, b):
    return ((a % mod) * (b % mod)) % mod

def power(x, n):
    """
    O(log n)
    """
    if n == 0:
        return 1

    K = 1
    while n > 1:
        if n % 2 != 0:
            K *= x % mod
        x *= x % mod
        n //= 2

    return K * x % mod

def div(a, b):
    return mul(a, power(b, mod-2))

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

flag = True
x = 0
y = 0
x += min(X//3,Y//3)
y += min(X//3,Y//3)
tmp = min(X//3,Y//3)
X = X-tmp*3
Y = Y-tmp*3
if X == 0 and Y == 0:
    X = X
    Y = Y
elif (Y % (X*2) == 0):
    y += (Y//2)

elif (X % (Y*2) == 0):
    x += (X//2)
else:
    flag = False

if flag:
    ans = fact(x+y)
    ans = div(ans,fact(x))
    ans = div(ans,fact(y))
    print(ans)
    
else:
    print(0)

Submission status: Runtime Error

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

xy = list(map(int, input().split()))

if (2*xy[1]-xy[0]) % 3 == 0 and (2*xy[0]-xy[1]) % 3 == 0:
    a = (2*xy[1]-xy[0]) // 3
    b = (2*xy[0]-xy[1]) // 3
    print(cmb(a+b, a))
else:
    print(0)

Submission status: Runtime Error

Solution code:
from math import factorial

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

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

if a.is_integer() and b.is_integer():
    print(int(factorial(a+b)/(factorial(a)*factorial(b))%1000000007)) # 順列の数を計算する
else:
    print(0)

Submission status: Runtime Error

Solution code:
from scipy.misc import comb
x,y = map(int, input().split())
k=(2*x-y)/3
l=(2*y-x)/3
if k==int(k) and l==int(l):
  k=int(k)
  l=int(l)
  s=comb(k+l,k)
else:
  s=0
print(int(s%(10**9+7)))

Submission status: Runtime Error

Solution code:

from scipy import special

mod = 10**9+7 #出力の制限

X,Y = map(int,input().split())
n = (2*Y-X)//3
m = (2*X-Y)//3
if (2*Y-X)%3 == 0 and (2*X-Y)%3 == 0:
    ans = special.comb(n+m,n,exact=True)%mod
else:
    ans = 0
print(ans)

Submission status: Runtime Error

Solution code:
import sys
input = sys.stdin.readline
from operator import itemgetter
sys.setrecursionlimit(10000000)
INF = 10**30
from math import factorial

fac = [0] * (10**6+1)
ifac = [0] * (10**6+1)
d = 10**9 + 7

def mpow(x, n):
    ans = 1
    while n != 0:
        if n&1:
            ans = ans * x % d
        x = x*x % d
        n = n >> 1
    return ans

def comb(a, b):
    if a == 0 and b == 0:
        return 1
    if a < b or a < 0:
        return 0
    tmp = ifac[a-b] * ifac[b] % d
    return tmp * fac[a] % d

def main():
    global fac, ifac
    x, y = map(int, input().strip().split())
    if (x + y) % 3 != 0:
        print(0)
        return
    k = (x+y) // 3
    q = x - k

    fac[0] = 1
    ifac[0] = 1
    for i in range(10**6+1):
        fac[i+1] = fac[i]*(i+1) % d
        ifac[i+1] = ifac[i]*mpow(i+1, d-2) % d

    print(comb(k, q) % d)

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import math, sys
sys.setrecursionlimit(20000)

M = 1000000007 #10^9+7
X, Y = [int(j) for j in input().split(' ')]

a = [1, 2]
b = [2, 1]

p_ = [0, 0]

def f(p):
    s = 0
    if p[0]==X and p[1]==Y:
        return 1
    if p[0]>X or p[1]>Y:
        return 0
    p2 = p[:]
    p2[0] += a[0]
    p2[1] += a[1]
    s+=f(p2)
    p2 = p[:]
    p2[0] += b[0]
    p2[1] += b[1]
    s+=f(p2)
    return s

print(f(p_)%M)

Submission status: Runtime Error

Solution code:
import sys
import math
x,y=map(int,input().split())
if ((2*x)-y)%3!=0 or ((2*y)-x)%3!=0:
  print(0)
  sys.exit()
n=((2*x)-y)//3
m=((2*y)-x)//3
a=math.factorial(m+n)
b=math.factorial(m)
c=math.factorial(n)
print((a//(b*c))%((10**9)+7))

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
from scipy.special import comb
A = [int(s) for s in input().split()]
X, Y = A[0], A[1]

def count(X,Y):
    return comb(int((X+Y)/3),X-int((X+Y)/3),exact=True)%(10**9+7)

if Y<=2*X and Y>=0.5*X and (X+Y)%3 == 0:
    print(count(X,Y))
else:
    print(0)

Submission status: Runtime Error

Solution code:
if __name__=='__main__':
    x,y = map(int,input().split())
    x0 = (2.0*x-y)/3.0
    y0 = (2.0*y-x)/3.0
    if x0<0 or y0<0 or not x0.is_integer() or not y0.is_integer():
        ans = 0
    elif x0==0 and y0==0:
        ans = 1
    else:
        ans = 1
        for i in range(max(x0,y0)+1,x0+y0+1):
            ans = ans*i//(i-max(x0,y0))%(10e9+7)
    print(int(ans))

Submission status: Runtime Error

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

MOD = 10 ** 9 + 7

xx = 2 * Y - X
if (xx % 3 == 0 and Y - 2 * xx // 3 >= 0):
    a = xx // 3
    b = Y - 2 * a

    f = 1
    factorials = [1]
    for m in range(1, a + b + 1):
        f *= m
        f %= MOD
        factorials.append(f)

    print (a, b)
    inv = pow(f, MOD - 2, MOD)
    invs = [1] * (a + b + 1)
    invs[a + b] = inv
    for m in range(a + b, 1, -1):
        inv *= m
        inv %= MOD
        invs[m - 1] = inv


    print (factorials[-1] * invs[a] * invs[b] % MOD)

    # print (math.factorial(a + b) // math.factorial(a) // math.factorial(b) %  MOD)


else:
    print (0)

Submission status: Runtime Error

Solution code:
class Solution:
    def solve(self, x: int, y: int) -> int:

        if (2*x - y) % 3 != 0 or (-x + 2*y) % 3 != 0:
            return 0

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

        # calculate {m+n}C{n}

        mod = 10**9 + 7

        # power
        def fastPow(x: int, n: int) -> int:
            ans = 1
            while n > 0:
                if n & 1 == 1:
                    ans = ans * x % mod
                x = x * x % mod
                n >>= 1

            return ans

        # factorial and its inverse
        fact = [1]
        inv = [1]
        for i in range(1, m+n+1):
            fact.append(0)
            inv.append(0)
            fact[i] = fact[i-1] * i % mod
            inv[i] = fastPow(fact[i], mod - 2) % mod

        return fact[n+m] * inv[n] % mod * inv[m] % mod


if __name__ == '__main__':

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

    # solve
    solution = Solution()
    print(solution.solve(x, y))

Submission status: Runtime Error

Solution code:
from math import factorial
x, y = map(int, input().split())
m = 10**9+7

def calc_ans(p, q):
    res = 1
    j=q
    for i in reversed(range(p+1, p+q+1)):
        res = res*i
        if not j == 1:
            res = res/j
            j-=1
        res = res%m
    while not j == 1:
        res = res/j
        j-=1
    return res

if not (x+y)%3==0:
    print(0)
else:
    a = (2*x-y)//3
    b = (2*y-x)//3
    ans = calc_ans(a,b)
    print(int(ans%m))

Submission status: Runtime Error

Solution code:
def mod_combination(n, k, mod):
    # nCk (mod m)
    def mod_permutation(n, k, mod):
        if n<=k:
            return 1
        else:
            return (n * mod_permutation(n-1,k,mod))%mod

    def mod_inv_permutation(k, mod):
        k, mod = int(k), int(mod)
        if k<=1:
            return 1
        else:
            return (pow(k,mod-2,mod) * mod_inv_permutation(k-1, mod))%mod

    return (mod_permutation(n,n-k,mod) * mod_inv_permutation(k, mod))%mod

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

if not((x + y) % 3 == 0):
    print(0)
elif (x > 2*y) or (y > 2 * x):
    print(0)
else:
    k = (x + y) // 3
    i = x - k
    print(mod_combination(k, i, 10 ** 9 + 7))

Submission status: Runtime Error

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




if ((2*Y-X)%3 != 0) or ((2*X-Y)%3 != 0) or (2*Y-X) < 0 or (2*X-Y) < 0:
    print(0)
else:
    x = (2*Y-X) // 3
    y = (2*X-Y) // 3
    fac_list = [None for _ in range(x+y+2)]
    inv_fac_list = [None for _ in range(x+y+2)]

    fac_list[0] = 1
    for i in range(1, x+y+2):
        print(i)
        fac_list[i] = i * fac_list[i-1] % MOD

    inv_fac_list[x+y+1] = pow(fac_list[x+y+1],(MOD - 2), MOD)
    for i in range(x+y, 0, -1):
        inv_fac_list[i] = inv_fac_list[i+1] * (i+1) % MOD

    print((fac_list[x+y] * inv_fac_list[x] * inv_fac_list[y]) % MOD)

Submission status: Runtime Error

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

MOD = 10 ** 9 + 7

xx = 2 * Y - X
if (xx % 3 == 0 and Y - 2 * xx // 3 >= 0):
    a = xx // 3
    b = Y - 2 * a

    f = 1
    factorials = [1]
    for m in range(1, a + b + 1):
        f *= m
        f %= MOD
        factorials.append(f)

    print (a, b, inv)
    inv = pow(f, MOD - 2, MOD)
    invs = [1] * (a + b + 1)
    invs[a + b] = inv
    for m in range(a + b, 1, -1):
        inv *= m
        inv %= MOD
        invs[m - 1] = inv


    print (factorials[-1] * invs[a] * invs[b] % MOD)

    # print (math.factorial(a + b) // math.factorial(a) // math.factorial(b) %  MOD)


else:
    print (0)

Submission status: Runtime Error

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

if (X + Y) % 3 != 0:
    print(0)
else:
    m = (X + Y) // 3 #動かした回数
    d = X - m
    n = math.factorial(m)
    p = math.factorial(m-d)
    q = math.factorial(d)
    print((n // (p * q)) % ((10**9) + 7))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
if __name__=='__main__':
    x,y = map(int,input().split())
    x0 = (2.0*x-y)/3.0
    y0 = (2.0*y-x)/3.0
    if x0<0 or y0<0 or not x0.is_integer() or not y0.is_integer():
        ans = 0
    elif x0==0 and y0==0:
        ans = 1
    else:
        ans = 1
        for i in range(max(x0,y0)+1,x0+y0):
            ans = ans*i//(i-max(x0,y0))%(10e9+7)
    print(int(ans))

Submission status: Runtime Error

Solution code:
import math
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:
    print(int(math.factorial(i+j)/(math.factorial(i)*math.factorial(j))%(pow(10,9)+1)))

Submission status: Runtime Error

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




if ((2*Y-X)%3 != 0) or ((2*X-Y)%3 != 0):
    print(0)
else:
    x = (2*Y-X) // 3
    y = (2*X-Y) // 3
    fac_list = [None for _ in range(x+y+2)]
    inv_fac_list = [None for _ in range(x+y+2)]

    fac_list[0] = 1
    for i in range(1, x+y+2):
        print(i)
        fac_list[i] = i * fac_list[i-1] % MOD

    inv_fac_list[x+y+1] = pow(fac_list[x+y+1],(MOD - 2), MOD)
    for i in range(x+y, 0, -1):
        inv_fac_list[i] = inv_fac_list[i+1] * (i+1) % MOD

    print((fac_list[x+y] * inv_fac_list[x] * inv_fac_list[y]) % MOD)

Submission status: Runtime Error

Solution code:
import functools
import sys

sys.setrecursionlimit(10 ** 9)
sys.setrecursionlimit(5000)


@functools.lru_cache(maxsize=None)
def dis(x, y):
    if (x, y) == (2, 1) or (x, y) == (1, 2):
        return 1
    elif (x, y) == (0, 0):
        return 0
    elif x <= 0 or y <= 0:
        return 0
    else:
        return dis(x - 1, y - 2) + dis(x - 2, y - 1)


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

print(dis(X, Y) % R)

Submission status: Runtime Error

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

MOD = 10 ** 9 + 7

xx = 2 * Y - X
if (xx % 3 == 0 and Y - 2 * xx // 3 >= 0):
    a = xx // 3
    b = Y - 2 * a

    f = 1
    factorials = [1]
    for m in range(1, a + b + 1):
        f *= m
        f %= MOD
        factorials.append(f)

    inv = pow(f, MOD - 2, MOD)
    invs = [1] * (a + b + 1)
    invs[a + b] = inv
    for m in range(a + b, 1, -1):
        inv *= m
        inv %= MOD
        invs[m - 1] = inv

    print (a, b, inv)

    print (factorials[-1] * invs[a] * invs[b] % MOD)

    # print (math.factorial(a + b) // math.factorial(a) // math.factorial(b) %  MOD)


else:
    print (0)

Submission status: Runtime Error

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




mod=10**9+7

if (2*x-y)%3==0 and (2*y-x)%3==0:
  a=(2*x-y)/3
  b=(2*y-x)/3
  #print(a,b)

  result=0.0
  bunbo=1
  bunshi=1
  for i in range(int(a)):
    bunbo=bunbo*(a+b-i)
    bunshi=bunshi*(1+i)
    #print(bunbo,bunshi)
  result=bunbo/bunshi%mod
  print(int(result))
  

  
else:
  print(0)