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:
from sys import stdin


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


def main():
    X, Y = [int(x) for x in stdin.readline().rstrip().split()]
    if (X + Y) % 3:
        print(0)
    else:
        n = (X * 2 - Y) // 3
        m = (X - n) // 2
        ans = cmb(n + m, min(n, m))
        print(ans % (10 ** 9 + 7))


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import fractions

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

  if (2*x-y)%3==0 and (2*y-x)%3==0:
    a=(2*x-y)//3
    b=(2*y-x)//3
    #print(a,b)

    result=0.0
    bunbo=1
    bunshi=1

    for i in range(min(a,b)):
      bunbo=bunbo*(a+b-i)
      temp=1+i
      
      if bunbo%temp==0:
        bunbo=bunbo//temp
      else:
        bunshi=bunshi*(1+i)
      while bunbo%2==0 and bunshi%2==0:
        bunbo=bunbo//2
        bunshi=bunshi//2
      while bunbo%3==0 and bunshi%3==0:
        bunbo=bunbo//3
        bunshi=bunshi//3
      while bunbo%5==0 and bunshi%5==0:
        bunbo=bunbo//5
        bunshi=bunshi//5
      #print(bunbo,bunshi)
      f=fractions.gcd(bunbo,bunshi)
      bunbo=bunbo//f
      bunshi=bunshi//f
      
    result=bunbo//bunshi%mod
    print(int(result))

  else:
    print(0)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys

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

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

n1 = (2 * X - Y) // 3
n2 = (2 * Y - X) // 3

P = 10 ** 9 + 7
N = 10 ** 6 + 5
inv_t = [0]+[1]
for i in range(2, N):
    inv_t += [inv_t[P % i] * (P - int(P / i)) % P]

m = 10 ** 9 + 7
res = 1
for i in range(2, n1 + n2 + 1):
    res = res * i % m
for i in range(1, n2 + 1):
    res = res * inv_t[i] % m
for i in range(1, n1 + 1):
    res = res * inv_t[i] % m
print(res)

Submission status: Wrong Answer

Solution code:
import math

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

comb_list = {}
mod_param = 10**9 + 7


def egcd(a, b):
    (x, lastx) = (0, 1)
    (y, lasty) = (1, 0)
    while b != 0:
        q = a // b
        (a, b) = (b, a % b)
        (x, lastx) = (lastx - q * x, x)
        (y, lasty) = (lasty - q * y, y)
    return (lastx, lasty, a)

# ax ≡ 1 (mod m)
def modinv(a, m):
    (inv, q, gcd_val) = egcd(a, m)
    return inv % m

def comb(a, b):
  ans = 1
  for i in range(1, a+1):
    ans *= i
    ans %= mod_param
  
  for i in range(1, b+1):
    k = modinv(i, mod_param)
    ans *= k
    ans %= mod_param
  
  for i in range(1, a-b+1):
    k = modinv(i, mod_param)
    ans *= k
    ans %= mod_param
  return ans

if (abs(2*X-Y)%3 != 0):
  print(0)
else:
  alpha = (2*Y-X)//3
  beta = (2*X-Y)//3
  if alpha > beta:
    print(comb(alpha+beta, beta))
  else:
    print(comb(alpha+beta, alpha))

Submission status: Wrong Answer

Solution code:
def main():
    X, Y = map(int, input().split())
    a = (X+Y)//3
    ans = 0
    mod = 10**9+7

    f = [1]
    for i in range(a):
        f.append(f[i]*(i+1)%mod)

    if (X+Y)%3 == 0:
        for i in range(a+1):
            print('i, a-i',i, a-i)
            x = i + 2 * (a - i)
            y = (2 * i) + (a - i)
            if X == x and Y == y:
                 ans += f[a] * pow(f[i], mod-2, mod)%mod * pow(f[a-i], mod-2, mod)%mod
                                                             
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

def mod_Combination(n, k, mod):
    def ext_gcd(a, b):
        if b == 0:
            return a, 1, 0
        else:
            d,x,y = ext_gcd(b,a%b)
            x-=(a//b)*y 
        return d,y,x
    p,q=1,1
    for i in range(n-k+1, n+1):
        p=(p*i)%mod
    for i in range(2, k+1):
        q=(q*i)%mod
    return int(p*(ext_gcd(q, mod)[1]%mod)%mod)

if X > Y:
    X, Y = Y, X

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

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


else:
    ans = mod_Combination(int(a + b), int(a), 10**9 + 7)

print(ans)

Submission status: Wrong Answer

Solution code:
from sys import stdin
import numpy as np
mod = 10**9+7
X,Y = [int(x) for x in stdin.readline().rstrip().split()]

def mul(a, b):
    return ((a % mod) * (b % mod)) % mod
 
def power(x, n):
    """
    O(log n)
    """
    if n == 0:
        return 1
 
    K = 1
    while n > 1:
        if n % 2 != 0:
            K *= x % mod
        x *= x % mod
        n //= 2
 
    return K * x % mod
 
def div(a, b):
    return mul(a, power(b, mod-2))
 
def fact(n):
    f = 1
    for i in range(1,n+1):
        f *= i
        f %= mod
    return f

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

else:
    A = np.matrix([[2, 1],[1, 2]])
    Y = np.matrix([[X],[Y]])
    x,y = np.linalg.solve(A,Y)
    x = int(x)
    y = int(y)
    ans = fact(x+y)
    ans = div(ans,fact(x))
    ans = div(ans,fact(y))
    print(ans%mod)

Submission status: Wrong Answer

Solution code:
def main():
    X, Y = map(int, input().split())
    a = (X+Y)//3
    ans = 0
    mod = 10**9+7

    f = [1]
    for i in range(a):
        f.append(f[i]*(i+1)%mod)

    if (X+Y)%3 == 0:
        for i in range(a):
            #print('i, X+Y//3-i',i, (X+Y)//3-i)
            x = i + 2 * (a - i)
            y = (2 * i) + (a - i)
            #print('x, y',x, y)
            if X == x and Y == y:
                 ans += f[a] * pow(f[i], mod-2, mod)%mod * pow(f[a-i], mod-2, mod)%mod
                                                             
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

  if (2*x-y)%3==0 and (2*y-x)%3==0:
    a=(2*x-y)//3
    b=(2*y-x)//3
    #print(a,b)

    result=0.0
    bunbo=1
    bunshi=1

    for i in range(min(a,b)):
      bunbo=bunbo*(a+b-i)
      temp=1+i
      if bunbo%temp==0:
        bunbo=bunbo//temp
      else:
        bunshi=bunshi*(1+i)
      while bunbo%2==0 and bunshi%2==0:
        bunbo=bunbo//2
        bunshi=bunshi//2
      while bunbo%3==0 and bunshi%3==0:
        bunbo=bunbo//3
        bunshi=bunshi//3
      while bunbo%5==0 and bunshi%5==0:
        bunbo=bunbo//5
        bunshi=bunshi//5
      #print(bunbo,bunshi)
    result=bunbo//bunshi%mod
    print(int(result))

  else:
    print(0)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

  if (2*x-y)%3==0 and (2*y-x)%3==0:
    a=(2*x-y)//3
    b=(2*y-x)//3
    #print(a,b)

    result=0.0
    bunbo=1
    bunshi=1

    for i in range(min(a,b)):
      bunbo=bunbo*(a+b-i)
      temp=1+i
      if bunbo%temp==0:
        bunbo=bunbo%temp
      else:
        bunshi=bunshi*(1+i)
      if bunbo%2==0 and bunshi%2==0:
        bunbo=bunbo//2
        bunshi=bunshi//2
      #print(bunbo,bunshi)
    result=bunbo/bunshi%mod
    print(int(result))

  else:
    print(0)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
MOD = 1000000007

def factorial(n):
    fac = 1
    for i in range(1, n + 1):
        fac = (fac * i) % MOD
    return fac

def power(x, y, m):
    if (y == 0):
        return 1
    p = power(x, y // 2, m) % m
    p = (p * p) % m

    if (y % 2 == 0):
        return p
    else:
        return ((x * p) % m)

c, d = map(int, raw_input().split())
if c == 0 and d == 0:
    print 1
else:
    if (c < d):
        temp = c
        c = d
        d = temp

    diff = (c - d)
    x1 = c - 2 * diff
    y1 = d - diff
    if (x1 != y1 or x1 % 3 != 0):
        print 0
    else:
        ones = diff + (x1 / 3)
        twos = (x1 / 3)
        ans = factorial(ones + twos)
        onef = factorial(ones)
        onef = power(onef, MOD - 2, MOD)
        twof = factorial(twos)
        twof = power(twof, MOD - 2, MOD)
        ans = (ans * ((onef * twof) % MOD)) % MOD
        print ans

Submission status: Wrong Answer

Solution code:
import sys

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

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

mod = 10 ** 9 + 7

def inv(x):
  return pow(x, mod-2, mod)

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

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

if a <= 0 or b <= 0:
  print (0)
  sys.exit(0)

ans = fac(a+b)
ans = (ans * inv(fac(a))) % mod
ans = (ans * inv(fac(b))) % mod
print (ans)

Submission status: Wrong Answer

Solution code:
import sys

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

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

mod = 10 ** 9 + 7

def inv(x):
  return pow(x, mod-2, mod)

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

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

ans = fac(a+b)
ans = (ans * inv(fac(a))) % mod
ans = (ans * inv(fac(b))) % mod
print (ans)

Submission status: Wrong Answer

Solution code:
from math import factorial
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  = list(map(int, input().split()))
n = int((2*Y-X)/3)
m = int((2*X-Y)/3)
if (X+Y)%3==0 and n>0 and m>0:
    print(comb(n+m, m, 10**9+7))
else:
    print(0)

Submission status: Wrong Answer

Solution code:
def nCk(n,k):
    k=min(k,n-k)
    num,denum=1,1
    for i in range(k):
        num=num*(n-i)%mod
        denum=denum*(i+1)%mod
    return num*pow(denum,mod-2,mod)%mod

x,y=map(int,input().split())
mod=10**9+7
n=(y-0.5*x)/1.5
if int(n)!=n:
    print(0)
else:
    m=(y+x)//3
    l=int(n)
    print(nCk(m,l))

Submission status: Wrong Answer

Solution code:
def nCk(n,k):
#    k=min(k,n-k)
    num,denum=1,1
    for i in range(k):
        num=num*(n-i)%mod
        denum=denum*(i+1)%mod
    return num*pow(denum,mod-2,mod)%mod

x,y=map(int,input().split())
mod=10**9+7
n=(y-0.5*x)/1.5
if int(n)!=n:
    print(0)
else:
    m=(y+x)//3
    l=int(n)
    print(nCk(m,l))

Submission status: Wrong Answer

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

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

if (2*X-Y)%3 != 0 or (2*Y-X)%3 != 0 or Y > X*2:
  print(0)
else:
  m = (2*X-Y)//3
  n = (2*Y-X)//3
  print(nCr(m+n, n))

Submission status: Wrong Answer

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

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

if (2*X-Y)%3 != 0 or (2*Y-X)%3 != 0:
  print(0)
else:
  m = (2*X-Y)//3
  n = (2*Y-X)//3
  print(nCr(m+n, n))

Submission status: Wrong Answer

Solution code:
import logging

logging.basicConfig(level=logging.INFO, format="%(message)s")
#logging.disable(logging.CRITICAL)


def combination(n, r, mod = 10 ** 9 + 7):
    r = min(r, n-r)
    up, down = 1, 1

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

    return up * pow(down, mod - 2, mod) % mod
        
def main():
    X, Y = map(int, input().split())

    if (X + Y) % 3 != 0:
        print(0)
    else:
        m = (2 * Y - X) // 3
        n = (2 * X - Y) // 3
    
        print(combination(n + m, m))
    
    
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import logging

logging.basicConfig(level=logging.INFO, format="%(message)s")
#logging.disable(logging.CRITICAL)


def combination(n, r, mod = 10 ** 9 + 7):
    r = min(r, n-r)
    up, down = 1, 1

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

    return up * pow(down, mod - 2, mod) % mod
        
def main():
    X, Y = map(int, input().split())

    if (X + Y) % 3 != 0:
        print(0)
    else:
        m = (2 * X - Y) // 3
        n = (2 * Y - X) // 3
    
        print(combination(n + m, m))
    
    
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import logging

logging.basicConfig(level=logging.INFO, format="%(message)s")
#logging.disable(logging.CRITICAL)


def combination(n, r, mod = 10 ** 9 + 7):
    r = min(r, n-r)
    up, down = 1, 1

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

    return up * pow(down, mod - 2, mod) % mod
        
def main():
    X, Y = map(int, input().split())

    if (X + Y) % 3 != 0:
        print(0)
    else:
        m = (2 * X - Y) // 3
        n = (2 * Y - X) // 3
    
        print(combination(n, m))
    
    
if __name__ == "__main__":
    main()

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 % (10 ** 9 + 7)
ab = input().split()
a, b = int(ab[0]), int(ab[1])
sum = a + b
if sum % 3 == 0:
    n = int(sum / 3)
    m = b - n
    print(cmb(n, m))
else:
    print("0")

Submission status: Wrong Answer

Solution code:
import math
def C(n,r,mod):
  #a=math.factorial(n)/(math.factorial(r)*math.factorial(n-r))
  print(n,r)
  r=min(r,n-r)
  numer=1
  for i in range(n,n-r,-1):
    numer*=i
  denom=1
  for i in range(r,1,-1):
    denom*=i
  a=int(numer/denom)
  return int(a%mod)

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

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

Submission status: Wrong Answer

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

z=format(Z-2,'b')

def f(A):
    p=1
    for i in range(1,A+1):
        p=(p*i)%Z
    return p

def g(B):
    L=[B]
    for j in range(1,len(z)):
        L.append(L[-1]*B)
    L.reverse()
    q=1
    for k in range(len(z)):
        if z[k]==1:
            q=(q*L[k])%Z
    return q

if (X+Y)%3!=0 or 2*X<Y or 2*Y<X:
    print('0')
else:
    N=(2*Y-X)//3
    M=(2*X-Y)//3
    if N==0:
        print('1')
    elif M==0:
        print('1')
    else:
        ans=f(N+M)*g(f(N))*g(f(M))
        print(ans%Z)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(99999999)
p, q = map(int, input().split())


def knight(x, y):
    if x == 2*y or 2*x == y:
        return 1
    else:
        return (knight(x - 1, y -2) + knight(x - 2, y - 1)) % (10 ** 9 + 7)


if (p + q) % 3 == 0 and abs(p - q) <= (p + q) // 3:
    print(knight(p, q) % (10 ** 9 + 7))
    print("a")
else:
    print(0)

Submission status: Wrong Answer

Solution code:
mod=10**9+7
x,y=map(int,input().split())
a=[0]*101
b=[0]*101
a[1]=1
if (x+y)%3!=0:
    print(0+1)
    exit()
#move cnt
m=(x+y)//3

if x>m*2 or y>m*2:
    print(0+1)
    exit()
print(0)
exit()

Submission status: Wrong Answer

Solution code:
def combination(n,r,mod=10**9+7):
    r=min(r,n-r)
    up,down=1,1
    for i in range(r):
        up=up*(n-i)%mod
        down=down*(i+1)%mod
    return up*pow(down,mod-2,mod)%mod


x,y=map(int,input().split())
n=(x+y)//3
r=y-n
if (x+y)%3!=0 or n<0 or n<r:print(0);exit()
print(combination(n,r))

Submission status: Wrong Answer

Solution code:
def combination(n,r,mod=10**9+7):
    r=min(n,n-r)
    up,down=1,1
    for i in range(r):
        up=up*(n-i)%mod
        down=down*(i+1)%mod
    return up*pow(down,mod-2,mod)%mod


x,y=map(int,input().split())
n=(x+y)//3
m=y-n
if (x+y)%3!=0 or n<0 or n<m:print(0);exit()
print(combination(n,m))

Submission status: Wrong Answer

Solution code:
import sys
from math import factorial

def ncr(n, r, p): 
    # initialize numerator 
    # and denominator 
    num = den = 1 
    for i in range(r): 
        num = (num * (n - i)) % p 
        den = (den * (i + 1)) % p 
    return (num * pow(den,  
            p - 2, p)) % p 

def check(x, y):
    if x < y:
        tmp = x
        x = y
        y = tmp

    n = x - y
    x -= 2 * n

    if (x + y) % 3 == 0:
        return True
    else:
        return False
    

# Read
line = sys.stdin.readlines()[0]
X, Y = map(int,line.split(' '))

if not check(X, Y):
    print(0)
    exit(0)

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

if n < 0 or m < 0:
    print(0)
else:
    p = m if m < n else n
    print(ncr(n+m, p, 10**9+7))

Submission status: Wrong Answer

Solution code:
def fact(n, r):
    calc_a = 1
    calc_b = 1
    for i in range(1, r + 1):
        calc_a = (calc_a * (n + 1 - i)) % p
        calc_b = (calc_b * i) % p
    ans = (calc_a * pow(calc_b, p - 2, p)) % p
    return ans


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

Submission status: Wrong Answer

Solution code:
import sys
from scipy.misc import comb

def check(x, y):
    if x < y:
        tmp = x
        x = y
        y = tmp

    n = x - y
    x -= 2 * n

    if (x + y) % 3 == 0:
        return True
    else:
        return False
    

# Read
line = sys.stdin.readlines()[0]
X, Y = map(int,line.split(' '))

if not check(X, Y):
    print(0)
    exit(0)

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

if n < 1 or m < 1:
    print(0)
else:
    ans = comb(n+m, n, exact=True)
    print(ans%((10**9)+7))

Submission status: Wrong Answer

Solution code:
import sys
from scipy.misc import comb

def check(x, y):
    if x < y:
        tmp = x
        x = y
        y = tmp

    n = x - y
    x -= 2 * n

    if (x + y) % 3 == 0:
        return True
    else:
        return False
    

# Read
line = sys.stdin.readlines()[0]
X, Y = map(int,line.split(' '))

if not check(X, Y):
    print(0)
    exit(0)

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

if n < 1 or m < 1:
    print(0)
else:
    ans = comb(n+m, n, exact=True)
    print(ans)

Submission status: Wrong Answer

Solution code:
# 入力が10**5とかになったときに100ms程度早い
import sys
read = sys.stdin.readline


def read_ints():
    return list(map(int, read().split()))


def read_a_int():
    return int(read())


def read_matrix(H):
    '''
    H is number of rows
    '''
    return [list(map(int, read().split())) for _ in range(H)]


def read_map(H):
    '''
    H is number of rows
    文字列で与えられた盤面を読み取る用
    '''
    return [read()[:-1] for _ in range(H)]


def read_col(H, n_cols):
    '''
    H is number of rows
    n_cols is number of cols

    A列、B列が与えられるようなとき
    '''
    ret = [[] for _ in range(n_cols)]
    for _ in range(H):
        tmp = list(map(int, read().split()))
        for col in range(n_cols):
            ret[col].append(tmp[col])

    return ret


MOD = 10**9 + 7

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

pascal_depth = int((X + Y) / 3)  # パスカルの三角形に当たるn
x = ((X + Y) * 2) // 3
pascal_k = x - X  # 端からいくつずれているか


def combination(n, r, mod=MOD):
    r = min(r, n - r)
    nf = rf = 1
    for i in range(r):
        nf = nf * (n - i) % mod
        rf = rf * (i + 1) % mod
    return nf * pow(rf, mod - 2, mod) % mod


# def com(n, k, mod):
#     if k == 0:
#         return 1
#     s = n
#     mod = 10**9 + 7
#     inv = [0, 1]
#     for c in range(2, k + 1):
#         inv.append((-(mod // c) * inv[mod % c]) % mod)
#         s = (((s * (n + 1 - c)) % mod) * inv[c]) % mod
#     return s


a = combination(pascal_depth, pascal_k, MOD)
print(a)

Submission status: Wrong Answer

Solution code:
# 入力が10**5とかになったときに100ms程度早い
import sys
read = sys.stdin.readline


def read_ints():
    return list(map(int, read().split()))


def read_a_int():
    return int(read())


def read_matrix(H):
    '''
    H is number of rows
    '''
    return [list(map(int, read().split())) for _ in range(H)]


def read_map(H):
    '''
    H is number of rows
    文字列で与えられた盤面を読み取る用
    '''
    return [read()[:-1] for _ in range(H)]


def read_col(H, n_cols):
    '''
    H is number of rows
    n_cols is number of cols

    A列、B列が与えられるようなとき
    '''
    ret = [[] for _ in range(n_cols)]
    for _ in range(H):
        tmp = list(map(int, read().split()))
        for col in range(n_cols):
            ret[col].append(tmp[col])

    return ret


MOD = 10**9 + 7

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

pascal_depth = int((X + Y) / 3)  # パスカルの三角形に当たるn
x, y = int((X + Y) * 2 / 3), (X + Y) / 3
pascal_k = x - X  # 端からいくつずれているか

if pascal_k > pascal_depth / 2:
    pascal_k = pascal_depth - pascal_k


def combination(n, r, mod=MOD):
    r = min(r, n - r)
    nf = rf = 1
    for i in range(r):
        nf = nf * (n - i) % mod
        rf = rf * (i + 1) % mod
    return nf * pow(rf, mod - 2, mod) % mod


a = combination(pascal_depth, pascal_k, MOD)
print(a)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
x,y = map(int,input().split(" "))
move_a = (2*y - x)//3
move_b = (2*x - y)//3
counter = 1
if (2*y - x)%3 != 0 or (2*x - y)%3 != 0:
  print(0)
else:
  move = min(move_a,move_b)
  for i in range(move):
    counter *= (move_a+move_b-i)//(move-i)
  print(counter%(10**9+7))

Submission status: Wrong Answer

Solution code:
def d_knight():
    X, Y = [int(i) for i in input().split()]

    def combination(n, r, mod):
        n += 1
        r = min(r, n - r)
        numerator, denominator = 1, 1
        for i in range(1, r + 1):
            numerator = (numerator * (n - i)) % mod
            denominator = (denominator * i) % mod
        return numerator * pow(denominator, mod - 2, mod) % mod

    if not (X <= 2 * Y and Y <= 2 * X):
        ans = 0
    else:
        n, m = (-X + 2 * Y) / 3, (2 * X - Y) / 3
        if n.is_integer() and m.is_integer():
            n, m = int(n), int(m)
            ans = combination(n + m, n, 10**9 + 7)
        else:
            ans = 0
    return ans

print(d_knight())

Submission status: Wrong Answer

Solution code:
x,y=map(int,input().split())
m=10**9+7
if (2*x-y)%3==0 and (2*y-x)%3==0 and 2*x-y>0 and 2*y-x>0:
    a,b=(2*x-y)//3,(2*y-x)//3
    c=min(a,b)
    p=1
    for i in range(c):
        p=(p*(a+b-i)*pow(i+1,m-2,m))%m
    print(p)
else:
    print(0)

Submission status: Wrong Answer

Solution code:
x,y=map(int,input().split())
m=10**9+7
if (2*x-y)%3==0 and (2*y-x)%3==0:
    a,b=(2*x-y)//3,(2*y-x)//3
    c=min(a,b)
    p=1
    for i in range(c):
        p=(p*(a+b-i)*pow(i+1,m-2,m))%m
    print(p)
else:
    print(0)

Submission status: Wrong Answer

Solution code:
def d_knight():
    X, Y = [int(i) for i in input().split()]

    def combination(n, r, mod):
        n += 1
        r = min(r, n - r)
        numerator, denominator = 1, 1
        for i in range(1, r + 1):
            numerator = (numerator * (n - i)) % mod
            denominator = (denominator * i) % mod
        return numerator * pow(denominator, mod - 2, mod) % mod

    if not (X <= 2 * Y and Y <= 2 * X):
        return 0

    n, m = (-X + 2 * Y) / 3, (2 * X - Y) / 3
    if not (n.is_integer() and m.is_integer()):
        return 0

    n, m = int(n), int(m)
    return combination(n + m, n, 10**9 + 7)

print(d_knight())

Submission status: Wrong Answer

Solution code:
def com(n,k):
    s=n
    p=10**9+7
    inv=[0,1]
    for c in range(2,k+1):
        inv.append((-(p//c)*inv[p%c])%p)
        s=(((s*(n+1-c))%p)*inv[c])%p
    return s

x,y=map(int,input().split())
if (x+y)%3!=0 or 2*y<x or 2*x<y:
    print(0)
else:
    r=min(2*y-x,2*x-y)//3
    print(com((x+y)//3,r))

Submission status: Wrong Answer

Solution code:
x, y = map(int, input().split())
if (x + y) % 3 == 0:
        n = (2*y - x)//3 
        r = (2*x - y)//3
        mod = 10**9+7
        def inv(x):
                return pow(x, mod-2, mod)
        def fact(x):
                f = 1 
                for i in range(1, x + 1): 
                        f *= i
                        f %= mod    
                return f
        def comb(n, r): 
                return (fact(n) * inv(fact(n-r)) * inv(fact(r))) % mod 
        print(comb(n+r, r)) 
else:
        print(0)

Submission status: Wrong Answer

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

def nCk(n, k, mod=10**9+7):
  
  ans = 1
  for i in range(1, k+1):
    ans = ans*(n-i+1)*pow(i, mod-2, mod)%mod
    
  return ans

ans = 0

if (2*x-y)%3==0 & (2*y-x)%3==0:
  k = (2*x-y)//3
  l = (2*y-x)//3
  
  ans = nCk(k+l, min(k, l))

print(ans)

Submission status: Wrong Answer

Solution code:
x, y = map(int, input().split())
if (x + y) % 3 == 0:
        n = int(x - 2/3*(2*x-y))
        r = int((2*x - y)/3)
        mod = 10**9+7
        def inv(x):
                return pow(x, mod-2, mod)
        def fact(x):
                f = 1 
                for i in range(1, x + 1): 
                        f *= i
                        f %= mod    
                return f
        def comb(n, r): 
                return (fact(n) * inv(fact(n-r)) * inv(fact(r))) % mod 
        print(comb(n+r, r)) 
else:
        print(0)

Submission status: Wrong Answer

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

def nCk(n, k, mod=10**9+7):
  
  ans = 1
  for i in range(1, k+1):
    ans = ans*(n-i+1)*pow(i, mod-2, mod)%mod
    
  return ans

ans = 0

if (2*x-y)%3==0 & (2*y-x)%3==0:
  k = (2*x-y)//3
  l = (2*y-x)//3
  
  ans = nCk(k+l, k)

print(ans)

Submission status: Wrong Answer

Solution code:
def com(n,k,mod):
    r=min(k,n-k)
    s=1
    inv=[1,1]
    for c in range(1,r+1):
        inv.append((-(mod//c)*inv[mod%c])%mod)
        s=(((s*(n+1-c))%mod)*inv[c])%mod
    return s

x,y=map(int,input().split())
if (x+y)%3!=0 or 2*y<x or 2*x<y:
    print(0)
else:
    r=int(min(2*y-x,2*x-y)/3)
    print(com(int((x+y)/3),r,10**9+7))

Submission status: Wrong Answer

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

if (x+y)%3==0 and x<=2*y and y<=2*x:
    a=(x+y)/3
    b=(2*x-y)/3
    a=int(a)
    b=int(b)
    f=[1]
    
    for i in range(1,a+1):
        f.append(f[-1]*i%mod)
    #print(f)
    ans=f[a]//f[b]//f[a-b]  #aCbが答
    if ans>mod:
        ans=ans%mod
else:
    ans=0
print(int(ans))

Submission status: Wrong Answer

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

if (2*x-y)%3 != 0 or (-x+2*y)%3 != 0 or x<2*y or y<2*x:
  print(0)
  exit()
  
a = ((2*x-y)//3)%mod
b = ((-x+2*y)//3)%mod


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

print(cmb(a+b,a)%mod)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
X, Y = map(int, input().split())

mod = 10 ** 9 + 7

a = (2 * Y - X) / 3
b = (2 * X - Y) / 3
if a < 0 or b < 0 or a < 1 and b < 1:
    print(0)
    sys.exit()

a = int(a)
b = int(b)
N = a + b
f = [1]
for i in range(1,a+b+1):
    f.append((f[-1] * i) % mod)
ans = f[a+b] * (pow(f[a], mod-2, mod) * pow(f[b], mod-2, mod) % mod) % mod
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
import math
import scipy
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: Wrong Answer

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

Solution code:
import math
from math import factorial
from operator import mul
from functools import reduce


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

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

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

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


if ((X + Y) %3!=0):
    print(0)
else :
    min_za = min(X, Y)
    max_za = max(X, Y)
    diff_2 = int((min_za * 2-max_za) / 3)
    diff_1 = max_za - diff_2*2
    sum = diff_1 + diff_2
    print(comb(sum,diff_1,10**9+7))