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:
mport subprocess
import gzip, base64, os
import stat

gz = b'H4sIAEMB0F0C/+19C3gUVbZudTqPBkK6QdTwkoBBggwhnQRIdNSEpKFaOhAJID6wSDodEu2k86WrMfjESeLYNlGOx+s4zpwZ7sxcRz0zZ/AxDHpGCILEx4iIiCgiERGrCQqoQEShz1p77+rsqq6KMDP3ft/9vmklu9dfa++91tprr/2o6tr3ujyzkywWQf0kCVcLSD07uoTQJQx/wBtnAaxIGAR/xwljhFSgUzi+EqFEk/axotXUxvis8C8Z/hUlUbooqUSTjmF8amrh0hSB/5RoUtv1giYVhKx4PpR1z1KK7lm6TJM6kimel6bNl8Ty9bF8fYxfTYUkQZOq+iWzfwsZvpDppabljK+c48dP5WdyLbHLdcwu15Vo0rsY3126fNdBvlTh3D8Oli5g9ZnZJYfJr6ZqO0zzN9TMKJzmr53qb2gKtU5tLZoxdUZhbjCQm09kcjDeOfMWaeyYyWQewXwAr5+xV/zp+p8cv+vsjzemT5p344y7jjt78Foxy4dN0tHkqE8ePyjJIhQKq6BovPZj+FcK/577qOC9wfetkf7D+/KrDzXGXnugw3vRrqq1batvKDk+9bh0S0bWirwc13uersOXdY14PL3sV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xM/Y1hd0bgfvlpRwh8cmHhdsGGISzg5OLER7vrJRKdrDy7UlGB55bnJSuC4ukzN2DaLH33diti4u+AJ1eneKnyuu1YAM9H/fqdW6OsmPQBNc6JwPjTYYsw1OcjeLBSYHchu1J3eit84U5Okqo6O4E93mn3DktMGoaaBd/Lx33TXNOc9wjZ27rD/GPdGq6oncBtMfeqa2gRD6A8cTXbl5ZX/LOwsTz63WT0oamgQa1/4HvgJuIEeKAAA='
bin = gzip.decompress(base64.b64decode(gz))
p = os.path.dirname(__file__)
pymain = os.path.join(p, "a.out")
with open(pymain, "wb") as f:
    f.write(bin)
os.chmod(pymain, stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR)
if p == "":
    pymain = "./" + pymain
subprocess.call(pymain)


# compiled by pythran
'''
#pythran export main2()
import numpy as np
i8 = np.int64
MOD = 1000000007


def init(fac, inv, finv):
    fac[0] = fac[1] = 1
    finv[0] = finv[1] = 1
    inv[1] = 1
    for i in range(2, fac.shape[0]):
        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, fac, finv):
    if n < k:
        return 0
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD

def main2():
    stdin = open('/dev/stdin')
    X, Y = map(int, stdin.readline().split())
    a = X + Y
    if a % 3:
        print(0)
    else:
        d = a // 3
        if X < d or Y < d:
            print(0)
        else:
            fac = np.empty(d + 1, i8)
            inv = np.empty(d + 1, i8)
            finv = np.empty(d + 1, i8)
            init(fac, inv, finv)
            ans = com(d, X - d, fac, finv)
            print(ans)
'''

Submission status: Runtime Error

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

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 = 5*(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 )

if sum_xy%3!=0:
    print(0)
else:
    ab_sum = sum_xy//3
    a = x-ab_sum
    b = y-ab_sum
    print(cmb(ab_sum,a,inf))

Submission status: Runtime Error

Solution code:
import sys
import numpy as np

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

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


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

    s = (2*X - Y)/3
    t = (2*Y - X)/3

    if s != int(s) or t != int(t) or s < 0 or t < 0:
        print(0)
        sys.exit()

    s = int(s)
    t = int(t)
    MAX_NUM = max(X, Y)
    dp = np.zeros((X+1, Y+1), np.int)
    for i in range(MAX_NUM):
        if i == 0:
            for j in range(len(dp[0])):
                if j == 0: dp[i][j] = 0
                else: dp[i][j] = 1
        else:
            for j in range(len(dp[0]-1)):
                if j == 0: dp[i][j] = 1
                else: dp[i][j] = dp[i-1][j] + dp[i][j-1]

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


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import math
from math import factorial

def combinations_count(n, r):
    ''' 組み合わせ '''
    return factorial(n) // (factorial(n - r) * factorial(r))

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

i = (2*X-Y)//3
j = (2*Y-X)//3

if(  ((2*X-Y)%3)!=0 or (2*Y-X)%3!=0  ):
    print(0)
else:
    print(combinations_count(i+j, i))

Submission status: Runtime Error

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

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

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


X,Y = map(int,input().split())
s = (2*Y-X)//3
t = (2*X-Y)//3

if (X+Y)%3 == 0 :
    ans =  mod_combination(s+t, s, mod)
    print(ans)
else:
    print(0)

Submission status: Runtime Error

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

m = min(x-n,y-n)
mod = 1000000007
a=1
b=1

for i in range(1,m+1):
  a = a *(n+1-i) % mod
  b = b * i %mod
print(ans)

Submission status: Runtime Error

Solution code:
from math import factorial
import sys

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

if min(X, Y) == 1:
    if max(X, Y) == 2:
        print('1')
    else:
        print('0')
else:

    for i in range(round(min(X, Y) / 2) + 1):
        if (min(X, Y) - i * 2) * 2== (max(X, Y) - i):
            answer = factorial(min(X, Y) - i) / factorial(i) / factorial(min(X, Y) - i * 2)
            print(answer)
            sys.exit()
    print('0')

Submission status: Runtime Error

Solution code:
X,Y=map(int,input().split())
A=0
B=0
kaijo_1=1
kaijo_2=1
if Y>X:
    A=(2*X-Y)/3
    B=(5*X-4*Y)/3
    for i in range(B+1,A+B+1):
        kaijo_1=kaijo_1*i
    for i in range(1,A+1):
        kaijo_2=kaijo_2*i
    print(int((kaijo_1/kaijo_2)%(10**9+7)))
elif X>Y:
    A=(2*Y-X)/3
    B=(5*Y-4*X)/3
    for i in range(B+1,A+B+1):
        kaijo_1=kaijo_1*i
    for i in range(1,A+1):
        kaijo_2=kaijo_2*i
    print(int((kaijo_1/kaijo_2)%(10**9+7)))
else:
    if X%3==0:
        A=int(X/3)
        for i in range(A+1,2*A+1):
            kaijo_1=kaijo_1*i
        for i in range(1,A+1):
            kaijo_2=kaijo_2*i
        print(int((kaijo_1/kaijo_2)%(10**9+7)))
    else:
        print(0)

Submission status: Runtime Error

Solution code:
s=list(map(int,input().split()))
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 result
if s[0]%3==0 and s[1]%3==0:
  a=max(s)-min(s)
  b=(min(s)-a)//3
  c=ncr(b*2+a,b)%1000000009
  print(int(c))
elif s[0]%3==1 and s[1]%3==2:
  a=s[0]-1
  b=s[1]-2
  c=max(a,b)-min(a,b)
  d=(min(a,b)-c)//3
  e=ncr(d*2+c+1,d)%1000000009
  print(int(e))
elif s[0]%3==2 and s[1]%3==1:
  a=s[0]-2
  b=s[1]-1
  c=max(a,b)-min(a,b)
  d=(min(a,b)-c)//3
  e=ncr(d*2+c+1,d)%1000000009
  print(int(e))

Submission status: Runtime Error

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

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

if y > 2 * x or y < x / 2:
    print(0)
    sys.exit()

dp[0][0] = 1
dp[2][1] = 1
dp[1][2] = 1

#print(dp)

for i in range(2, x+1):
    #for j in range(i // 2, 2 * i + 1):
    for j in range(i // 2, y+1):
        #print(i, j)
        # if j > y:
        #     break
        if (i + j) % 3 != 0:
            continue
        if y == x / 2:
            dp[i][j] = dp[i-2][j-1] % div
        elif y == 2 * x:
            dp[i][j] = dp[i-1][j-2] % div
        else:
            #print('merge!', dp[i-1][j-2], dp[i-2][j-1])
            dp[i][j] = (dp[i-1][j-2] + dp[i-2][j-1]) % div

#print(dp)
print(dp[x][y])

Submission status: Runtime Error

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

m1=(2*y-x)/3
n1=y-m1*2

m2=(2*x-y)/3
n2=x-m2*2

if(m1.is_integer()):
  print(int(factorial(m1+n1)/factorial(m1)/factorial(n1)) % (10**9+7))

elif(m2.is_integer()):
  print(int(factorial(m2+n2)/factorial(m2)/factorial(n2)) % (10**9+7))

else:
 print(0)

Submission status: Runtime Error

Solution code:
class Combination:
    def __init__(self, size, mod=10**9 + 7):
        self.size = size + 2
        self.mod = mod
        self.fact = [1, 1] + [0] * size
        self.factInv = [1, 1] + [0] * size
        self.inv = [0, 1] + [0] * size

        for i in range(2, self.size):
            self.fact[i] = self.fact[i - 1] * i % self.mod
            self.inv[i] = -self.inv[self.mod % i] * (self.mod // i) % self.mod
            self.factInv[i] = self.factInv[i - 1] * self.inv[i] % self.mod

    def npr(self, n, r):
        if n < r or n < 0 or r < 0:
            return 0
        return self.fact[n] * self.factInv[n - r] % self.mod

    def ncr(self, n, r):
        if n < r or n < 0 or r < 0:
            return 0
        return self.fact[n] * (self.factInv[r] * self.factInv[n - r] % self.mod) % self.mod

    def factN(self, n):
        if n < 0:
            return 0
        return self.fact[n]

    def f(self, p, q):
        return self.fact[p + q] * self.factInv[p] * self.factInv[q] % MOD


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

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

time = (X + Y) // 3
ans = 0
comb = Combination(time + 10)

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

print(comb.f(x, y) % MOD)

Submission status: Runtime Error

Solution code:
import math
X,Y = map(int,input().split())
def comb(n,r):
    return math.factorial(n) // (math.factorial(n-r) * math.factorial(r))
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)
    print((comb(lr,min([left,right])))%(10**9+7))

Submission status: Runtime Error

Solution code:
import numpy as np
def cumprod(arr,MOD):
    L = len(arr); Lsq = int(L**.5+1)
    arr = np.resize(arr,Lsq**2).reshape(Lsq,Lsq)
    for n in range(1,Lsq):
        arr[:,n] *= arr[:,n-1]; arr[:,n] %= MOD
    for n in range(1,Lsq):
        arr[n] *= arr[n-1,-1]; arr[n] %= MOD
    return arr.ravel()[:L]

def make_fact(U,MOD):
    x = np.arange(U,dtype=np.int64); x[0] = 1
    fact = cumprod(x,MOD)
    x = np.arange(U,0,-1,dtype=np.int64); x[0] = pow(int(fact[-1]),MOD-2,MOD)
    fact_inv = cumprod(x,MOD)[::-1]
    return fact,fact_inv

U = 10**6
fact, invfact = make_fact(U,MOD)

MOD = 10**9 + 7
X, Y = [int(x) for x in input().split()]
if (X+Y) % 3 != 0:
    print(0)
    exit()
r = (X+Y) // 3
k = X - r
if (k < 0 or Y - r < 0):
    print(0)
else:
    print(fact[r] * invfact[r-k] % MOD * invfact[k] % MOD)

Submission status: Runtime Error

Solution code:
import math
from operator import mul
from functools import reduce
import sys a

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

a=list(map(int, input().split()))
X=a[0]
Y=a[1]
if X/2>Y or X<Y/2:
  print(0)
  sys.exit()
x=0
y=0

mi=min(X,Y)//3*3
if mi>=2:
  X-=mi
  Y-=mi
  x+=mi//3
  y+=mi//3
  if X==0 and Y==0:
    print(cmb(x+y, x)%(10**9+7))
    sys.exit()
  elif max(X,Y)%3==0:
    print(0)
    sys.exit()

if X>Y:
  x+=X//3*2
  y-=X//3
elif Y>X:
  y+=X//3*2
  x-=X//3
print(cmb(x+y, x)%(10**9+7))
"""
flag=True
while(flag):
  if X>=Y:
    X-=2
    Y-=1
    x+=1
  else:
    Y-=2
    X-=1
    y+=1
  if X==0 or Y==0:
    print('step')
    if X==Y:
      # a = comb(n, r)
      print(cmb(x+y, x)%(10**9+7))
      #print((int(math.factorial(x+y))//int(math.factorial(x))//int(math.factorial(y)))%(10**9+7))
      break
    else:
      print(0)
      break
"""

Submission status: Runtime Error

Solution code:
t = input().rstrip().split(" ")
x = int(t[0])
y = int(t[1])
temp = {}
def get_num(x, y):
    res = 0
    if (x == 0) and (y == 0):
        res = 1
    elif (x <= 0) or (y == 0):
        res = 0
    elif (x, y) in temp:
        res = temp[(x, y)]
    else:
        res += get_num(x-1, y-2) % (1e9 + 7)
        res += get_num(x-2, y-1) % (1e9 + 7)
        res %= (1e9 + 7)
        temp[(x, y)] = res
    return res

print(int(get_num(x, y)))

Submission status: Runtime Error

Solution code:
import sys
import math
from statistics import mean
from functools import reduce, lru_cache
from itertools import permutations


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

    print(reachable((0, 0), (x, y)))


def reachable(current, target):
    if current == target:
        return 1
    elif (current[0]>target[0]) or (current[1]>target[1]):
        return 0
    else:
        return reachable((current[0]+1, current[1]+2), target) + reachable((current[0]+2, current[1]+1), target)


if __name__ == '__main__':
    p = input().split(' ')
    main(int(p[0]), int(p[1]))

Submission status: Runtime Error

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

m1=(2*y-x)/3
n1=y-m1*2

m2=(2*x-y)/3
n2=x-m2*2

if(m1.is_integer()):
  print(int(factorial(m1+n1)/factorial(m1)/factorial(n1)))

elif(m2.is_integer()):
  print(int(factorial(m2+n2)/factorial(m2)/factorial(n2)))

else:
 print(0)

Submission status: Runtime Error

Solution code:
mod = 1000000007
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
X,Y = (int(i) for i in input().split())

Z = X + Y
A = max(X,Y)
B = min(X,Y)
C = A - B

if Z % 3 != 0:
    print(0)
else:
    N = Z // 3
    if (N - C) % 2 != 0:
        print(0)
    else:
        M = (N - C) // 2


        a = 1
        b = 1
        for i in range(M):
            a = (a * (i + 1)) % mod
            c = power(a, mod-2)
        for i in range(M):
            b = (b * (N-i)) % mod
        ans = b * c % mod

        print(ans)

Submission status: Runtime Error

Solution code:
import scipy
from scipy.misc import comb
X,Y = map(int,input().split())
T = X + Y
if T % 3 != 0:
    print(0)
elif X > 2*Y:
    print(0)
elif Y > 2*X:
    print(0) 
else:
    Z = int(comb(T/3,X-T/3,exact = True) % 1000000007)
    print(Z)