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:
MOD = 10**9+7 #const

def repeat(n,p):
    if p == 0:
        return 1
    if p%2==0:
        t = repeat(n,p//2)
        return t * t % MOD
    return n * repeat(n,p-1) % MOD


def com(n,r):
    if n < r or n < 0:
        return 0
    if n == 0 and r == 0:
        return 1
    fact = [0] * (n+1)
    fact[0] = 1
    for i in range(n):
        fact[i+1] = fact[i] * (i+1) % MOD #階乗計算
    f_inv = repeat(fact[r],MOD-2)
    f = repeat(fact[n-r],MOD-2)

    return fact[n] * f_inv * f % MOD


def main():
    x,y = map(int,input().split())
    if (x+y)%3 != 0:
        print(0)
    n = (2*y - x)//3
    m = (2*x - y)//3
    print(com(n+m,n))


if __name__ == "__main__":
    main()

Submission status: Runtime Error

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


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


move = [(-1 * X + 2 * Y) // 3, (2 * X - Y) // 3]
ans = 1
for i in range(min(move)):
    n = sum(move) - i
    r = min(move) - i
    ans = (ans * (n % MOD)) % MOD
    ans = (ans * (powermod(r, MOD - 2) % MOD)) % MOD
print(ans)

Submission status: Runtime Error

Solution code:
def Factorial(p, q, prime):  # Factorial from p to q
  p = int(p)
  q = int(q)
  res = 1
  for i in range(p, q):
    res = res * i % prime
  return res

prime = 10 ** 9 + 7
 
X, Y = map(int, input().split(" "))
 
x = (-1*X + 2*Y) / 3
y = (2*X - Y) / 3
 
if int(x) != x or int(y) != y or min(x, y) < 0:
  print(0)
else:
  max_val = max(x, y)
  min_val = min(x, y)
  x_y_factorial = Factorial(max_val + 1, min_val + min_val + 1, prime)
  min_factorial = Factorial(1, min_val + 1, prime)
  
  res = 1
  mod = prime - 2
  while mod:
    if mod & 1:
      res = res * min_factorial % prime
    min_factorial = min_factorial ** 2 % prime
    mod = mod >> 1

print(x_y_factorial * res % prime)

Submission status: Runtime Error

Solution code:
# coding: utf-8
# Your code here!
from operator import mul
from functools import reduce

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

if (X + Y) % 3 != 0:
    print(0)
    sys.exit()
    
num = int((X + Y) / 3) 
A = X - num
B = num - A

print(cmb(num, A) % (10**9 + 7))

Submission status: Runtime Error

Solution code:
import math


x,y=(int(i) for i in input().split())

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

#そもそもマスに進めることができないとき
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
    
    # a+b C aを計算
    up=1
    down=1
    print(permutations_count(a+b,a)%l)

Submission status: Runtime Error

Solution code:
import math
import itertools
import sys

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

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

total_move = (x+y) // 3
move_a = 2 * total_move - x

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

    a = cmb(total_move,move_a,mod)

print(a)

Submission status: Runtime Error

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

def main():
    x, y = map(int, input().split())
    if (2 * y - x) % 3 == 0:
        x_c = (2 * y - x) // 3
        y_c = y - 2 * x_c
        print(x_c, y_c)
        if x_c == 0 or y_c == 0:
            print(1)
        else:
            f = math.factorial
            print(f(x_c+y_c)/(f(x_c) * f(y_c)))
    else:
        print(0)

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
def p_d():
    from scipy.special import comb
    x, y = map(int, input().split())
    mod = 10 ** 9 + 7
    if y > x:
        x, y = y, x
    if (x + y) % 3 != 0:
        print(0)
        exit()
    if x - y > (x + y) // 3:
        print(0)
        exit()
    x, y = x - (x + y) // 3, y - (x + y) // 3
    print(comb(x + y, y, exact=True) % mod)
    
p_d()

Submission status: Runtime Error

Solution code:
import math
from numpy.linalg import solve

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

if (x + y) % 3 != 0:
    print(0)
else:
    left = [[1, 2],
            [2, 1]]
    right = [x, y]
    n, m = map(int, solve(left, right))
    if n < 0 or m < 0:
        print(0)
    else:
        total = n + m
        a = 1
        for i in range(total, total - max(n, m), -1):
            a *= i
        b = math.factorial(min(n, m))
        print(a / b % 1000000007)

Submission status: Runtime Error

Solution code:
from math import inf
x, y = map(int, input().split())

chess_board = [[inf for i in range(x+1)] for j in range(y+1)]

chess_board[0][0] = 1
for i in range(x+1): # 0
    for j in range(y+ 1): # 0 
        if i == 1 and j == 1:
            continue
        elif i and j:	
            prev_i_two_j = chess_board[i-1][j-2] + 1
            prev_j_two_i = chess_board[i-2][j-1] + 1
            chess_board[i][j] = min(chess_board[max(0, i-1)][max(0, j-2)] + 1, chess_board[max(0, i-2)][max(0,j-1)] + 1)


print(chess_board[x][y] - 1 if chess_board[x][y] != inf else 0)

Submission status: Runtime Error

Solution code:
from math import inf
x, y = map(int, input().split())

chess_board = [[inf for i in range(x+1)] for j in range(y+1)]

chess_board[0][0] = 1
for i in range(x+1): # 0
    for j in range(y+ 1): # 0 
        if i == 1 and j == 1:
            continue
        elif i and j:	
            prev_i_two_j = chess_board[i-1][j-2] + 1
            prev_j_two_i = chess_board[i-2][j-1] + 1
            chess_board[i][j] = min(chess_board[max(0, i-1)][max(0, j-2)] + 1, chess_board[max(0, i-2)][max(0,j-1)] + 1)


# [print(' '.join(map(str,i))) for i in chess_board]
print(chess_board[x][y] - 1 if chess_board[x][y] != inf else 0)

Submission status: Runtime Error

Solution code:
import cmath
import numpy as np
import sys

INF=1**18
MOD=10**9+7


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

if (x+y)%3:
    print(0)
    exit()

N=(x+y)//3
if x<N or y<N:
    print(0)
    exit()

def moP(x,n):
    res=1
    while n>0:
        if n and 1:
            res=res*x%MOD
        x=x*x%MOD
        n//=2

fa=[1]*(N+1)
re=[1]*(N+1)


for i in range(1, N+1):
    fa[i]=fa[i-1]*i%MOD
    re[i]=moP(fa[i], MOD-2)

def comb(n,k):
    if n==0 or n==k:
        return 1
    return fa[n]*re[k]%MOD*re[n-k]%MOD

K=min(x,y)-N
print(comb(N,K))

Submission status: Runtime Error

Solution code:
from scipy.special import comb

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

i = 2 * X - Y
if i % 3 != 0:
    print('0')
else:
    y = (2 * X - Y) // 3
    x = X - 2 * y
    result = comb((x + y), x, exact = True) % (10 ** 9 + 7)
    print(result)

Submission status: Runtime Error

Solution code:
from scipy.special import comb

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

i = 2 * X - Y
if i % 3 != 0:
    print('0')
else:
    print('In')
    y = (2 * X - Y) // 3
    x = X - 2 * y
    result = comb((x + y), x, exact = True) % (10 ** 9 + 7)
    print(result)

Submission status: Runtime Error

Solution code:
def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
  #  print(g1[n],g2[r],g2[n-r])
    return g1[n] * g2[r] * g2[n-r] % mod

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

if n <= 0 or m <= 0:
    print(0)
elif int(n) != n or int(m) != m:
    print(0)
else:
    mod = 10**9+7 #出力の制限
    N = n+m
    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,n,mod)
    print(ans)

Submission status: Runtime Error

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

if (X*2 - Y)%3 != 0 or (Y*2 - X)%3 != 0:
    print(0)
    exit()
else:
    X, Y = (X*2 - Y)//3, (Y*2 - X)//3
    waru = 1000000007
    Xfac = math.factorial(X)
    Yfac = math.factorial(Y)
    XYfac = math.factorial(X+Y)
    p = (XYfac // Xfac // Yfac) % waru
    print(p)

Submission status: Runtime Error

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

if (X*2 - Y)%3 != 0 or (Y*2 - X)%3 != 0:
    print(0)
    exit()
else:
    X, Y = (X*2 - Y)//3, (Y*2 - X)//3
    p = [[0 for i in range(Y+2)]for j in range(X+2)]
    waru = 1000000007

    p[0][0]=1
    for y in range(Y+1):
       for x in range(X+1):
            p[x+1][y] = (p[x+1][y] + p[x][y]) % waru
            p[x][y+1] = (p[x][y+1] + p[x][y]) % waru

    print(p[X][Y]%waru)

Submission status: Runtime Error

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

if (X*2 - Y)%3 != 0 or (Y*2 - X)%3 != 0:
    print(0)
    exit()
else:
    X, Y = (X*2 - Y)//3, (Y*2 - X)//3
    p = [[0 for i in range(Y+2)]for j in range(X+2)]
    waru = 1000000007

    p[0][0]=1
    for y in range(Y+1):
        for x in range(X+1):
            p[x+1][y] += p[x][y] % waru
            p[x][y+1] += p[x][y] % waru

    print(p[X][Y]%waru)

Submission status: Runtime Error

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

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

Submission status: Runtime Error

Solution code:
mod = 10**9+7
fac = [1, 1]
finv = [1, 1]
inv = [0, 1]


def init(n):
    for i in range(2, n):
        fac.append(fac[-1] * i % mod)
        inv.append(-inv[mod % i] * (mod // i) % mod)
        finv.append(finv[-1] * inv[-1] % mod)


def com(n, k, mod):
    if n < 0 or k < 0 or n < k:
        return 0
    return fac[n] * (finv[k] * finv[n - k] % mod) % mod


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

if not (X+Y) % 3 == 0:
    print(0)
else:
    n = (Y - 2 * X) // -3
    m = X - (2 * n)
    if n < 0 or m < 0:
        print(0)
    else:
        init(n + m)
        print(com(n + m, n, mod))

Submission status: Runtime Error

Solution code:
# coding: utf-8
import sys

x, y = map(int, input().split())
if (x + y) % 3 != 0:
    print(0)
    sys.exit()

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

if a < 0 or b < 0:
    print(0)
    sys.exit()

#(a+b)! / a!*b!
def combi(c, num):
    result = 1
    for i in range(num):
        result = (result * (c-i)) % MOD
    return result
    
out = combi(a+b, a) // combi(a, a)

print(out)

Submission status: Runtime Error

Solution code:
# coding: utf-8
import sys

x, y = map(int, input().split())
if (x + y) % 3 != 0:
    print(0)
    sys.exit()

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

if a < 0 or b < 0:
    print(0)
    sys.exit()

#(a+b)! / a!*b!
def combi(c, num):
    result = 1
    for i in range(num):
        result *= (result * (c-i)) % MOD
    return result
    
out = combi(a+b, a) // combi(a, a)

print(out)

Submission status: Runtime Error

Solution code:
a = (x + y) //3
n = (2*x-y)//3
m = a-n
print(n,m)
def nCr(n,r,mod):
    r = min(r, n-r)
    fact = rial=1
    for i in range(1,r+1):
        fact *= (n+1-i) % mod
        rial *= i %mod
    return fact * pow(rial,mod-2,mod) %mod
    
if (x + y) %3 == 0:
    if 0 < n and 0 < m and (x+y)%3==0:
       
        print(nCr(a,n,mod))
        
    else: 
        print(0)
    
else:
    print(0)

Submission status: Runtime Error

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

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 main():
    
    x, y = map(int, readline().split())
    if (x+y)%3!=0:
        print(0)
        return
    n = (x+y)//3
    o = cmb(n, min((2*y-x)//3, (2*x-y)//3))
    o = o % (10**9+7)
    print(o)

if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
    MOD = 10 ** 9 + 7
     
    X, Y = map(int, input().split())
     
    a = (2 * X - Y) // 3
    b = (2 * Y - X) // 3
     
    if not ((2 * X - Y) % 3 == 0 and (2 * Y - X) % 3 == 0 and a >= 0 and b >= 0):
        print(0)
        exit()
     
    maxf = a + b + 1
    f = [1 for _ in range(maxf)]
    invf = [1 for _ in range(maxf)]
     
    for i in range(1, maxf):
        f[i] = (i * f[i - 1]) % MOD
    invf[maxf - 1] = pow(f[maxf - 1], MOD - 2, MOD)
     
    for i in range(maxf - 1, 0, -1):
        invf[i - 1] = (i * invf[i]) % MOD
     
     
    def comb(a, b):
        return (f[a + b] * invf[a] * invf[b]) % MOD
     
     
    print(comb(a, b))

Submission status: Runtime Error

Solution code:
x, y = map(int(), input().split())
# m + 2n = x
# 2m + n = y

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

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

if (-x+2*y>=0) and (2*x-y>=0) and ((-x+2*y)%3==0) and ((2*x-y)%3==0):
  m = (-x+2*y)/3
  n = (2*x-y)/3
  mod = 10**9+7
  res = 1
  for i in range(1,m+n+1):
    res = res*i%mod
  for i in range(1,m+1):
    res = res*mod_inv(i,mod)%mod
  for i in range(1,n+1):
    res = res*mod_inv(i,mod)%mod
  print(res)
else:
  print(0)

Submission status: Runtime Error

Solution code:
import math
import sys

# スペース区切りの整数の入力
X, Y = map(int, input().split())
#X = 999999; Y = 999999

BIGCONST = 10**9 + 7

def COMinit(maxval):
    fac[0]  = fac[1]  = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1
    for i in range(2, maxval+1):
        fac[i]  = fac[i - 1] * i % BIGCONST
        inv[i]  = BIGCONST - inv[BIGCONST%i] * ( BIGCONST // i) % BIGCONST
        finv[i] = finv[i - 1] * inv[i] % BIGCONST
    
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] % BIGCONST) % BIGCONST
    
def calc(X, Y):
    n_bunshi = 2*X - Y
    m_bunshi = 2*Y - X
    
    if n_bunshi % 3 != 0 or n_bunshi < 0:
        return 0, 0
    
    if m_bunshi % 3 != 0 or m_bunshi < 0:
        return 0, 0
    
    n = n_bunshi // 3
    m = m_bunshi // 3
    
    return n, m

n, m = calc(X, Y)

if n == 0 and m == 0:
    print("0")

fac  = [0] * (n+m+1)
finv = [0] * (n+m+1)
inv  = [0] * (n+m+1)
    
COMinit(n+m)
answer = COM(n + m, m)
 
print(answer)

Submission status: Runtime Error

Solution code:
import math
import sys

# スペース区切りの整数の入力
X, Y = map(int, input().split())
#X = 999999; Y = 999999

BIGCONST = 10**9 + 7

def COMinit(maxval):
    fac[0]  = fac[1]  = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1
    for i in range(2, maxval+1):
        fac[i]  = fac[i - 1] * i % BIGCONST
        inv[i]  = BIGCONST - inv[BIGCONST%i] * ( BIGCONST // i) % BIGCONST
        finv[i] = finv[i - 1] * inv[i] % BIGCONST
    
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] % BIGCONST) % BIGCONST
    
def calc(X, Y):
    n_bunshi = 2*X - Y
    m_bunshi = 2*Y - X
    
    if n_bunshi % 3 != 0 or n_bunshi < 0:
        return 0
    
    if m_bunshi % 3 != 0 or m_bunshi < 0:
        return 0
    
    n = n_bunshi // 3
    m = m_bunshi // 3
    
    return n, m

n, m = calc(X, Y)

fac  = [0] * (n+m+1)
finv = [0] * (n+m+1)
inv  = [0] * (n+m+1)
    
COMinit(n+m)
answer = COM(n + m, m)
 
print(answer)

Submission status: Runtime Error

Solution code:
x,y = map(int,input().split())
mod = 10**9 + 7
if (x+y)%3 != 0:
    print(0)
    exit()
n = (x+y)//3
a = (2 * x - y) // 3
b = (2 * y - x) // 3
if a == 0 or b == 0:
    print(1)
    exit()
if a < 0 or b < 0:
    print(0)
    exit()
MAX = 10
fac = [1,1] + [0] * MAX
finv = [1,1] + [0] * MAX
inv = [0,1] + [0] * MAX
for i in range(2,MAX):
    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-1]%mod)%mod

print(nCr(n,a))

Submission status: Runtime Error

Solution code:
x,y = map(int,input().split())
mod = 10**9 + 7
if (x+y)%3 != 0:
    print(0)
    exit()
n = (x+y)//3
a = (2 * x - y) // 3
b = (2 * y - x) // 3
if a == 0 or b == 0:
    print(1)
    exit()
if a < 0 or b < 0:
    print(0)
    exit()
MAX = 10
fac = [1,1] + [0] * MAX     #累積積
finv = [1,1] + [0] * MAX    #modにおける逆元
inv = [0,1] + [0] * MAX     #invの累積積
for i in range(2,MAX):
    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-1]%mod)%mod

print(nCr(n,a))

Submission status: Runtime Error

Solution code:
import sys
from functools import lru_cache

sys.setrecursionlimit(10000)

INF = 10**9+7

@lru_cache(maxsize=1000)
def c(n,k):
    return 1 if (k<=0 or n<=k) else (c(n-1,k-1)+c(n-1,k))%INF

# for i in range(5):
#     print([c(i, j) for j in range(i+1)])

def solver(x, y):
    if (x, y) == (0, 0):
        return 0
    if (x+y)%3 != 0:
        return 0
    k = (x+y)//3
    (xi, yi) = (k, 2*k)
    for i in range(k+1):
        if (xi, yi) == (x, y):
            return c(k, i)
        else:
            (xi, yi) = (xi+1, yi-1)
    return 0

x, y = map(int, input().split())
res = solver(x, y)
print(res)

Submission status: Runtime Error

Solution code:
mod = 10**9 + 7
x,y = map(int,input().split())
dp = [[0]*(y+3) for _ in range(x+3)]
dp[0][0] = 1

for i in range(x+1):
    for j in range(y+1):
        if dp[i][j] >= mod:
            dp[i][j] %= mod
        if dp[i][j] == 0:
            continue
        else:
            if i+2 <= x+1 and j+1 <= y+1:
                dp[i+2][j+1] += dp[i][j]
            if i+1 <= x+1 and j+2 <= y+1:
                dp[i+1][j+2] += dp[i][j]
print(dp[x][y])

Submission status: Runtime Error

Solution code:
import sys
import math
# スペース区切りの整数の入力
X, Y = map(int, input().split())

n = (2*X - Y) / 3

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

m = ( 2*Y - X) / 3
if (2*Y - X) % 3 != 0:
    print("0")
    sys.exit()

bunshi = math.factorial(n+m)
bunbo_n = math.factorial(n)
bunbo_m = math.factorial(m)
constant = 10**9 + 7
print(n,m, constant)
answer0 = bunshi // (bunbo_n * bunbo_m)
answer = answer0 % constant
print(answer)

Submission status: Runtime Error

Solution code:
from math import factorial

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

def nCk(n, k):
   return factorial(n)//(factorial(k) * factorial(n-k))

# n = number of (i+2 j+1)-type moves
# m = number of (i+1, j+2)-type moves
# 2n+1m = X
# 1n+2m=Y

m = (2*Y-X)/3
n = (X-1*m)/2

if not(m.is_integer()) or not (n.is_integer()):
    print("0")
else:
    mod = 10**9 + 7
    print(int(nCk(n+m, n) % mod))

Submission status: Runtime Error

Solution code:
import math
mod = 10**9 + 7
x,y = map(int,input().split())
e = 0
for i in range(x//2 + 1):
    n = x - 2*i
    m = i
    if y == 2*n + m:
        e += 1
        break
if e == 0:
    print("0")
    exit()
a = math.factorial(n+m)
b = math.factorial(n)
c = math.factorial(m) 
print((a/(b*c))%mod)

Submission status: Runtime Error

Solution code:

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

I = J = -1
for i in xrange(X/2+1):
    j = X-2*i
    y = i + 2*j
    if y == Y:
        I = i
        J = j
        break
    
if I == -1:
    print 0
else:
    print np.prod(np.arange(1,I+J+1)) / np.prod(np.arange(1,I+1)) / np.prod(np.arange(1,J+1))

Submission status: Runtime Error

Solution code:
from functools import reduce

def combination(n, r):
    return reduce(lambda x, y: x * y, range(n - r, n + 1)) // reduce(lambda x, y: x * y, range(1, r + 1))
eps = 10**9 + 7

x, y = map(int, input().split())
if (2 * x - y) % 3 != 0 or (2 * y - x) % 3 != 0:
    print(0)
elif 2 * y - x < 0 or 2 * x - y < 0:
    print(0)
else:
    vertical = (2 * y - x) // 3
    horizontal = (2 * x - y) // 3
    total = vertical + horizontal
    print(int(combination(total, horizontal) % eps))

Submission status: Runtime Error

Solution code:
def factrial(n):
    if n == 1:
        return 1
    else:
        return n * factrial(n - 1)

def combination(n, r):
    return factrial(n) // (factrial(n - r) * factrial(r))

x, y = map(int, input().split())
if (2 * x - y) % 3 != 0 or (2 * y - x) % 3 != 0:
    print(0)
# elif 2 * y - x < 0 or 2 * x - y < 0:
#     print(0)
else:
    vertical = (2 * y - x) // 3
    horizontal = (2 * x - y) // 3
    total = vertical + horizontal
    print(combination(total, horizontal))

Submission status: Runtime Error

Solution code:
def factrial(n):
    if n == 1:
        return 1
    else:
        return n * factrial(n - 1)

def combination(n, r):
    return factrial(n) // (factrial(n - r) * factrial(r))

x, y = map(int, input().split())
if (2 * x - y) % 3 != 0 or (2 * y - x) % 3 != 0:
    print(0)
elif 2 * y - x < 0 or 2 * x - y < 0:
    print(0)
else:
    vertical = (2 * y - x) // 3
    horizontal = (2 * x - y) // 3
    total = vertical + horizontal
    print(combination(total, horizontal))

Submission status: Runtime Error

Solution code:
def factrial(n):
    if n == 1:
        return 1
    else:
        return n * factrial(n - 1)

def combination(n, r):
    return factrial(n) // (factrial(n - r) * factrial(r))

x, y = map(int, input().split())
if (x - y) % 3 != 0:
    print(0)
elif 2 * y - x < 0 or 2 * x - y < 0:
    print(0)
else:
    vertical = (2 * y - x) // 3
    horizontal = (2 * x - y) // 3
    total = vertical + horizontal
    print(combination(total, horizontal))

Submission status: Runtime Error

Solution code:
def m(n,r):
    d=1
    c=1
    for i in range(r):
        d*=(n-i)
        c*=(i+1)
    return(int(d/c))

n=[int(i) for i in input().split()]
a=sum(n)
c=max(n)-min(n)
if a%3 != 0:print(0)
elif c!=0 and a/c < 0.5:print(0)
else:
    b=int(a/3)
    if b==1:
        print(1)
    else:
        if c==0:
            c=int(b/2)
        d=m(b,c)
        print(d%(10**9+7))

Submission status: Runtime Error

Solution code:
def m(n,r):
    d=1
    c=1
    for i in range(r):
        d*=(n-i)
        c*=(i+1)
    return(int(d/c))

N,Y= [int(i) for i in input().split()]
a=N+Y
if a%3 != 0:print(0)
else:
    b=int(a/3)
    c=abs(N-Y)
    if b==1:
        print(1)
    else:
        if c==0:
            c=int(b/2)
        d=m(b,c)
        print(d%(10**9+7))

Submission status: Runtime Error

Solution code:
X,Y = map(int,input().split())
flag = 0
A = 0
B = 0
import math
if X == Y:
    if X%3 == 0:
        A = B = X//3
    else:
        flag = 1
else:
    A = (2*Y-X)/3
    B = A + X - Y
    if not A.is_integer():
        flag = 1
    else:
        A,B = int(A),int(B)


if flag == 1:
    print(0)
else:
    ans = math.factorial(A+B)//(math.factorial(A)*math.factorial(B))
    ans = ans%1000000007
    print(ans)

Submission status: Runtime Error

Solution code:
from scipy.special import comb

N,Y= [int(i) for i in input().split()]
a=N+Y
if a%3 != 0:print(0)
else:
    b=int(a/3)
    c=abs(N-Y)
    if b==1:
        print(1)
    elif c==0:
        e=int(b/2)
        print(int(comb(b,e,exact=True))%(10**9+7))
    else:
        print(int(comb(b,c,exact=True))%(10**9+7))

Submission status: Runtime Error

Solution code:
import math
N,Y= [int(i) for i in input().split()]
a=N+Y
if a%3 != 0:print(0)
else:
    b=a/3
    print(int((math.factorial(b)/math.factorial(abs(N-Y)))%(10**9+7)))

Submission status: Runtime Error

Solution code:
import math

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

if a%3 == 0:
  c = x -y
  d = int((x + y - 3*c)/6)
  e = math.factorial(c + 2*d)
  f = math.factorial(d)
  g = math.factorial(c + d)
  h = e/(f*g)
  print(int(h%(10**9+7)))
else:
  print(0)

Submission status: Runtime Error

Solution code:
mod = int(1e9 + 7)
def powmod(a, b):
    ans = 1
    while(b):
        if(b&1): ans = ans*a%mod
        a = a*a%mod
        b >>= 1
    return ans
x, y = map(int,input().split())
if((2*x-y)%3 or (2*y-x)%3): print(0)
else:
    x, y = (2*x-y)//3, (2*y-x)//3
    #print(x,y)
    fac = [0 for i in range(x+y+1)]
    inv = [0 for i in range(x+y+1)]
    fac[0] = 1
    for i in range(1,x+y+1):
        fac[i] = fac[i-1]*i%mod
    inv[x+y] = powmod(fac[x+y],mod-2)
    for i in range(x+y-1,-1,-1):
        inv[i] = inv[i+1]*(i+1)%mod
    ans = fac[x+y]*inv[x]*inv[y]%mod
    print(ans)

Submission status: Runtime Error

Solution code:
X, Y = map(int, input().split())
import math
a = 2*Y -X
b = 2*X -Y
if a % 3 == 0 and b % 3 == 0 and a > 0 and b > 0:
  k = a // 3
  l = b // 3
  c = max(k, l)
  d = min(k, l)
  sita = math.factorial(d)
  ue = 1
  for i in range(c + 1, c + d + 1):
    ue * = i
  total = ue // sita
  print(total % (7 + 10 ** 9))
else:
  print(0)

Submission status: Runtime Error

Solution code:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include <boost/multiprecision/cpp_int.hpp>
//typedef boost::multiprecision::cpp_int ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E17;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
////////////////////////////


#define N 2000004

ll kai[N];
ll kai2[N];
ll po(ll i,ll p){
    if(p==0)return 1;
    else{
        i=mod(i);
        if(p==1)return i;
        if(p%2==0)return po(mod(i*i),p/2);
        return mod(i*po(i,p-1));
    }
}
void calc(){
    kai[0]=1;
    kai2[0]=1;
    rep(i,1,N-1){
        kai[i]=mod(kai[i-1]*i);
    }
    kai2[N-1]=po(kai[N-1],i_5);
    for(ll i=N-2;i>=0;i--){
        kai2[i]=mod(kai2[i+1]*(i+1));
    }
}
ll comb(ll n,ll k){
    if(n<k)return 0;
    if(n==0)return 1;
    return mod(mod(kai[n]*kai2[n-k])*kai2[k]);
}
ll bunbo(ll n){
    return po(n,i_5);
}

int main(){fastio
    
    calc();
    
    ll x,y;cin>>x>>y;
    if((x+y)%3!=0){
        cout<<0<<endl;return 0;
    }
    ll n=(x+y)/3;
    x-=n;
    y-=n;
    if(x<0||y<0){
        cout<<0<<endl;return 0;
    }
    cout<<comb(x+y,x)<<endl;
    
    
    return 0;
}

Submission status: Runtime Error

Solution code:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include <boost/multiprecision/cpp_int.hpp>
//typedef boost::multiprecision::cpp_int ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E17;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
////////////////////////////


#define N 100004

ll kai[N];
ll kai2[N];
ll po(ll i,ll p){
    if(p==0)return 1;
    else{
        i=mod(i);
        if(p==1)return i;
        if(p%2==0)return po(mod(i*i),p/2);
        return mod(i*po(i,p-1));
    }
}
void calc(){
    kai[0]=1;
    kai2[0]=1;
    rep(i,1,N-1){
        kai[i]=mod(kai[i-1]*i);
    }
    kai2[N-1]=po(kai[N-1],i_5);
    for(ll i=N-2;i>=0;i--){
        kai2[i]=mod(kai2[i+1]*(i+1));
    }
}
ll comb(ll n,ll k){
    if(n<k)return 0;
    if(n==0)return 1;
    return mod(mod(kai[n]*kai2[n-k])*kai2[k]);
}
ll bunbo(ll n){
    return po(n,i_5);
}

int main(){fastio
    
    calc();
    
    ll x,y;cin>>x>>y;
    if((x+y)%3!=0){
        cout<<0<<endl;return 0;
    }
    ll n=(x+y)/3;
    x-=n;
    y-=n;
    if(x<0||y<0){
        cout<<0<<endl;return 0;
    }
    cout<<comb(x+y,x)<<endl;
    
    
    return 0;
}

Submission status: Runtime Error

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

mod = 10**9 + 7

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

# def comb(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

def comb_mod(n, r, mod):
    if n < r:
        return 0
    elif n < 0 or r < 0:
        return 0
    else:
        fac = [1, 1]
        finv = [1, 1]
        inv = [0, 1]
        for i in range(2, n + 1):
            fac.append(fac[-1] * i % mod)
            inv.append(-inv[mod % i] * (mod // i) % mod)
            finv.append((finv[-1] * inv[-1]) % mod)
        return int(fac[n] * finv[r] * finv[n - r] % mod)


# def comb(n,r,mod):
# 	'''
# 	return nCr
# 	O(min{n-r, r})
# 	'''
# 	a=1
# 	b=1
# 	r = min(r,n-r)
# 	for i in range(r):
# 		a = a*(n-i)%mod
# 		b = b*(i+1)%mod
# 	return a*pow(b,mod-2,mod)%mod

if (x+y)%3!=0:
    print(0)
    exit()
else:
    n = int((2/3)*x - (1/3)*y)
    m = int((2/3)*y - (1/3)*x)
    if n>=0 and m>=0:
        print(comb(n+m,m,mod))
        exit()
    else:
        print(0)
        exit()