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:
import subprocess
import os
import time


import sys
import math
from copy import deepcopy
from collections import deque, defaultdict
from operator import mul
from functools import reduce
sys.setrecursionlimit(20000000)

input = sys.stdin.readline


mod = 10**9+7
N = 10**6
g1 = [1, 1]
g2 = [1, 1]
inverse = [0, 1]


# def find_n(x, y):
#     moves = int((x+y)/3)
#     for n in range(moves+1):
#         if n + (moves-n)*2 == x and n*2 + (moves-n) == y:
#             return n % mod, (moves-n) % mod


# def cmb(n, r):
#     return math.factorial(n) % mod // ((math.factorial(r) % mod) * (math.factorial(n-r) % mod))


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


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

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

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

    # n, m = find_n(x, y)

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

    ans = cmb(n+m, min([n, m]))

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Runtime Error

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

def cmb(x, y, mod):
    a = math.factorial(x)
    b = math.factorial(y)

    #Fermat小定理
    p = pow(a, mod-2, mod)
    q = pow(b, mod-2, mod)
    return (p * q) % mod 

if (X + Y) % 3 != 0:
    ans = 0
else:
    mod = 10 ** 9 + 7
    m = (X + Y) // 3 #動かした回数
    d = X - m # m回とも1進むことにすると，あぶれた回数が2進む回数と一致する

    t = cmb(m-d, d, mod)
    n = math.factorial(m)
    ans = (n * t) % mod 

print(ans)

Submission status: Runtime Error

Solution code:
from numpy.linalg import solve
import math

a, b = map(int, input().split())
print(a, b)

left = [[1, 2],
        [2, 1]]

right = [a, b]

x, y = solve(left, right)

if not x % 1 == 0 and not y % 1 == 0:
    print(0)

else:
    #answer = (x+y)! / x! * y!
    fac_xy = int(math.factorial(x+y))
    fac_x = int(math.factorial(x))
    fac_y = int(math.factorial(y))
    answer = int((fac_xy / fac_x * fac_y) % (10**9 + 7))
    
    print(answer)

Submission status: Runtime Error

Solution code:
import subprocess
import os
import time


import sys
import math
from copy import deepcopy
from collections import deque, defaultdict
from operator import mul
from functools import reduce
sys.setrecursionlimit(20000000)

input = sys.stdin.readline


mod = 10**9+7
N = 10**6
g1 = [1, 1]
g2 = [1, 1]
inverse = [0, 1]


def find_n(x, y):
    moves = int((x+y)/3)
    for n in range(moves+1):
        if n + (moves-n)*2 == x and n*2 + (moves-n) == y:
            return n, moves-n


# def cmb(n, r):
#     return math.factorial(n) % mod // ((math.factorial(r) % mod) * (math.factorial(n-r) % mod))


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


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

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

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

    n, m = find_n(x, y)

    ans = cmb(n+m, min([n, m]))

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
def cmb(n, k, mod, fac, ifac):
    """
    nCkを計算する
    """
    k = min(k, n-k)
    return fac[n] * ifac[k] * ifac[n-k] % mod


def make_tables(mod, n):
    """
    階乗テーブル、逆元の階乗テーブルを作成する
    """
    fac = [1, 1] # 階乗テーブル・・・(1)
    ifac = [1, 1] #逆元の階乗テーブル・・・(2)
    inverse = [0, 1] #逆元テーブル・・・(3)
    
    for i in range(2, n+1):
        fac.append((fac[-1] * i) % mod)
        inverse.append((-inverse[mod % i] * (mod//i)) % mod)
        ifac.append((ifac[-1] * inverse[-1]) % mod)
    return fac, ifac


X, Y = map(int, input().split())
# 後の、n, mの大小を一定にするため
if X > Y:
    X, Y = Y, X
dist = X + Y
   
if dist % 3 != 0:
    print(0)
else:
    # (+1,+2) の移動の回数を n、(+2,+1) の移動の回数を m とする)
    # total = n + m
    # 以下の式は、2n + m = X, n + 2m = Y の連立方程式を解いた結果
    total = int((X+Y) / 3)
    n = X - total
    
    # n < 0 もしくは m < 0 の場合、たどり着けない
    # Y > X なので、m > n
    # n < 0 → 2X - Y < 0
    if Y > 2*X:
        print(0)
    else:
        MOD = 10**9 + 7

        fac, ifac = make_tables(MOD, total)
        ans = cmb(total, n, mod, fac, ifac)
        print(ans)

Submission status: Runtime Error

Solution code:
import subprocess
import os
import time


import sys
import math
from copy import deepcopy
from collections import deque, defaultdict
from operator import mul
from functools import reduce
sys.setrecursionlimit(20000000)

input = sys.stdin.readline


def find_n(x, y):
    moves = int((x+y)/3)
    for n in range(moves+1):
        if n + (moves-n)*2 == x and n*2 + (moves-n) == y:
            return n, moves-n


def cmb(n, m):
    return math.factorial(n+m) // (math.factorial(n+m - n) * math.factorial(n))


def main():
    x, y = map(int, input().split())

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

    n, m = find_n(x, y)

    ans = cmb(min([n, m]), max([n, m]))

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


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
def main():
    X, Y = (int(i) for i in input().split())
    fac = [0] * max(X, Y)
    finv = [0] * max(X, Y)
    inv = [0] * max(X, Y)
    MOD = (10**9) + 7

    def COMinit(m):
        fac[0] = 1
        fac[1] = 1
        finv[0] = 1
        finv[1] = 1
        inv[1] = 1
        for i in range(2, m):
            fac[i] = fac[i-1] * i % MOD
            inv[i] = MOD - inv[MOD % i] * (MOD // i) % MOD
            finv[i] = finv[i - 1] * inv[i] % MOD

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

    COMinit(max(X, Y))
    if (X+Y) % 3 != 0:
        return print(0)
    n = (2*Y - X) // 3
    m = (2*X - Y) // 3
    print(COM(n+m, m))


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import numpy as np
import math
import scipy
print(scipy.__version__)
from scipy.misc import comb

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

A = np.array([[2,-1],[-1, 2]])
x, y = A.dot(np.array([X,Y]))/3

#print(x, y)
#print(x < 0, y < 0, int(x)!=x, int(y)!=y)
if x < 0 or y < 0 or int(x)!=x or int(y)!=y: # minus or float
  print(0)
else:
  # num of combination
  print(comb(int(x+y), int(x), exact=True)&(1e+9+7))

Submission status: Runtime Error

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

dist = X + Y

def cmb(n, k, mod, fac, ifac):
    """
    nCkを計算する
    """
    k = min(k, n-k)
    return fac[n] * ifac[k] * ifac[n-k] % mod

if dist % 3 != 0:
    print(0)
else:
    # (+1,+2) の移動の回数を n、(+2,+1) の移動の回数を m とする)
    # total = n + m
    total = int((X+Y) / 3)
    n = total - Y 
    
    mod = 10**9+7 
    fac = [1, 1] # 階乗テーブル・・・(1)
    ifac = [1, 1] #逆元の階乗テーブル・・・(2)
    inverse = [0, 1] #逆元テーブル・・・(3)
    
    for i in range( 2, total + 1 ):
        fac.append( ( fac[-1] * i ) % mod )
        inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
        ifac.append( (ifac[-1] * inverse[-1]) % mod )
    
    ans = cmb(total, n, mod, fac, ifac)
    print(ans)

Submission status: Runtime Error

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

x,y=map(int,input().split())
if (x+y)%3!=0:
  print(0)
else:
  a=int((2*x-y)/3)
  b=int((2*y-x)/3)
  if a>=0 and b>=0:
    print(cmb(a+b,b)%(10**9+7))
  else:
    print(0)

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=map(int,input().split())
if (x+y)%3!=0:
  print(0)
else:
  a=int((2*x-y)/3)
  b=int((2*y-x)/3)
  if a>=0 and b>=0:
    print(cmb(a+b,b,mod))
  else:
    print(0)

Submission status: Runtime Error

Solution code:
n,m = int(input())
a = 1

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

Submission status: Runtime Error

Solution code:
x,y=map(int,input().split())
a=min(x,y)-abs(x-y)

from math import factorial
def c(n,r):
  a = factorial(n) / factorial(r) / factorial(n - r)
  return a
if a%3!=0:
  print(-1)
else:
  p=(a//3)*2
  q=p+a
  print(c(p,q))

Submission status: Runtime Error

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

x, y = map(int, input().split())
mod = 10 * 9 + 7
m = (x * 2 - y) / 3
n = x - 2 * m
if (x + y) % 3:
    ans = 0
else:
    ans = factorial(m + n) / factorial(n) / factorial(m)% mod

print(int(ans))

Submission status: Runtime Error

Solution code:
from scipy.special import comb

x, y = map(int, input().split())
mod = 10 * 9 + 7
m = (x * 2 - y) / 3
n = x - 2 * m
if (x + y) % 3:
    ans = 0
else:
    ans = comb(m + n, n, exact=True) % mod

print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
M = 10 ** 9 + 7

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

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

if a > 0 && b > 0 a % 3 ==  0 && b % 3 == 0:
	counter += 1

result = counter % M
print(result)

Submission status: Runtime Error

Solution code:
import math
import numpy as np 

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

mod = 10**9+7 #出力の制限
N = 10**6
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

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


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

Submission status: Runtime Error

Solution code:
def C(n,k):
    if k in (0, n):
        return 1
    else:
        return C(n-1, k-1)%(10**9+7) + C(n-1, k)%(10**9+7)

[X, Y] = [int(i) for i in input().split()]

div = 10**9 + 7

kouho = []

for i in range(1, int(X/2) + 1):
    if  Y == i + 2*(X-2*i):
        kouho.append([i, X-2*i])
    
ans = 0

for v in kouho:
    ans += C(sum(v), v[1])

print(ans)

Submission status: Runtime Error

Solution code:
from math import factorial
X, Y = map(int,input().split())
if (X+Y)%3!=0:
    print(0)
else:
    itr=(X+Y)//3
    x_mx=itr*2
    flag=0
    ir=-1
    for i in range(itr,x_mx+1,1):
        ir+=1
        if X==i and Y==x_mx-ir:
            flag=1
            break
    print(flag)
    if flag==1:
        g=factorial(itr)/factorial(ir) / factorial(itr-ir)
        print(int(g%(10**9+7)))
    elif flag==0:
        print(0)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
import math

def mod_factorial(n):
    mod = 10**9+7

    if n < 1:
        return 1

    r = n
    for i in range(n-1):
        r = r*(i+1) % mod
    
    return r

def mod_pow(n,m):

    mod = 10**9+7
    r = 1

    while m > 0:
        if m & 1:
            r = r*n % mod
        n = n * n % mod
        m = m>>1

    return(r)



def mod_comb(n, k):
    mod = 10**9+7

    if n+k < 1:
        return 1
    
    a = mod_factorial(n)
    b = mod_pow(mod_factorial(k), mod-2)
    c = mod_pow(mod_factorial(n-k), mod-2)


    return (a * ((b * c) % mod)) % mod


a, b= map(int, input().split())

t = [a,b]

r = 0
mod = 10**9+7

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

if (x%3 == 0 and y%3 == 0) and (x > 0 and y > 0):
    m = int(x/3)
    n = int((y/3)

    r += mod_comb(n+m,m)

print(r)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
mod = 10**9+7

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

if (X + Y) % 3 != 0:
    ans = 0
else:
    n = (X + Y) // 3
    r = X - n
    # nCr
    fact = [1, 1]
    for i in range(2, n+1):
        fact.append(fact[-1] * i % mod)
    ans = fact[n]*pow(fact[r], mod-2, mod)*pow(fact[n-r], mod-2, mod) % mod

print(ans)

Submission status: Runtime Error

Solution code:
from operator import mul
from functools import reduce

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

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

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

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

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

Submission status: Runtime Error

Solution code:
import numpy as np
import math
 

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

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

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

Submission status: Runtime Error

Solution code:
import math
import sys
sys.setrecursionlimit(100000)

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

if (X + Y) % 3 != 0:
    print(0)
else:
    N_r = int((2*X-Y) / 3)
    N_u = int((2*Y-X) / 3)

    if N_u < 0 or N_r < 0:
        print(0)
    if N_u == 0 or N_r == 0:
        print(1)
    else:


        mod = 1000000007
        ans = 0

        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 mul(a, b):
            return ((a % mod) * (b % mod)) % mod

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


        factorial = [1]
        for n in range(N_r + N_u-1):
            factorial.append(factorial[n]*(n+2)%mod)

        inverse_factorial = [0] * (N_u + N_r)
        inverse_factorial[-1] = power(factorial[-1], mod-2)

        for n in range(N_u+N_r-2, -1, -1):
            inverse_factorial[n] = (inverse_factorial[n+1] * (n+2)) % mod

        def combi(n, m):
            return factorial[n-1] * inverse_factorial[m-1] * inverse_factorial[n-m-1] % mod

        print(int(combi(N_u+N_r, N_u)))

Submission status: Runtime Error

Solution code:
import math
import sys
sys.setrecursionlimit(10000)

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

if (X + Y) % 3 != 0:
    print(0)
else:
    N_r = int((2*X-Y) / 3)
    N_u = int((2*Y-X) / 3)

    if N_u < 0 or N_r < 0:
        print(0)
    if N_u == 0 or N_r == 0:
        print(1)
    else:


        mod = 1000000007
        ans = 0

        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 mul(a, b):
            return ((a % mod) * (b % mod)) % mod

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


        factorial = [1]
        for n in range(N_r + N_u-1):
            factorial.append(factorial[n]*(n+2)%mod)

        inverse_factorial = [0] * (N_u + N_r)
        inverse_factorial[-1] = power(factorial[-1], mod-2)

        for n in range(N_u+N_r-2, -1, -1):
            inverse_factorial[n] = (inverse_factorial[n+1] * (n+2)) % mod

        def combi(n, m):
            return factorial[n-1] * inverse_factorial[m-1] * inverse_factorial[n-m-1] % mod

        print(int(combi(N_u+N_r, N_u)))

Submission status: Runtime Error

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

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

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

Submission status: Runtime Error

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

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


def combination(n, r, mod=10 ** 9 + 7):
    n1, r = n + 1, min(r, n - r)
    numer = denom = 1
    for i in range(1, r + 1):
        numer = numer * (n1 - i) % mod
        denom = denom * i % mod
    return numer * pow(denom, mod - 2, mod) % mod


X, Y = map(int, input().split())
if (X + Y) % 3 != 0 or not (X <= 2 * Y and Y <= 2 * X):
    print(0)
    exit()

n = (X + Y) // 3
r = Y - n
print(combination(n, r))


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

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


def chker(x, y):
    if (x + y) % 3 != 0 or x > 2 * y or y > 2 * x:
        print(0)
        return

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

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

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

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

    print(nCk(u, d1))


chker(_x, _y)

Submission status: Runtime Error

Solution code:
import numpy as np
import math
 

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

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

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

Submission status: Runtime Error

Solution code:
import numpy as np
import math
 

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

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

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

Submission status: Runtime Error

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

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


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


def combination(n, r, mod=10**9 + 7):
    r = min(r, n - r)
    res = 1
    for i in range(r):
        res = res * (n - i) * modinv(i + 1, mod) % mod
    return res


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

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

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

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

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

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


chker(_x, _y)

Submission status: Runtime Error

Solution code:
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<n; ++i)
#define rep1(i, n) for (int i=1; i<=n; ++i)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
using namespace std;
typedef long long ll;
constexpr ll  MOD = (1e9+7);
constexpr int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

ll factorial(ll n, ll m=2) {
    // calculate nPm
    m = max(2LL, m);
    ll rtn = 1;
    for (ll i=m; i<=n; i++) {
        rtn = (rtn * i) % MOD;
    }
    return rtn;
}
ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b;
        swap(a, b);
        u -= t * v;
        swap(u, v);
    }
    u %= m;
    if (u < 0)
        u += m;
    return u;
}
ll modpow(ll a, ll n) {
    ll res = 1;
    while (n > 0) {
        if (n & 1)
            res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}

int main() {
    cin.tie(NULL);
    ios::sync_with_stdio(0);
    ll x, y; cin >> x >> y;
    if ((x+y) % 3 != 0) {
        cout << 0 << endl;
    } else {
        int a = (2 * x - y) / 3;
        int b = (2 * y - x) / 3;
        if (a >= 0 && b >= 0) {
            int ans = factorial(a+b) * modinv(factorial(a), MOD) % MOD * modinv(factorial(b), MOD) % MOD;
            cout << ans << endl;
        } else {
            cout << 0 << endl;
        }
    }
    return 0;
}

Submission status: Runtime Error

Solution code:
import math
def C(n,r,mod):
  a=math.factorial(n)/(math.factorial(r)*math.factorial(n-r))
  return int(a%mod)

x,y=map(int,input().split())
mod=1e9+7

if (x+y)%3!=0:
  print(0)
  exit()
n=(2*x-y)/3
m=(2*y-x)/3
if n<0 and m<0:
  print(0)
  exit()
print(n,m)
print(C(n+m,n,mod))

Submission status: Runtime Error

Solution code:
import math
mod = 10**9 + 7
def P(n, r):
    return math.factorial(n)//math.factorial(n-r)
def C(n, r):
    return P(n, r)//math.factorial(r)
X, Y = map(int,input().split())
if (X+Y) % 3 != 0:
    print(0)
    exit()
n = (2*Y-X)//3
m = (2*X-Y)//3
print(C(n+m,m) % mod)

Submission status: Runtime Error

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

def d(r,n,p):#r^n mod p
    if(n==0):
        return 1
    
    elif(n%2==0):
        d_ = d(r,n//2,p)
        return (d_**2)%p
    
    else:
        d_ = d(r,(n-1),p)
        return (d_*r)%p
    
def fac(n,p):#n! mod p
    mul = 1
    for i in range(1,n+1):
        mul = (mul*i)%p
        
def r_fact_p(r,p):#(r!)^(p-2)
    mul = 1
    for i in range(1,r+1): #i^(p-2)
        mul = (mul*d(i,p-2,p))%p
        
    return mul

def C(n,r):
    return (d(r,n,p)*r_fact_p(r,p))%p



if((X-2*Y)%3 !=0 or (2*X-Y)%3 != 0):
    print(0)
    
else:
    a = (-X+2*Y)//3
    b = (2*X-Y)//3
    
    if(a<0 or b<0):
        print(0)
    else:
        
    print(C(a+b,b))

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 #出力の制限x
N = 10**6
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

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


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

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

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

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

Submission status: Runtime Error

Solution code:
import math

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

if m.is_integer() == n.is_integer() == True:
    ans = math.factorial(m+n)//(math.factorial(m) * math.factorial(n))
else:
    ans = 0

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

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 #出力の制限x
N = 10**6
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

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


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

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

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

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

Submission status: Runtime Error

Solution code:
from functools import reduce

def nCk(n, k, mod=10 ** 9 + 7):
    if n < k:
        return 0
    k = min(k, n - k)
    mod_mul = lambda a, b: a * b % mod
    numer = reduce(mod_mul, range(n - k + 1, n + 1))
    denom = reduce(mod_mul, range(1, k + 1))
    return numer * pow(denom, mod - 2, mod) % mod

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

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

if (X + Y) % 3 != 0 or a < 0 or b < 0:
    print(0)
else:
    print(nCk(a + b, a))

Submission status: Runtime Error

Solution code:
from operator import mul
from functools import reduce

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


X, Y = (int(i) for i in input().split())
num = (X+Y) % 3
if num == 0 and max(X,Y) - min(X,Y) <= min(X,Y):
    if num % 2 == 0:
        center = num/2
    else:
        center = (num+1)/2
    if abs(X-Y) % 2 == 0:
        a = abs(X-Y)/2
    else:
        a = abs(X-Y)+1/2

    print(cmb(X+Y/3, center - a)% (10**9+7))
else:
    print(0)

Submission status: Runtime Error

Solution code:
import math
X,Y = list(map(int,input().split()))
if X%3!=0 or Y%3!=0:
    print(0)
else:
    n = (2*Y - X)//3
    m = (2*X - Y)//3

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

Submission status: Runtime Error

Solution code:
import numpy as np
from operator import mul
from functools import reduce
mod = 1000000007
X,Y = map(int, input().split())

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:
    print(0)
else:
    left = [[1,2],
            [2,1]]
    right = [X,Y]
    n,m = np.linalg.solve(left,right)
    n = int(n)
    m = int(m)
    ans = cmb(n+m, n) % mod
    print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np
import itertools
mod = 1000000007
X,Y = map(int, input().split())

def comb(N,R):
    if R == 1:
        return N
    else:
        return N/R * comb(N-1,R-1)

if (X + Y) % 3:
    print(0)
else:
    left = [[1,2],
            [2,1]]
    right = [X,Y]
    n,m = np.linalg.solve(left,right)
    n = int(n)
    m = int(m)
    ans = len(list(itertools.combinations(range(n+m), n))) % mod
    print(ans)

Submission status: Runtime Error

Solution code:
import math

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

if m.is_integer() == n.is_integer() == True:
    ans = math.factorial(m+n)/(math.factorial(m)*math.factorial(n))
else:
    ans = 0

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

Submission status: Runtime Error

Solution code:
import math

x, y = map(int, input().split())
m = (2*x-y)/3
n = (-x+2*y)/3
print(m,n)
if m.is_integer() == n.is_integer() == True:
    ans = math.factorial(m+n)/(math.factorial(m)*math.factorial(n))
else:
    ans = 0

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

Submission status: Runtime Error

Solution code:
import numpy as np
mod = 1000000007
X,Y = map(int, input().split())

def comb(N,R):
    if R == 1:
        return N
    else:
        return N/R * comb(N-1,R-1)

if (X + Y) % 3:
    print(0)
else:
    left = [[1,2],
            [2,1]]
    right = [X,Y]
    n,m = np.linalg.solve(left,right)
    n = int(n)
    m = int(m)
    ans = comb(n+m,n) % mod
    print(ans)

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 #出力の制限x
N = 10**6
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

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


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

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

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

rx = X - tX
ry = Y - tY
if rx == 0 and ry == 0:
    print(cmb(cA+cB, cA, mod))
    exit(0)

if rx != 0 and ry / rx == 2:
    cA += rx
elif ry != 0 and rx / ry == 2:
    cB += ry
else:
    raise Exception
    print(0)
    exit(0)

print(cmb(cA+cB, cA, mod))
# 6.0

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 #出力の制限x
N = 10**6
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

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


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

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

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

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

if rx != 0 and ry / rx == 2:
    cA += rx
elif ry != 0 and rx / ry == 2:
    cB += ry
else:
    print(0)
    exit(0)

print(cmb(cA+cB, cA, mod))
# 6.0