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 sys
import math

def factorial(n) : 
    if n>= 0:
        memo[0] = 1
        for i in range(n):
            memo[i] = i*memo[i-1]
        return memo[n]

X,Y = list(map(int, input().split()))
counter = 0
memo = [0]*((X+Y))
factorial((X+Y)//3)

if (X+Y)%3 != 0:
    print(0)
    sys.exit()
else:
    for k in range(Y//2 + 1):
        if X == 2*Y - 3*k:
            #print(k)
            counter += memo[Y-k]//memo[k]//memo[Y-2*k]#//factorial(k)*factorial(Y-2*k)#math.factorial(Y-k) // (math.factorial(k)*math.factorial(Y-2*k))
print(counter%(10**9+7))

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())
if (X+Y) % 3 == 0 and max(X,Y) - min(X,Y) <= min(X,Y):
    print(cmb(X+Y/3, X-Y))
else:
    print(0)

Submission status: Runtime Error

Solution code:
import sys, math

mod = 1000000007

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

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

if X > Y * 2 or Y > X * 2:
    print(0)
    sys.exit()
if (X + Y) % 3 != 0:
    print(0)
    sys.exit()

distance = (X + Y) // 3
x = (X - distance)
y = (Y - distance)
distance_fact = math.factorial(distance)
x_fact = math.factorial(x)
y_fact = math.factorial(y)
answer = div(distance_fact, x_fact)
answer = div(answer, y_fact)
print(answer)

Submission status: Runtime Error

Solution code:
# from operator import mul
from functools import reduce


def com_init():
    for i in range(2, n):
        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():
    return fac[n] * (finv[r] * finv[n - r] % mod) % mod


def modpow(a, m):
    ret = 1
    while m > 0:
        if m & 1:
            ret = ret * a % mod
        a = a * a % mod
        m = m >> 1
    return ret


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


def cmb(n, r):
    r = min(r, n - r)
    if r == 0:
        return 1
    over = reduce(lambda a, b: a * b % mod, range(n, n - r, -1))
    under = reduce(lambda a, b: a * b % mod, range(1, r + 1))
    return over * modinv(under) % mod


x, y = [int(i) for i in input().split()]
if (x + y) % 3:
    print(0)
else:
    # n = (x + y) // 3
    # r = min((2 * x - y) // 3, (2 * y - x) // 3)
    mod = 10**9 + 7
    # fac, finv, inv = [1] * (n + 1), [1] * (n + 1), [1] * (n + 1)
    # com_init()
    # print(com())
    # print(factorial(n) // factorial(r) // factorial(n - r))
    print(cmb((x + y) // 3, (2 * x - y) // 3))

Submission status: Runtime Error

Solution code:
x,y=map(int,input().split())
f=[[0]*(10**3) for i in range(10**3)]
for i in range(x):
  for j in range(y):
    f[i][j]=f[i-1][j-2]+f[i-2][j-1]
print(f[x][y])

Submission status: Runtime Error

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

i = int((2*y-x)/3) if (2*y-x)%3==0 else 0
j = int((2*x-y)/3) if (2*x-y)%3==0 else 0
if i == 0 and j == 0:
    print(0)
else:
    print(int(math.factorial(i+j)//(math.factorial(i)*math.factorial(j))%(pow(10,9)+1)))

Submission status: Runtime Error

Solution code:
import sys
import math
sys.setrecursionlimit(200000)
MOD = 10 ** 9 + 7


def main():
    X, Y = map(int, input().split())
    while X != Y and X >= 0 and Y >= 0:
        if X > Y:
            X -= 2
            Y -= 1
        else:
            X -= 1
            Y -= 2
    if X % 2 == 1 and Y % 2 == 1:
        ab = math.factorial((X + Y) // 3)
        a = math.factorial(X // 3)
        b = math.factorial(Y // 3)
        print(ab // (a * b) % MOD)
    else:
        print(0)



if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
from numpy.linalg import solve


x, y = map(int, input().split())
s, t = solve([[2,1], [1,2]], [x, y])

mod = 1000000007
if s.is_integer() and t.is_integer():
    # ans = (fact(s+t, mod) / (fact(s, mod)*fact(t, mod))) % mod
    ans = 1
    for a, b in zip(list(range(1, s+t+1)), list(range(1, s+1)+list(range(1, t+1)))):
        ans = (ans * (a/b)) % mod
    print(int(ans))
else:
    print(0)

Submission status: Runtime Error

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

if x==1 and y==2:
    print(1)
    exit()

c=0
while x>1 or y>1:
    if x==y*2:
        if c*y<10**9+7:
            L=[1]*y
            L[0]=0
            L2=[1]*y
            for i in range(c):
                L2[i+1]=L[i+1]+L2[i]
                print(L2[-1])
                exit()
        else:
            print(c*7%10**9+7)
            exit()
    x-=1
    y-=2
    c+=1
print(0)

Submission status: Runtime Error

Solution code:
import math
# import itertools
# from scipy.special import perm
# from scipy.functions.combinatorial.numbers import nP

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

# X=2m+n
# Y=2n+m

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

# print(n,m)

if n.is_integer() and m.is_integer():
  print(int((math.factorial(int(n+m))/int(math.factorial(int(n))*int(math.factorial(int(m)))))%(10**9+7)))
  # print(int((math.perm(int(n+m),int(n))/int(int(math.factorial(int(n)))))%(10**9+7)))
  # print(int((len(list(itertools.permutations(range(int(n+m)))))/(len(list(itertools.permutations(range(int(n)))))*len(list(itertools.permutations(range(int(m)))))))%(10**9+7)))
  # print(int((len(list(itertools.permutations(range(int(n+m)),int(n))))/len(list(itertools.permutations(range(int(n))))))%(10**9+7)))
  # print(int(perm(int(n+m), int(n), exact=True)/perm(int(n), exact=True))%(10**9+7))
  # print(int(nP(int(n+m), int(n))/nP(int(n),int(n)))%(10**9+7))
  
else:
  print(0)

Submission status: Runtime Error

Solution code:
x,y=list(map(int,input().split()))
dic={}
pre=1
for i in range(1,max(x+1,y+1)):
  pre*=i
  dic[i]=pre
  

num=(x+y)/2
if (num*2)%3!=0:
  print(0)
  exit()
else:
  dif=abs(num-x)
  result=dic[(num*2)//3]//dic[num//2-dif]
  print(result%(10**9+7))

Submission status: Runtime Error

Solution code:
import math
def com(n, r):
    return math.factorial(n) // (math.factorial(n - r)*math.factorial(r))
x,y=map(int,input().split())
if (2*x-y)/3==int((2*x-y)/3) and (2*y-x)/3==int((2*y-x)/3):
  k=(2*x-y)/3
  l=(2*y-x)/3
  print(com(k+l,k))
else:
  print(0)

Submission status: Runtime Error

Solution code:
import sys

sys.setrecursionlimit(10**6)
input=sys.stdin.readline

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

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

val = [X,Y]
val_min = min(val)

val_min_sho = int(val_min/3)

X_henkan = X - 3*val_min_sho
Y_henkan = Y - 3*val_min_sho
if (X_henkan == 0 and Y_henkan == 0):
    n = (val_min_sho)*2
    n_2 = int(n/2)
    print(comb(n,n_2,10**9+7))
elif (X_henkan / Y_henkan == 2):
    n = (val_min_sho)*2 + Y_henkan
    n_2 = val_min_sho
    print(comb(n,n_2,10**9+7))
elif (Y_henkan / X_henkan == 2):
    n = (val_min_sho)*2 + X_henkan
    n_2 = val_min_sho
    print(comb(n,n_2,10**9+7))
else:
    print(0)

Submission status: Runtime Error

Solution code:
a, b = map(int, input().split(" "))
                
flg = False
  
if a == b and a % 3 == 0:
  x = a//3
  y = b//3
elif a % 2 == 0 and b % 2 != 0:
  x = a // 2
  y = b
elif  b % 2 == 0 and a % 2 != 0:
  x = a 
  y = b // 2
else:
  flg = True
  
if flg:
  print(0)
else:
  if x < y:
    x, y = y, x
  top = 1
  for i in range(x):
    top = top * (i + 1)
  #for i in range(x+y, -1):
      #if i < y:
        #break
      #top = top * (i + 1)

  bottom = 1
  for i in range(x):
    bottom = bottom * (i + 1)

  for i in range(y):
    bottom = bottom * (i + 1)

  value = ( top // botom ) % (1000000000+7)
  #if top < bottom:  
   # value = (top + (1000000000+7)) // bottom
  #else:
    #value = top // bottom
  print(value)

Submission status: Runtime Error

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

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

a = (2*Y-X) / 3
b = Y - 2*a
if a.is_integer() & b.is_integer():
    sum_ = 1
    for i in range(a, a+b+1):
        if sum_ >= mod:
            sum_ = sum_ % mod
        sum_ *= i

    k = factorial(b) % mod
    print(sum_ * modinv(k, mod) % mod)
else:
    print(0)

Submission status: Runtime Error

Solution code:

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

a=int(0)
x=max([a, b])
y=min([a, b])

if x+y % 3 ==0 and x < y*2:
    a=int(1)

n=(x+y)/3
r=(x-y)/2
n2=int(1)
r2=int(1)
r3=int(1)
for i in range(n):
    n2=n2*(i+1)
for i in range(r):
    r2=r2*(i+1)
for i in range(n-r):
    r3=r3*(i+1)
ans=(n2/r2/r3)//(10**9+7)

if a==1:
    print(ans)
else:
    print(a)

Submission status: Runtime Error

Solution code:
import math

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

ans = 0

xx = 1
for i in range(x):
    n = i # x：1 の数
    m = (x - i)/2 # x：2 の数
    if y- 2/n == m:
        if max(n,m) == m:
            n,m = m,n
        ans = math.factorial(n) // (math.factorial(n - m) * math.factorial(m))
        break

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

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

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

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 )

a = cmb(level,ind-1,mod)



print(a )

Submission status: Runtime Error

Solution code:
def modinv(a,m):
	b = m
	u = 1
	v = 0
	while(b):
		t = a // b
		a -= t * b
		a,b = b,a
		u -= t * v
		u,v = v,u
	u %= m
	if u < 0:
		u += m
	return u

def affine_inverse(x,y):
	return (x*2+y*-1)/3, (x*-1+y*2)/3

def main():
	x,y = [int(p) for p in input().split(' ')]
	x,y = affine_inverse(x,y)

	if float.is_integer(x) or float.float.is_integer(y):
		print(0)
		return

	x = int(x)
	y = int(y)

	fac = [0 for r in range(x+y+1)]
	fac_inv = [0 for r in range(x+y+1)]

	for i in range(x+y+1):
		if i == 0:
			fac[i] = 1
		else:
			fac[i] = (fac[i-1]*i)%1000000007

	for i in reversed(range(x+y+1)):
		if i == h+w-3:
			fac_inv[i] = modinv(math.factorial(i),1000000007)
		else:
			fac_inv[i] = fac_inv[i+1] * (i+1) % 1000000007

	print(fac[x+y]*fac_inv[x]*fac_inv[y])%1000000007

main()

Submission status: Runtime Error

Solution code:

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

    if x < y:
        x_ = y
        y_ = x

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

    else:
        n = (x+y)//3
        r = x//2

        #a = len(list(itertools.combinations(range(n), r)))
        #a = comb(n, r, exact=True)
        #a = comb_1(n, r)
        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 )

        a = cmb(n,r,mod)

        print(a)

if __name__ == '__main__':
    main()

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

n = 4
m = 3

memo = {}
def ncr(n,r):
    try:
        return memo[(n,r)]
    except:
        if r == 0 or r == n:
            a = 1
        else:
            a = ncr(n-1,r-1) + ncr(n-1,r)
        memo[(n,r)] = a
        return a

# for i in range(13):
#     print(i)
#     method += ncr(12,i)

# for i in range(16):
#     method += ncr(15,i)

# print( method - 1)
    

    

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 or min(x,y)<n):
        print(0)
    else:
        print(ncr(n,min(x,y)-n)%(10**9+7))
        #print(int(comb(n,min(x,y)-n))%(10**9+7))
        # 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:
# -*- coding: utf-8 -*-

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

mod=10**9+7
fact, inv_fact = [1], [1]
fact_tmp = 1
for i in range(1, max(X,Y)+1):
    fact_tmp *= i
    fact_tmp %= mod
    fact.append(fact_tmp)
    inv_fact.append(pow(fact_tmp, mod-2, mod))
 
 
def ncr(n,r):
	if n < 0 or r < 0 or n < r:	return 0
	else:	return (fact[n] * inv_fact[r] * inv_fact[n-r]) %mod

if X==Y:
    if X%3!=0:
        print 0
    else:
        x=X/3
        print ncr(x*2,x)
else:
    if X<Y: X,Y=Y,x
    sho=X/2
    x=X-(sho*2)
    y=Y-sho
    if (x,y)==(0,0):
        print 0
    elif (x,y)!=(1,2):
        print 0
    else:
        print ncr(sho+1,sho)

Submission status: Runtime Error

Solution code:
from math import factorial

goal = list(map(int, input().split(" ")))

big = max(goal)
small = min(goal)

diff = big - small
diffh = int(diff / 2)

big -= diffh * 2
small -= diffh
bigcount = diffh

if (big % 3 == 2 and small % 3 == 2) or (small <= 0):
    print(0)
    exit()

n = int(big / 3)
if big % 3 == 0:
    ren = 0
else:
    ren = 1

a = factorial(2 * n + bigcount + ren)
b = factorial(n + bigcount)
c = factorial(n + ren)

print(int(
    (a / (b * c))
    % 1000000007)
)

Submission status: Runtime Error

Solution code:
import math

x, y = (int(l) for l in input().split())
if (x+y) % 3 != 0:
    print(0)
else:
    a = (x+y)//3
    n = math.factorial(a)
    if (x+y) % 2 == 0:
        k = a // 2 + abs(x-y)
        ka = math.factorial(k)
        nk = math.factorial(a-k)
        print(int(n/(ka*nk)))
    else:
        k =  a//2 - (abs(x-y)-1)
        ka = math.factorial(k)
        nk = math.factorial(a-k)
        print(nk)
        print(int(n/(ka*nk)))

Submission status: Runtime Error

Solution code:
x, y = map(int, input().split())
dp = [[0 for i in range(x+1)] for j in range(y+1)]
p = 10**9+7
# value, index
node_list = [[dp[0][0], (0, 0)]]
flag = True
while node_list:
    point = node_list.pop(0)

    i = point[1][0]
    j = point[1][1]

    if (i, j) == (x, y):
        print(point[0]%p)
        flag = False
        break

    if i+1 <= x and j+2 <= y:
        dp[i+1][j+2] = point[0] + 1
        node_list.append([dp[i+1][j+2], (i+1, j+2)])
    elif i+2 <= x and j+1 <= y:
        # i+2, j+1
        dp[i+2][j+1] = point[0] + 1
        node_list.append([dp[i+2][j+ 1], (i + 2, j + 1)])

if flag:
    print(0)

Submission status: Runtime Error

Solution code:
x,y=map(int,input().split())
d=[[0]*x for i in range(y)]

def d(a,b):
  if a==1 and b==2:
    return 1
  elif a==2 and b==1:
    return 1
  elif a<1 and b<1:
    return 0
  return d(a-1,b-2)+d(a-2,b-1)

print(d(x,y)%(10**9+7))

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


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

Submission status: Runtime Error

Solution code:
import math
def comb(x,y):
    return (math.factorial(permutations_count(x, y))/math.factorial(y))



x,y = map(int,input().split())
if x<y:
    temp = x
    x = y
    y = x
count = 0

if x == y and x % 3 ==0 and y % 3 == 0:
    print(int(comb((x/3)*2,x/3)))
else:
    while True:
        print(count)
        if x == y*2:
            print(int(comb(y+(count*2), count)))
            break
        elif x > y*2:
            print(0)
            break
        else:
            x =x - 3
            y =y - 3
            count +=1

Submission status: Runtime Error

Solution code:
X, Y=map(int, input().split())
import math
a=(2*X-Y)/3
b=(2*Y-X)/3
if a.is_integer()==True and b.is_integer()==True:
  print(math.factorial(a+b)/(math.factorial(a)*math.factorial(b)))

Submission status: Runtime Error

Solution code:
import math
[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
	# d=1
	# rr=1
	# nr=1
	# for i in range(1,dansu+1):
		# d=d*(i%(10**9+7))
	# for i in range(1,r+1):
		# rr=rr*(i%(10**9+7))
	# for i in range(1,dansu-r+1):
		# nr=nr*(i%(10**9+7))
	
	# kotae=int(d/(rr*nr))
	kotae=math.factorial(dansu)/(math.factorial(dansu-r)*math.factorial(r))
	kotae=int(kotae%(10**9+7))
	
	print(kotae)

Submission status: Runtime Error

Solution code:
from math import factorial

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

if m.is_integer() and n.is_integer():
    a = int(factorial(m+n)/factorial(m)/factorial(n))
    print(a%(10**9+7))
    
else:print(0)

Submission status: Runtime Error

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

dp = [[-1]*(x+1) for i in range(y+1)]
# dp[1][2]=1
# dp[2][1]=1
# dp[1][1]=0
# dp[1][0]=0
# dp[0][1]=0

def f(x,y):
    if (x,y)==(1,2):
        dp[y][x]=1
        return 1
    elif (x,y)==(2,1):
        dp[y][x]=1
        return 1
    elif (x,y)==(1,1):
        dp[y][x]=0
        return 0
    elif (x,y)==(0,1):
        dp[y][x]=0
        return 0
    elif (x,y)==(1,0):
        dp[y][x]=0
        return 0
    else:
        if dp[y][x]==-1:
            dp[y][x]=f(x-1,y-2)+f(x-2,y-1)
        return dp[y][x]

print(dp[y][x]%(10**9+7))

Submission status: Runtime Error

Solution code:
from scipy import special

class Combination:
    def __init__(self, n_max, mod=10**9+7):
        self.mod = mod
        self.modinv = self.make_modinv_list(n_max)
        self.fac, self.facinv = self.make_factorial_list(n_max)

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

    def make_factorial_list(self, n):
        fac = [1]
        facinv = [1]
        for i in range(1, n+1):
            fac.append(fac[i-1] * i % self.mod)
            facinv.append(facinv[i-1] * self.modinv[i] % self.mod)
        return fac, facinv

    def make_modinv_list(self, n):
        modinv = [0] * (n+1)
        modinv[1] = 1
        for i in range(2, n+1):
            modinv[i] = self.mod - self.mod//i * modinv[self.mod%i] % self.mod
        return modinv

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

flag = 0
if x == 0 or y == 0:
  flag = 1

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

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

print(ans)

Submission status: Runtime Error

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

if (X + Y) % 3 != 0:
    print(0)
else:
    m = (X + Y) // 3 #動かした回数
    d = X - m # 2がでた回数
    num = 1
    if m - d >= d:
        for i in range(d):
            num *= m - i
        num = num // math.factorial(d)
    else:
        for i in range(m-d):
            num *= m - i
        num = num // math.factorial(m - d)
    print(num % (10**9 + 7))

Submission status: Runtime Error

Solution code:
x, y = [int(x) for x in input().split()]
 
def c(n, r):
    u = 1
    l = 1
    for i in range(min(r, n - r)):
        u = u * (n - i) / (i + 1)
    return int(u)
 
def solve(x, y):
    if (x + y) % 3 != 0:
        return 0
    if x * 2 < y or y * x < x:
        return 0
    
    n = (x + y) // 3
    r = ((x - y) + n) // 2
    return c(n, r)

print(solve(x, y) % 1000000007)

Submission status: Runtime Error

Solution code:
import sys
import math
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 *= numerator[k]
    return int(result)

x,y= (int(_) for _ in input().split()) 
if (x+y)%3!=0:
    print(0)
    sys.exit()
else:
    n=(x+y)/3
    n=int(n)
    if x<n or y<n:
         print(0)
         sys.exit()
    else:
        x=x-n
        y=y-n
        ans=(ncr(x+y,x))
        print(ans%1000000007)

Submission status: Runtime Error

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

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

mod=10**9+7
fact, inv_fact = [1], [1]
fact_tmp = 1
for i in range(1, max(X,Y)+1):
    fact_tmp *= i
    fact_tmp %= mod
    fact.append(fact_tmp)
    inv_fact.append(pow(fact_tmp, mod-2, mod))
 
 
def ncr(n,r):
	if n < 0 or r < 0 or n < r:	return 0
	else:	return (fact[n] * inv_fact[r] * inv_fact[n-r]) %mod

if X==Y:
    if X%3!=0:
        print 0
    else:
        x=X/3
        print ncr(x*2,x)
else:
    if X<Y: X,Y=Y,x
    sho=X/2
    x=X-(sho*2)
    y=Y-sho
    if (x,y)!=(1,2):
        print 0
    else:
        print ncr(sho+1,sho)

Submission status: Runtime Error

Solution code:
import math
[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
	# d=1
	# rr=1
	# nr=1
	# for i in range(1,dansu+1):
		# d=d*(i%(10**9+7))
	# for i in range(1,r+1):
		# rr=rr*(i%(10**9+7))
	# for i in range(1,dansu-r+1):
		# nr=nr*(i%(10**9+7))
	
	# kotae=int(d/(rr*nr))
	kotae=math.factorial(dansu)/(math.factorial(dansu-r)*math.factorial(r))
	kotae=kotae%(10**9+7)
	
	print(kotae)

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 =map(int,input().split())
M = 0
N = 0
if isinstance((2*Y-X)/3, int) == True:
  M = (2*Y-X)/3
if isintance((2*X-Y)/3, int)==True:
  N = (2*Y-X)/3
if M == 0 && N == 0:
  print(0)
else:
  print(cmb(M+N,M))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import math

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

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

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

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

    ans = (a_b // ab) % 1000000007

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

    
print(ans)

# 999999 999999

Submission status: Runtime Error

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

dp = [[-1]*(x+1) for i in range(y+1)]
# dp[1][2]=1
# dp[2][1]=1
# dp[1][1]=0
# dp[1][0]=0
# dp[0][1]=0

def f(x,y):
    if (x,y)==(1,2):
        dp[y][x]=1
        return 1
    elif (x,y)==(2,1):
        dp[y][x]=1
        return 1
    elif (x,y)==(1,1):
        dp[y][x]=0
        return 0
    elif (x,y)==(0,1):
        dp[y][x]=0
        return 0
    elif (x,y)==(1,0):
        dp[y][x]=0
        return 0
    else:
        if dp[y][x]==-1:
            dp[y][x]=f(x-1,y-2)+f(x-2,y-1)
        return dp[y][x]

print(dp[y][x]%(10**9+7))

Submission status: Runtime Error

Solution code:
import math
import scipy 
import numpy as np
#ABC共通 
abc = input()
abc_list = abc.split(' ')
 
#問題用変数
abc_intlist = []

 
#inputを整数化
for c1 in abc_list:
  abc_intlist.append(int(c1))
 
#以下処理
tesuu = (abc_intlist[0]+abc_intlist[1])/3
diff = max(abc_intlist)-min(abc_intlist)
k = (tesuu-diff)/2

if (tesuu-diff)%2==1:
  print(0)
elif k<0:
  print(0)
elif (abc_intlist[0]+abc_intlist[1])%3 != 0:
    print(0)
else:
    maa = max([tesuu-k,k])
    mk = int(tesuu - maa)
    calc=np.zeros(mk+1, dtype=np.float128)
    calc[0] = 1
    #for c1 in range(mk):
    #    calc = calc*(tesuu-c1)
    for c2 in range(mk):
        calc[c2+1] = calc[c2]*(tesuu-c2)/(mk-c2)
    #print(tesuu/1)
    #print(calc[c2+1])
    print(calc[c2+1]%(10**9+7))

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

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



move = (x+y) / 3
if int(move) != move or x < move or y < move:
    print(0)
else:
    move = int(move)
    diff = max(x,y) - min(x,y)
    res = cmb(move, move//2 - diff//2, mod)
    print(res)

Submission status: Runtime Error

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

xy = [0, 0]
def search(now):
  ret = 0
  #print(now, end="")
  if now[0] > X or now[1] > Y:
    #print("a")
    pass
  elif now[0] == X and now[1] == Y:
    ret = 1
  else:
    ret += search([now[0] + 1, now[1] + 2])
    ret += search([now[0] + 2, now[1] + 1])
  
  return ret % 1000000007

print(search(xy))

Submission status: Runtime Error

Solution code:
import math

X,Y = (int(num) for num in input().split())

a_ = 2*Y - X
b_ = 2*X - Y

aa_ = a_ % 3
bb_ = b_ % 3

if aa_==0 and bb_==0:
    a = a_ / 3
    b = b_ / 3
    conb = int(math.factorial(a+b)) // (int(math.factorial(a))  * int(math.factorial(b)))
    ans = conb % (10 ** 9 + 7)                           
    print(ans)   
else:
    print(0)

Submission status: Runtime Error

Solution code:
import math
def search(stack,num):
    tmp_num = num
    if len(stack) == 0:
        print(tmp_num % (pow(10,9)+7))
        return 0
    tmp = stack.pop()
    if (tmp[0]+tmp[1]) < x+y:
        stack.append([tmp[0]+1,tmp[1]+2])
        stack.append([tmp[0]+2,tmp[1]+1])
        search(stack,tmp_num)
    elif tmp == [x,y]:
        tmp_num += 1
        search(stack,tmp_num)
    else:
        search(stack,tmp_num)

n = input()
x = int(n.split(' ')[0])
y = int(n.split(' ')[1])
if (x + y) % 3 != 0:
    print(0)
else:
    stack = []
    stack.append([2,1])
    stack.append([1,2])
    search(stack,0)

Submission status: Runtime Error

Solution code:
import sys

sys.setrecursionlimit(10**6)
input=sys.stdin.readline

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

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

val = [X,Y]
val_min = min(val)

val_min_sho = int(val_min/3)

X_henkan = X - 3*val_min_sho
Y_henkan = Y - 3*val_min_sho
if (X_henkan / Y_henkan == 2):
    n = (val_min_sho)*2 + Y_henkan
    n_2 = val_min_sho
    print(comb(n,n_2,10**9+7))
elif (Y_henkan / X_henkan == 2):
    n = (val_min_sho)*2 + X_henkan
    n_2 = val_min_sho
    print(comb(n,n_2,10**9+7))
elif (X_henkan == 0 and Y_henkan == 0):
    n = (val_min_sho)*2
    n_2 = int(n/2)
    print(comb(n,n_2,10**9+7))
else:
    print(0)

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()
n=((2*x)-y)//3
m=((2*y)-x)//3
l=min(m,n)
num=m+n
x=1
for i in range(1,l):
  num*=(m+n-i)
  x*=i
x*=l
print((num//x)%((10**9)+7))

Submission status: Runtime Error

Solution code:
import math

N = input().split()
X = int(N[0])
Y = int(N[1])

y = int((2 * Y - X) / 3)
x = int((2 * X - Y) / 3)

if (2 * Y - X) % 3 != 0 or (2 * X - Y) % 3 != 0:
    print(0)
else:
    a = 1
    if x < y:
        for i in range(x):
            a *= x + y - i
        a = a / math.factorial(x)
    else:
        for i in range(y):
            a *= x + y - i    
        a = a / math.factorial(y)
    print(int(a) // (10 ** 9 + 7))