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: Wrong Answer

Solution code:
# compiled by pythran
"""
#pythran export main2()
import numpy as np
i8 = np.int64
MOD = 1000000007

def mod_inv(mod, a):

    old_s, s = 1, 0
    old_t, t = 0, 1
    old_r, r = mod, a

    while r != 0:
        quotient = old_r // r

        old_r, r = r, old_r - quotient * r
        old_s, s = s, old_s - quotient * s
        old_t, t = t, old_t - quotient * t

    return old_t % mod


def get_fac(fac):
    fac[1] = 1
    for i in range(2, fac.shape[0]):
        fac[i] = fac[i - 1] * i % MOD


def combine(m, n, fac):
    return fac[m] * mod_inv(MOD, (fac[m - n] * fac[n]) % MOD) % MOD


def main(in_file):
    stdin = open(in_file)
    X, Y = [int(x) for x in stdin.readline().split()]
    m1 = X + Y
    fac = np.empty(670000, i8)
    get_fac(fac)
    if m1 % 3 == 0:
        m = m1 // 3
        if X < m or Y < m:
            print(0)
        else:
            print(combine(m, X - m, fac))
    else:
        print(0)


def main2():
    main('/dev/stdin')
"""
import os, sys
p = os.path.dirname(__file__)
pymain = os.path.join(p, "a.out")
if len(sys.argv) == 1:
    import subprocess
    if p == "":
        pymain = "./" + pymain
    subprocess.call(pymain)
else:
    import gzip, base64, stat
    gz = b'H4sIADTbU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L2nyelhhqbcKJkPXCk6zFOafbrdyeondgXqGWSzNhQEQM4VEnSXLGu2B3gEAGVP5SJJYy2l4Iq/hFEOi1D4DnfTFh129olbvqCsU+pc3Bex1kELEJmmj/M3lgRlGs1AI9J2FYFTjA/YlDFriCRbiPL9+vKteIFCj3d8oFNYv9wA9mgZ89Ak7RqAAJHgG4yo7ZmTfmt0BrBLCWSEMceAvsZZCn5eM5wudjWwe0ljvS0BA1OFQLA9RGnRSQWnI35EOVgUkCYP2JpcDynsD5A+tn9YFHZFQCDMnnGZ+FedmrmV7PPI6n3wuopQhRqY4fyV/vsnOFMnl5fMTtQxh6LVnpvyYVOXlcxYBhsi7RHn8ndSpWMwrl5fPY6xjiDsYPlN1Tkv+zGFnrtJU57Lk9cddrGAWk12rOh+1gJ2FSlOd89quVZ7rSqW/u9iZKrm8fA7kj2zBdIWK/zRVejc7oyXD8nkR42AKdwoJ/tOTyH8v02ma6lzYicHKc2Fq/cnyt7Hy01XnzA4OUZ5Ly2Rl1OXXMJ1kqc7lbbhaeX4tVfuHVOXl8yydrKA5XXX+U5U+qiofP/fCjmwMKUpeXv48piov788NrVKep0vF/3qV/8n7ogZWvjpHmV/dfhtU5eV95+ZFCfkuVv8zqvLyuRwtc5z89IvX36kqL59bMUoUXq25eP14XVQOd55Q3u/OdyfXt1aV4hW6Oq68vI9e6k7Or7r8Uca/XF7e9zaz8htU/Kvj2WnOt/hziJEmpaNmqerVcwGBr18+hxTx9k3+TFX5+LmAZpo8pbl4+RxVeXl/8Kl7Ll6//MHfC2u58vL+Xycrn3sJ/V3D6jeq7YqVr+7D+d+0JP2a3sfak/kPnlu6NUn86cfrjvtUs42j1sEXj9+DU5R//Qc0vV5z8fL/A5S7nx24mgAA'
    bin = gzip.decompress(base64.b64decode(gz))
    with open(pymain, "wb") as f:
        f.write(bin)
    os.chmod(pymain, 0o775)

Submission status: Wrong Answer

Solution code:
#pythran export main2()
import numpy as np
i8 = np.int64
MOD = 1000000007

def mod_inv(mod, a):

    old_s, s = 1, 0
    old_t, t = 0, 1
    old_r, r = mod, a

    while r != 0:
        quotient = old_r // r

        old_r, r = r, old_r - quotient * r
        old_s, s = s, old_s - quotient * s
        old_t, t = t, old_t - quotient * t

    return old_t % mod


def get_fac(fac):
    fac[1] = 1
    for i in range(2, fac.shape[0]):
        fac[i] = fac[i - 1] * i % MOD


def combine(m, n, fac):
    return fac[m] * mod_inv(MOD, (fac[m - n] * fac[n]) % MOD) % MOD


def main(in_file):
    stdin = open(in_file)
    X, Y = [int(x) for x in stdin.readline().split()]
    m1 = X + Y
    fac = np.empty(670000, i8)
    get_fac(fac)
    if m1 % 3 == 0:
        m = m1 // 3
        if X < m or Y < m:
            print(0)
        else:
            print(combine(m, X - m, fac))
    else:
        print(0)


def main2():
    main('/dev/stdin')

Submission status: Wrong Answer

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

if ((2*X-Y) % 3 != 0) or (2*X-3 < 0):
  print(0)
  exit()
A = (2*X-Y)//3
B = Y-X+A
N = A+B
nu = 1
de = 1

for i in range(B+1, N+1):
  nu = (nu * i) % (10 ** 9 + 7)
for i in range(1, A+1):
  de = (de * i) % (10 ** 9 + 7)
  
print((nu * pow(de, -1, 10 ** 9 + 7) ) % (10 ** 9 + 7))

Submission status: Wrong Answer

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

MOD = 10**9+7
n = (x+y)//3
a = x-n
b = y-n

if (x+y)%3 != 0 or a < 0 or b < 0:
    print(0)
else:
    a = x-n
    b = y-n
    print(cmb(a+b,b))

Submission status: Wrong Answer

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

MOD = 10**9+7
n = (x+y)//3

if (x+y)%3 != 0:
    print(0)
else:
    a = x-n
    b = y-n
    print(cmb(a+b,a)%MOD)

Submission status: Wrong Answer

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

n = (x+y)//3

if (x+y)%3 != 0:
    print(0)
else:
    a = x-n
    b = y-n
    print(cmb(a+b,a))

Submission status: Wrong Answer

Solution code:
X, Y = map(int, input().split())
n = (2*X - Y) / 3
m = (2*Y - X) / 3
P = 10 ** 9 + 7
N = 10 ** 6
fact = [1, 1]
factinv = [1, 1]
inv = [0, 1]
for i in range(2, N+1):
    fact.append((fact[-1]*i)%P)
    inv.append((-inv[P%i] * (P // i)) %P)
    factinv.append((factinv[-1] * inv[-1])%P)
if n % 1 == 0:
    if m %1 == 0:
        n = int(n)
        m = int(m)
        print(fact[n+m]*factinv[n]*factinv[m]%P)
else:
    print(0)

Submission status: Wrong Answer

Solution code:
X, Y = map(int, input().split())
n = (2*X - Y) / 3
m = (2*Y - X) / 3
P = 10 ** 9 + 7
N = 10 ** 6
fact = [1, 1]
factinv = [1, 1]
inv = [0, 1]
for i in range(2, N+1):
    fact.append((fact[-1]*i)%P)
    inv.append((-inv[P%i] * (P // i)) %P)
    factinv.append((factinv[-1] * inv[-1])%P)
if n % 1 == 0:
    n = int(n)
    m = int(m)
    print(fact[n+m]*factinv[n]*factinv[m]%P)
else:
    print(0)

Submission status: Wrong Answer

Solution code:
mod=10**9+7
N,K=list(map(int,input().split()))
if (N+K)%3==0 and N*2>K and K*2>N:
   A=max(N,K)-min(N,K)
   low=(min(N,K)-A)//3
   all_pt=low*2+A
else:
   print(0)
   exit()
up,down=1,1
for i in range(low):
   up=up*(all_pt-i)%mod
   down=down*(i+1)%mod
base=pow(down,mod-2,mod)
print(up*base%mod)

Submission status: Wrong Answer

Solution code:
class Factorial:
    def __init__(self, max_fact, mod):
        #mod should be prime number
        #using homogeneous_product(n,r), max_fact ≧ max(n+r-1)
        f = [1] * (max_fact + 1)
        for idx in range(2, max_fact + 1):
            f[idx] = f[idx - 1] * idx
            f[idx] %= mod
        if mod > max_fact:
            fi = [pow(f[-1], mod - 2, mod)]
            for idx in range(max_fact, 0, -1):
                fi += [fi[-1] * idx % mod]
            fi = fi[::-1]
        else:
            fi = [pow(n, mod - 2, mod) for n in f]
        self.mod = mod
        self.f = f
        self.fi = fi

    def factorial(self, n):
        return self.f[n]

    def factorial_inverse(self, n):
        return self.fi[n]

    def combination(self, n, r):
        f = self.f
        fi = self.fi
        return f[n] * fi[r] * fi[n - r] % self.mod

    def permutation(self, n, r):
        return self.f[n] * self.fi[n - r] % self.mod

    def homogeneous_product(self, n, r):
        f = self.f
        fi = self.fi
        return f[n + r - 1] * fi[r] * fi[n - 1] % self.mod


max_fact = 10**6
mod = 10**9 + 7
fact_instance = Factorial(max_fact, mod)
comb = fact_instance.combination
perm = fact_instance.permutation
combrep = fact_instance.homogeneous_product

X, Y = [int(_) for _ in input().split()]
i = X - (X + Y) // 3
j = Y - (X + Y) // 3
if (X + Y) % 3 or i < 0 or j < 0:
    ans = -1
else:
    ans = comb(i + j, i)
print(ans)

Submission status: Wrong Answer

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

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

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

# ans = math.factorial(a+b)/math.factorial(a)
# ans=1
# for i in range(a+1,a+b+1):
#     ans*=i%(10**9+7)

def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % p

p = 10 ** 9 + 7
N = 10 ** 6  # N は必要分だけ用意する
fact = [1, 1]
factinv = [1, 1]
inv = [0, 1]
 
for i in range(2, N + 1):
    fact.append((fact[-1] * i) % p)
    inv.append((-inv[p % i] * (p // i)) % p)
    factinv.append((factinv[-1] * inv[-1]) % p)

ans = cmb(a+b,a,p)

print(ans)

Submission status: Wrong Answer

Solution code:
from functools import lru_cache

MOD = 10**9+7

x,y = list(map(int, input().split()))
a = (2*x - y) // 3
b = (2*y - x) // 3

if a == b == 0:
    print(0)
    exit()
    
@lru_cache(maxsize=None)
def fact(x):
    f = 1
    for i in range(2, x+1):
        f *= i
        f %= MOD
    return f

def fact_inv(x):
    return pow(fact(x), MOD-2, MOD)

ans = fact(a+b) * fact_inv(a) * fact_inv(b) % MOD

print(ans)

Submission status: Wrong Answer

Solution code:
p = 10 ** 9 + 7
N = 10**6  #Nの取りうる最大
R = 10**6  #Rの取りうる最大

fact = [1, 1]  # fact[n] = (n! mod p)
factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1]  # factinv 計算用

for i in range(2, N + 1):
  fact.append((fact[-1] * i) % p)
  
for i in range(2, R + 1):
  inv.append((-inv[p % i] * (p // i)) % p)
  factinv.append((factinv[-1] * inv[-1]) % p)

def comb(n, r, p):
  if (r < 0) or (n < r):
    return 0
  r = min(r, n - r)
  return fact[n] * factinv[r] * factinv[n-r] % p


a,b=map(int,input().split())
if (a+b)%3==0:
  T=int((a+b)/3)
  K=a-T
  print(comb(T,K,p))

Submission status: Wrong Answer

Solution code:
mod=10**9+7

x,y=map(int,input().split())
if (x+y)%3!=0:
  print(0)
  exit()
  
if x*2<y or y*2<x:
  print(0)
  exit()
  
z=(x+y)//3

x-=z
y-=z

n=x+y
r=x


lst=[0]+[1]
for i in range(2,n+10):
  lst.append((lst[-1]*i)%mod)


xxx=lst[n]
xxx*=pow(lst[n-r],10**9+5,mod)
xxx%=mod
xxx*=pow(lst[r],10**9+5,mod)
xxx%=mod

print(xxx)

Submission status: Wrong Answer

Solution code:
mod=10**9+7

x,y=map(int,input().split())
if (x+y)%3!=0:
  print(0)
  exit()
  
if x*2>y or y*2>x:
  print(0)
  exit()
  
z=(x+y)//3

x-=z
y-=z

n=x+y
r=x


lst=[0]+[1]
for i in range(2,n+10):
  lst.append((lst[-1]*i)%mod)


xxx=lst[n]
xxx*=pow(lst[n-r],10**9+5,mod)
xxx%=mod
xxx*=pow(lst[r],10**9+5,mod)
xxx%=mod

print(xxx)

Submission status: Wrong Answer

Solution code:
mod=10**9+7

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

x-=z
y-=z

n=x+y
r=x


lst=[0]+[1]
for i in range(2,2*10**6+10):
  lst.append((lst[-1]*i)%mod)


xxx=lst[n]
xxx*=pow(lst[n-r],10**9+5,mod)
xxx%=mod
xxx*=pow(lst[r],10**9+5,mod)
xxx%=mod

print(xxx)

Submission status: Wrong Answer

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

X,Y=2*y-x,2*x-y
if X%3!=0 or Y%3!=0:print(0);exit()


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


X,Y=X//3,y//3
n=X+Y
k=max(X,Y)
g1=[1,n]
g2=[1,1]
inverse=[0,1]

for i,j in enumerate(range(n-1,((n-k+1)-1),-1)):
    i=i+2
    g1.append((g1[-1]*j)%mod)
    inverse.append((-inverse[mod%i]*(mod//i))%mod)
    g2.append((g2[-1]*inverse[-1]%mod))

print(cmb(n,k,mod))

Submission status: Wrong Answer

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

if not((-X+2*Y)%3==0 and (2*X-Y)%3==0):
    print(0)
    sys.exit()

A,B=(-X+2*Y)//3,(2*X-Y)//3

P=1
for i in range(1,A+B+1):
    P*=i
    P%=M

Q=1
for i in range(1,A+1):
    Q*=i
    Q%=M

R=1
for i in range(1,B+1):
    R*=i
    R%=M

S=(P*pow(Q,M-2,M)*pow(R,M-2,M))%M
print(S)

Submission status: Wrong Answer

Solution code:
x,y=map(int,input().split())
a=max(x,y)
b=min(x,y)
s=a-b
A=a-s-s
if A>=0 and A%3==0:
    t=A//3
    p=t+s
    q=t
    ans=1
    print(p,q)
    for i in range(q):
        ans=ans*(p+q-i)*pow((i+1),10**9+5,10**9+7)
        ans=ans%(10**9+7)
    print(ans)
else:
    print(0)

Submission status: Wrong Answer

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

total = (X+Y)/3
k = (2*X-Y)//3

if (total == int(total)) and (k>0):
    total = (X+Y)//3

    mod = 10 ** 9 + 7

    modinv_table = [-1] * (k + 1)
    for i in range(1, k + 1):
        modinv_table[i] = pow(i, -1, mod)


    def binomial_coefficients(n, k):
        ans = 1
        for i in range(k):
            ans *= n - i
            ans *= modinv_table[i + 1]
            ans %= mod
        return ans

    print(binomial_coefficients(total,k))
else:
    print(0)

Submission status: Wrong Answer

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

total = (X+Y)/3
if total == int(total):
    total = (X+Y)//3

    mod = 10 ** 9 + 7
    k = (2*X-Y)//3


    modinv_table = [-1] * (k + 1)
    for i in range(1, k + 1):
        modinv_table[i] = pow(i, -1, mod)


    def binomial_coefficients(n, k):
        ans = 1
        for i in range(k):
            ans *= n - i
            ans *= modinv_table[i + 1]
            ans %= mod
        return ans

    print(binomial_coefficients(total,k))
else:
    print(0)