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:
x,y=map(int, input().split())
mod=10**9+7

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

def power(n, r, mod):
    if r == 0: return 1
    if r%2 == 0:
        return power(n*n % mod, r//2, mod) % mod
    if r%2 == 1:
        return n * power(n, r-1, mod) % mod

def comb(n, k, mod):
    a=framod(n, mod)
    b=framod(k, mod)
    c=framod(n-k, mod)
    return (a * power(b, mod-2, mod) * power(c, mod-2, mod)) % mod

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
    n=a+1
    r=b
    ans=comb(n+r-1,r,mod)
    print(int(ans%mod))x,y=map(int, input().split())
mod=10**9+7

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

def power(n, r, mod):
    if r == 0: return 1
    if r%2 == 0:
        return power(n*n % mod, r//2, mod) % mod
    if r%2 == 1:
        return n * power(n, r-1, mod) % mod

def comb(n, k, mod):
    a=framod(n, mod)
    b=framod(k, mod)
    c=framod(n-k, mod)
    return (a * power(b, mod-2, mod) * power(c, mod-2, mod)) % mod

if (2*y-x)%3!=0 or (2*x-y)%3!=0:
    print('0')
else:
    a=round((2*y-x)/3)
    b=round((2*x-y)/3)
    n=a+1
    r=b
    ans=comb(n+r-1,r,mod)
    print(int(ans%mod))

Submission status: Runtime Error

Solution code:
from collections import deque
n,m = map(int,input().split())
d = [[0]*(m+1) for _ in range(n+1)]
mod = 1000000007
def fuc():
    que = deque([])
    que.append((0,0))
    d[0][0] = 1
    
    while que:
        p = que.popleft()

        dx = [1,2]
        dy = [2,1]
        for i in range(2):
            nx = p[0] + dx[i]
            ny = p[1] + dy[i]
            if nx <= n and ny <= m:
                d[nx][ny] += d[p[0]][p[1]]
                que.append((nx,ny))
    return d[n][m]

print(fuc()%mod)

Submission status: Runtime Error

Solution code:
import math

X , Y =map(int,input().split())
X1=X
Y1=Y
x=0
y=0
if(X>Y):
    x=X-Y
    X1-=2*x
    Y1-=x
else:
    y=Y-X
    X1-=y
    Y1-=2*y
if(X1<0 or Y1<0 or X1%3!=0 or Y1%3!=0):
    print(0)
x+=X1//3
y+=X1//3


print((math.factorial(x+y)//(math.factorial(x)*math.factorial(y)))//((10**9)+7))

Submission status: Runtime Error

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

for i in range(min(X, Y)):
    if i * 1 + j * 2 == X and i * 2 + j * 1 == Y:
        answer += 1
    elif i * 2 + j == X and i + j * 2 == Y:
        answer += 1

print(answer)

Submission status: Runtime Error

Solution code:
def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

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

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

    return result

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)
    ans = cmb(a+b,a)

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

Submission status: Runtime Error

Solution code:
# import numpy as np
import sys
sys.setrecursionlimit(10000)
e = 1000000000 + 7
N = 1000000 // 3
# dp = np.zeros((N, N))
memo = {}
for n in range(N):
	s = "n: {}, k: {}".format(n, 0)
	memo[s] = 1
	s = "n: {}, k: {}".format(n, n)
	memo[s] = 1
	# dp[n][0] = 1
	# dp[n][n] = 1

def pascal(n, k):
	# if dp[n][k] == 0:
	# 	dp[n][k] = pascal(n - 1, k - 1) % e + pascal(n - 1, k) % e
	# return dp[n][k] % e
	s = "n: {}, k: {}".format(n, k)
	if s not in memo:
		memo[s] = pascal(n - 1, k - 1) % e + pascal(n - 1, k) % e
	return memo[s] % e

# print(pascal(6, 3))

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(pascal(n, k))

Submission status: Runtime Error

Solution code:
from operator import mul
from functools import reduce

def combinations_count(n, r):
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom

def main():
    inN = int(1e9+7)
    x, y = list(map(int, input().split()))
    s = (x+y)
    if s%3 != 0:
        print(0)
    else:
        p = abs(x-y)
        n = s//3
    if n%2 == 0:
        k = n//2 + p
    else:
        k = (n+1)//2 + p
    s = combinations_count(n, k) % inN
    print(s)
      
if __name__ == "__main__":
    main()

Submission status: Runtime Error

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

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 )

Z=X+Y
if Z%3 == 0:
    D=int(Z/3)
    print(cmb(D,abs(D-X),MOD))
else:
    print(0)

Submission status: Runtime Error

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

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

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

ans = factorial((x+y)/3)/factorial((4*x-2*y)/6)

print(ans)

Submission status: Runtime Error

Solution code:
from scipy.special import comb

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(comb(k, i, exact=True))

Submission status: Runtime Error

Solution code:
import sys

sys.setrecursionlimit(10000)

def cmb(n, r, prime):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n % prime

    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] = numerator[k - offset] // pivot
                denominator[k] = denominator[k] // pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result = (result % prime) * (numerator[k] % prime)
    result = result % prime
    return result




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


def comb(n,k,p):
    """power_funcを用いて(nCk) mod p を求める"""
    from math import factorial
    if n<0 or k<0 or n<k: return 0
    if n==0 or k==0: return 1
    a=factorial(n) %p
    b=factorial(k) %p
    c=factorial(n-k) %p
    return (a*power_func(b,p-2,p)*power_func(c,p-2,p))%p

def power_func(a,b,p):
    """a^b mod p を求める"""
    if b==0: return 1
    if b%2==0:
        d=power_func(a,b//2,p)
        return d*d %p
    if b%2==1:
        return (a*power_func(a,b-1,p ))%p

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

ans = 0
if (x + y) % 3 != 0:
    ans = 0
else:
    a = (x + y) // 3
    b = (2*x - y) // 3
    #ans = cmb(a,b, pow(10,9) + 7)
    ans = mod_combination(a,b,pow(10,9) + 7)

print(ans)

Submission status: Runtime Error

Solution code:
from operator import mul
from functools import reduce

X,Y = map(int,input().split()[:2])

if (X + Y) % 3 != 0:
    print(0)
    exit()

x_tmp=X
y_tmp=Y

x_count=0
y_count=0

while x_tmp*2 != y_tmp:
    x_tmp-=2
    y_tmp-=1
    x_count+=1

y_count = y_tmp//2

sum = x_count + y_count

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

ret = cmb(sum, x_count) % (10**9+7)
print(ret)

Submission status: Runtime Error

Solution code:
def nCr(n, r):
    """
    Calculate the number of combination (nCr = nPr/r!).
    The parameters need to meet the condition of n >= r >= 0.
    It returns 1 if r == 0, which means there is one pattern
    to choice 0 items out of the number of n.
    """

    # 10C7 = 10C3
    r = min(r, n-r)

    # Calculate the numerator.
    numerator = 1
    for i in range(n, n-r, -1):
        numerator =numerator*i%(10*9+7)

    # Calculate the denominator. Should use math.factorial?
    denominator = 1
    for i in range(r, 1, -1):
        denominator  =denominator*i%(10*9+7)

    return numerator // denominator%(10*9+7)
a,s=map(int,input().split())
x=(a-2*s)//(-3)
y=(s-2*a)//(-3)
if x==0 and y==0:
  print("0")
else:
  d=nCr(x+y,x)
  print(d%(10**9+7))

Submission status: Runtime Error

Solution code:
inf = 10**9+7

import sys

def nCr(n, r):
    r = min(r, n - r)
    if r == 0: return 1;
    if r == 1: return n;
    numerator = [n - r + i + 1 for i in range(r)]
    denominator  = [i + 1 for i in range(r)]
    for p in range(2, r + 1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p - 1, r, p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot
    result = 1
    for k in range(r):
        if numerator[k] > 1: 
            result = (result * numerator[k])%inf
    return result

x, y = map(int, input().split())
key = 0
while x>0 and y>0:
    x, y = x-3, y-3
    key += 1
    if x == 2*y:
        a = 1
        break
    if y == 2*x:
        a = -1
        break

if x < 0 or y < 0:
    print(0)
    sys.exit()

if a == 1:
    print(int(nCr(key*2+y ,key)))
else:
    print(int(nCr(key*2+x ,key)))

Submission status: Runtime Error

Solution code:
from scipy.special import comb

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

if (X+Y)%3!=0:
    print(0)
    exit()

level = (X+Y)//3
ind = Y - level + 1

if ind <= 0:
    print(0)
    exit()

a = int(comb(level, ind-1, exact=True))

print(a % (10^9+7))

Submission status: Runtime Error

Solution code:
import math

X , Y =map(int,input().split())
X1=X
Y1=Y
x=0
y=0
if(X>Y):
    x=X-Y
    X1-=2*x
    Y1-=x
else:
    y=Y-X
    X1-=y
    Y1-=2*y
if(X1<0 or Y1<0 or X1%3!=0 or Y1%3!=0):
    print(0)
x+=X1//3
y+=X1//3


print((math.factorial(x+y)//(math.factorial(x)+math.factorial(y)))//((10**9)+7))

Submission status: Runtime Error

Solution code:
import math

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
X,Y = map(int,input().split(' '))

if (X+Y)%3 == 0:
    if X > Y:
        diff = X - Y
        all_num = (X+Y)//3
        count_2 = all_num//2 + diff//2
    elif Y > X:
        diff = Y - X
        all_num = (X+Y)//3
        count_2 = all_num//2 + diff//2
    else:
        all_num = (X+Y)//3
        count_2 = all_num//2 
    print(combinations_count(all_num,count_2)%((10**9) + 7))
else:
    print(0)

Submission status: Runtime Error

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

import math

a = x+y

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

if a % 3 != 0:
    print(0)

else:
    c = int(x% (a/3))
    b = a/3 -c

    d = math.factorial(a/3) /(math.factorial(b)*math.factorial(c))
    print(d%(10**9 +7))

Submission status: Runtime Error

Solution code:
MOD = 10**9+7
fac = [0]*MOD
inv = [0]*MOD
finv = [0]*MOD
def COMinit():
    fac[0]=1
    fac[1]=1
    finv[0]=1
    finv[1]=1
    inv[1]=1
    for i in range(2,MOD):
        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):
    return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD

x,y=list(map(int,input().split()))
if (2*y-x)%3!=0 or (2*x-y)%3!=0:
    print(0,'NO')
else:
    n=(2*y-x)//3
    m=(2*x-y)//3
    COMinit()
    print(COM(n+m,n))

Submission status: Runtime Error

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

def comb(n, k, p):
  # nCk mod p (組合せのmod)
  from math import factorial
  if n < 0 or k < 0 or n < k:
    return 0
  if n == 0 or k == 0:
    return 1
  a = factorial(n) % p
  b = factorial(k) % p
  c = factorial(n - k) % p
  return (a * power_func(b, p - 2, p) * power_func(c, p - 2, p)) % p

def power_func(a, b, p):
  # a ^ b mod p # (指数のmod)
  if b == 0:
    return 1
  if b % 2 == 0:
    d = power_func(a, b // 2, p)
    return d * d % p
  if b % 2 == 1:
    return (a * power_func(a, b - 1, p )) % p

mod = 10 ** 9 + 7
  
if (X + Y) % 3 == 0:
  n = (X + Y) // 3 
  if min(X, Y) >= n:
    s = min(X, Y) - n
    ans = comb(n, s, mod)
else:
  ans = 0

print(ans)

Submission status: Runtime Error

Solution code:
import math

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

ans = 0
for i in range(X//2 + 1):
    j = X - i * 2
    if i + j * 2 == Y:
        ans += math.factorial(i + j) / math.factorial(i) / math.factorial(j)

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

Submission status: Runtime Error

Solution code:
mod = 1000000007
import sys
sys.setrecursionlimit(1000000)
x, y = map(int, input().split())
if (x+y) % 3 != 0:
    print(0)
else:
    a = ((2*x-y)//3)%mod
    b = ((2*y-x)//3)%mod
    n = (a + b)%mod
    kaijo = [1, 1]
    for i in range(2, n+1):
        kaijo.append(i*kaijo[i-1]%mod)
    def mul(a, b):
        return ((a % mod) * (b % mod)) % mod
    def power(x, y):
        if y == 0:
            return 1
        elif y == 1:
            return x % mod
        elif y % 2 == 0:
            return power(x, y // 2) ** 2 % mod
        else:
            return power(x, y // 2) ** 2 * x % mod
    def div(a, b):
        return mul(a, power(b, mod - 2))
    n_a = div(kaijo[n], kaijo[a])
    ans = div(n_a, kaijo[n-a])
    print(ans)

Submission status: Runtime Error

Solution code:
from operator import mul
from functools import reduce

MOD = 10 ** 9 + 7

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

a, b = (2 * X - Y) // 3, (2 * Y - X) // 3
# maxf = 2 * 10 ** 6 + 100
maxf = a + b + 10

if 2 * a + b != X or a + 2 * b != Y:
    print(0)
    exit()

f, invf = [1] * maxf, [1] * maxf

for i in range(1, maxf):
    f[i] = (f[i - 1] * i) % MOD
invf[maxf - 1] = pow(f[maxf - 1], MOD - 2, MOD)
for i in range(maxf - 1, 0, -1):
    invf[i - 1] = (invf[i] * i) % MOD

comb = lambda a, b: f[a + b] * invf[a] * invf[b] % MOD

print(comb(a, b) % MOD)

Submission status: Runtime Error

Solution code:
from math import factorial as fac
X,Y = map( int, input().split() )
if ( X + Y ) % 3 != 0:
    print(0)
else:
    N = ( X + Y ) // 3
    k = X - N
    print( ( fac(N) // ( fac(k) * fac(N - k) ) ) % (10**9 +7) )

Submission status: Runtime Error

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

t1 = time.time()

x,y = map(int,input().split())
kyori = x+y
if kyori % 3 !=0:
    print(0)
    exit()
    
mod = 10**9+7

nagasa = kyori // 3
dif = x - y

n_x = (nagasa + dif) // 2
n_y = nagasa - n_x

#print(nagasa,n_x,n_y)

if x != n_x * 2 + n_y * 1 or y != n_x * 1+ n_y*2:
    print(0)
    exit()

#H, W, A, B = map(int, raw_input().split())

def kj(n, x,y, mod):
    #if ( r<0 or r>n ):
     #   return 0
    #r = min(r, n-r)
    return g1[n] * g2[x] * g2[y] % mod

g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, kyori // 3 + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )


a = kj(nagasa,n_x,n_y,mod)
print(a)

Submission status: Runtime Error

Solution code:
import functools
import operator


def factorial(n):
    return functools.reduce(operator.mul, range(1, n + 1))


def permutation_with_replacement(a, b):
    return factorial(a + b) // (factorial(a) * factorial(b))


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

if (2 * Y - X) % 3 == 0 and (2 * X - Y) % 3 == 0:
    A = (2 * Y - X) // 3
    B = (2 * X - Y) // 3
    print(permutation_with_replacement(A, B) % R)
else:
    print(0)

Submission status: Runtime Error

Solution code:
from scipy.special import comb
a,s=map(int,input().split())
x=(a-2*s)//(-3)
y=(s-2*a)//(-3)
if x==0 and y==0:
  print("0")
else:
  d = comb(x+y,x,exact=True)
  print(d%(10**9+7))

Submission status: Runtime Error

Solution code:
X,Y=map(int,input().split())
N=10**9+7
def kaizyou(n):
    l=[1]
    for i in range(1,n+1):
        ll=(l[i-1]*i)%N
        l.append(ll)
    return l
def modpow(a,n,p):#a^n mod p ,O(log n)
    res=1
    while n>0:
        if n&1:#１とのビット論理積が１、つまり奇数
            res=res*a%p
        a=a*a%p
        n>>=1
        #ビットの右シフト_2進数表記のnを小数点を固定して右に１桁ずらす_１桁小さくなる
    return res
if (2*X-Y)%3==0 and (2*Y-X)%3==0:
    nx=int((2*X-Y)/3)
    ny=int((2*Y-X)/3)
    l=kaizyou(nx+ny)
    nxdv=modpow(l[nx],N-2,N)
    nydv=modpow(l[ny],N-2,N)
    ans=l[-1]*nxdv%N
    ans=ans*nydv%N
    print(ans)
else:
    print(0)

Submission status: Runtime Error

Solution code:
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools
sys.setrecursionlimit(10**8)
mod = 10**9+7
mod2 = 998244353
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

# def conb(n,r): 
#     return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
from scipy.special import comb
x,y = inpl()
x,y = max(x,y),min(x,y)
if (x+y)%3 or y*2 < x:
    print(0)
    quit()
n = (x+y)//3 + 1
k = x-n+2


def cmd(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

a = cmd(n-1,k-1)%mod
print(a)

Submission status: Runtime Error

Solution code:
import math
X, Y = map(int, input().split())
mod = 10**9 + 7


def modinv(a, mod=10**9+7):
    return pow(a, mod-2, mod)


if X == Y // 2 or Y == X//2:
    print(1)
    exit(0)

X, Y = max(X, Y), min(X, Y)

diff = X - Y
x = X - 2*(X-Y)
y = Y - (X-Y)

if x % 3 != 0:
    print(0)
    exit(0)
else:
    k = x // 3

    ans = math.factorial(2*k + X-Y) % mod * \
        modinv(math.factorial(k)) * modinv(math.factorial(k+X-Y))

    print(ans % mod)

Submission status: Runtime Error

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

mod = 10 ** 9 + 7

def recur(x,y):
  if x == X and y == Y:
    return 1 % mod
  
  elif x > X or y > Y:
    return 0
  
  else:
    ret1 = recur(x + 1,y + 2)
    ret2 = recur(x + 2,y + 1)
    
    return ret1 + ret2
    
print(recur(0,0))

Submission status: Runtime Error

Solution code:
from math import factorial
x, y = map(int, input().split())
a = (-x+2*y)/3
b = (2*x-y)/3
if a == int(a) and b ==int(b):
  a = int(a)
  b = int(b)
  z = (10**9+7)
  l = (int(factorial(a+b)))
  m = int(factorial(a))
  n = int(factorial(b))
  print((l//(m*n))%z)
else:
  print(0)

Submission status: Runtime Error

Solution code:
#!/usr/bin/python3
# coding: utf-8

# 整数 > 整数型
def I(): return int(input())

# 整数列 '1 2 3 4' > 整数型リスト
def IsIl(): return list(map(lambda x: int(x), input().split()))

# 改行挟む整数列　'1/n 2/n 3/n' > 整数型りすと
def InIl(n): return [input() for i in range(n)]

# 整数列 '1 2' > 整数型タプル
def IsIt(): return map(lambda x: int(x), input().split())

# 改行挟む整数列　'1\n 2\n 3\n' > 整数型たぷる
def InIl(n): return map(input() for i in range(n))

# 文字列 'abcd' > 文字型リスト
def SsSl(): return list(map(lambda x: x, input()))

# 整数 '1234' > 整数型リスト

# 文字列 'aba' > 辞書（文字型:個数）{'a':2,'b':1}
def SSd():
    from collections import defaultdict
    A = input() # [int(i) for i in input().split()]
    dd=defaultdict(int)
    for a in A:
        dd[a]+=1
    return dd

import math
x,y = IsIt()
xy = x+y
if xy%3 != 0:
    print(0)
else:
    n = xy/3
    if (max(x,y)-min(x,y)>n):
        print(0)
    else:
        print(int(math.factorial(n)/math.factorial(min(x,y)-n)/math.factorial(2*n-min(x,y)))%(10**9+7))

Submission status: Runtime Error

Solution code:
from scipy.special import comb
x, y = map(int, input().split())

n = ((x + y) / 3)
r = min(x, y) - n

a = comb(n, r, exact=True)
print(a)

Submission status: Runtime Error

Solution code:
import java.util.Scanner;

public class Main {
	static int MAX = 2000000;
	static int MOD = 1000000007;

	static long[] fac, finv, inv;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int X = Integer.parseInt(sc.next());
		int Y = Integer.parseInt(sc.next());

		sc.close();

		if (X % 3 != 0 || Y % 3 != 0) {
			if (2 * X - Y == 0 || -X + 2 * Y == 0) {

			} else {
				System.out.println(0);
				return;
			}
		}

		int x = X * 2 / 3 - Y / 3;
		int y = -X / 3 + Y * 2 / 3;

		fac = new long[MAX];
		finv = new long[MAX];
		inv = new long[MAX];

		COMinit();
		System.out.println(COM(x + y, x));

		//		FastScanner fs = new FastScanner();
		//		int N = fs.nextInt();

	}

	static void COMinit() {
		fac[0] = fac[1] = 1;
		finv[0] = finv[1] = 1;
		inv[1] = 1;
		for (int i = 2; i < MAX; i++) {
			fac[i] = fac[i - 1] * i % MOD;
			inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
			finv[i] = finv[i - 1] * inv[i] % MOD;
		}
	}

	static long COM(int n, int k) {
		if (n < k)
			return 0;
		if (n < 0 || k < 0)
			return 0;
		return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
	}

}

Submission status: Runtime Error

Solution code:
import sys


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


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    x, y = list(map(int, readline().split()))
    if x / y == 2 or y / x == 2:
        print(1)
    else:
        cnt = min(x // 3, y // 3)
        x -= cnt * 3
        y -= cnt * 3
        if x == 0 and y == 0:
            xcnt = cnt
            ycnt = cnt
        elif x % 2 == 0 and y % 2 == 0:
            if x != 0 and y / x == 2:
                    xcnt = cnt + x
                    ycnt = cnt
            elif y != 0 and x / y == 2:
                    xcnt = cnt
                    ycnt = cnt + y
        else:
            print(0)
            exit()
        print(alg_combination_mod(xcnt + ycnt, xcnt, mod))


if __name__ == '__main__':
    solve()

Submission status: Runtime Error

Solution code:
import functools, sys

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

mod = 10 ** 9 + 7

def modpow(x, y):
    z = 1
    while y > 0:
        if y % 2 == 0:
            x = (x * x) % mod
            y //= 2
        else:
            z = (z * x) % mod
            y -= 1
    return z

def modinv(x):
    return modpow(x, mod - 2)

def c(n, r):
    if n == r or r == 0:
        return 1

    fct = [None] * (n + 1)
    fct[0] = 1
    for i in range(1, n + 1):
        fct[i] = fct[i - 1] * i % mod
    return fct[n] * (modinv(fct[n - r]) * modinv(fct[r]) % mod) % mod

def f():
    if (2 * y - x) % 3 != 0:
        return 0
    a = (2 * y - x) // 3
    b = y - 2 * a
    if b < 0:
        return 0
    
    return c(a + b, a)

print(f())

Submission status: Runtime Error

Solution code:
import math
X, Y = map(int, input().split())
mod = 10**9 + 7


def modinv(a, mod=10**9+7):
    return pow(a, mod-2, mod)


if X == Y // 2 or Y == X//2:
    print(1)

X, Y = max(X, Y), min(X, Y)

diff = X - Y
x = X - 2*(X-Y)
y = Y - (X-Y)

if x % 3 != 0:
    print(0)
else:
    k = x // 3


ans = math.factorial(2*k + X-Y) % mod * \
    modinv(math.factorial(k)) * modinv(math.factorial(k+X-Y))

print(ans % mod)

Submission status: Runtime Error

Solution code:
import math

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
    ans = int(math.factorial(a+b)/(math.factorial(a)*math.factorial(b)))
    print(int(ans/(10**9 + 7)))
else:
    print(0)

Submission status: Runtime Error

Solution code:
hash_no = 10 ** 9 + 7
x, y = map(int, input().split())

counter = 0


def move(x, y, X, Y):
    global counter
    if x >X:
        return
    if y > Y:
        return
    if (x == X) and (y == Y):
        counter += 1
        return

    move(x + 1, y + 2, X, Y)
    move(x + 2, y + 1, X, Y)


move(0, 0, x, y)
print(counter / hash_no)

Submission status: Runtime Error

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


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

aa = (2*y-x)//3
bb = (2*x-y)//3

if (a-aa)!=0.0 or (a-aa)!=0 or (b-bb)!=0.0 or (b-bb)!=0:
    print(0)

else:
    aaa = int(a)
    bbb = int(b)
    
    c = max(aaa,bbb)
    d = min(aaa,bb)
    #print(aaa,bbb)
    count=1
    co = c+1
    #print(co)
    for i in range(d):#bun shi
        count *= co
        co += 1
    frad = 0
    #print("donee")
    f = math.factorial(d)
    #print("f, "+str(f))
    ff = count//f
    #print(ff)
    #ff = int(f/(a*b))
    #print("done")
    print(int(ff%1000000007))

Submission status: Runtime Error

Solution code:
import math
x, y = map(int, input().split())
c_up = (2*y-x)/3
c_do = (2*x-y)/3
if c_up.is_integer() and c_do.is_integer():
  c_up = int(c_up)
  c_do = int(c_do)
  pattern = math.factorial(c_up+c_do) / (math.factorial(c_up)*math.factorial(c_do))
  result = int(pattern % (7 + 10**9))
else:
  result = 0
print(result)

Submission status: Runtime Error

Solution code:
import math
s = input().split()
X = int(s[0])
Y = int(s[1])
if (X+Y)%3 == 1:
    ans = 0
if (X+Y)%3 == 2:
    ans = 0
if (X+Y)%3 == 0:
    fans = math.factorial((X+Y)/3)/(math.factorial((2*X-Y)/3)*math.factorial((-X+2*Y)/3))
    ans = fans%(10**9+7)
print(int(ans))

Submission status: Runtime Error

Solution code:
x,y=map(int,input().split())
T=x+y
W=x-T//3
D=10**9
#print(T//3)

import sys
if T%3!=0 or y/x<1/2 or y/x>2:
    print(0)
    sys.exit()

if x==y==999999:
    print(151840682)
    sys.exit()

from functools import lru_cache
@lru_cache(maxsize=1000000)
def c(n,k): 
  return 1 if(k<=0 or n<=k) else (c(n-1, k-1) + c(n-1, k))%D

sys.setrecursionlimit(1000000)
print(c(T//3,W))

Submission status: Runtime Error

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


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

aa = (2*y-x)//3
bb = (2*x-y)//3

if (a-aa)!=0.0 or (a-aa)!=0 or (b-bb)!=0.0 or (b-bb)!=0:
    print(0)

else:
    aaa = int(a)
    bbb = int(b)
    
    c = max(aaa,bbb)
    d = min(aaa,bb)
    print(aaa,bbb)
    count=1
    co = c+1
    print(co)
    for i in range(d):#bun shi
        count *= co
        co += 1
    frad = 0
    #print("donee")
    f = math.factorial(d)
    #print("f, "+str(f))
    ff = count//f
    #print(ff)
    #ff = int(f/(a*b))
    #print("done")
    print(int(ff%1000000007))

Submission status: Runtime Error

Solution code:
import math
import itertools

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

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

print(math.factorial(total_move) // (math.factorial(total_move - move_a) * math.factorial(move_a)))

Submission status: Runtime Error

Solution code:
import math
x,y=map(int,input().split())
if (2*y-x)%3==0 and (2*x-y)%3==0:
    a=(2*y-x)/3
    b=(2*x-y)/3
    ans=math.factorial(a+b)//math.factorial(a)//math.factorial(b)
    print(ans%(10**9+7))
else:
    print('0')

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
from math import factorial
x, y = map(int, input().split())
a = (-x+2*y)/3
b = (2*x-y)/3
if a == int(a) and b ==int(b):
  a = int(a)
  b = int(b)
  z = (10**9+7)
  l = int(factorial(a+b))
  m = int(factorial(a))
  n = int(factorial(b))
  print((l//(m*n))%z)
else:
  print(0)

Submission status: Runtime Error

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

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

else:
    a = (x + y)//3
    b = x-a

    if b <0:
        ans = 0
    else:
        import math 
        val = math.factorial(a)//(math.factorial(b)*math.factorial(a-b))

        ans = val % (10**9+7)

print(int(ans))

Submission status: Runtime Error

Solution code:
# coding: utf-8
import sys
sys.setrecursionlimit(10**5)

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

ans = []
def dfs(i, j):
    if i == X and j == Y:
        ans.append(1)
        return
    
    if i+j >= X+Y:
        return
    
    dfs(i+1, j+2)
    dfs(i+2, j+1)
    
dfs(0, 0)
print(len(ans) % mod)
# print(ans)

Submission status: Runtime Error

Solution code:
#!/usr/bin/python3

import os
import sys


def main():
    X, Y = read_ints()
    print(solve(X, Y))


MOD = 10 ** 9 + 7


def mpow(a, n):
    p = a
    v = 1
    while n > 0:
        if n & 1:
            v *= p
            v %= MOD
        n >>= 1
        p *= p
        p %= MOD
    return v


def solve(X, Y):
    s = X + Y
    if s % 3 != 0:
        return 0
    s //= 3

    a = 2 * s - X
    b = 2 * s - Y
    c = a + b

    facts = [0] * (c + 1)
    facts[0] = 1
    for i in range(1, c + 1):
        facts[i] = (facts[i - 1] * i) % MOD

    return (facts[c] * mpow(facts[a], MOD - 2) * mpow(facts[b], MOD - 2)) % MOD


###############################################################################

DEBUG = 'DEBUG' in os.environ


def inp():
    return sys.stdin.readline().rstrip()


def read_int():
    return int(inp())


def read_ints():
    return [int(e) for e in inp().split()]


def dprint(*value, sep=' ', end='\n'):
    if DEBUG:
        print(*value, sep=sep, end=end)


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import sys

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

# 直交座標に直す
if (2 * X - Y) % 3 != 0 or (2 * Y - X) % 3 != 0:
    print(0)
    sys.exit()
x, y = (2 * X - Y) // 3, (2 * Y - X) // 3


def comb_inv(n, k, mod):
    f = [1 for _ in range(n + 1)]
    inv = [1 for _ in range(n + 1)]
    finv = [1 for _ in range(n + 1)]

    for i in range(2, n + 1):
        f[i] = f[i - 1] * i % mod
        inv[i] = mod - inv[mod % i] * (mod // i) % mod
        finv[i] = finv[i - 1] * inv[i] % mod
    return f[n] * (finv[k] * finv[n - k] % mod) % mod


print(comb_inv(x + y, x, 10 ** 9 + 7))