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:
inf = 10**9+7
a = 0
import sys

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 = (result * numerator[k])%inf
    return result

x, y = map(int, input().split())
key = 0
if x == 2*y:
    print(1)
    sys.exit()
if y == 2*x:
    print(1)
    sys.exit()
while x>0 and y>0:
    x, y = x-3, y-3
    key += 1
    if x == 2*y:
        a = 1
        break
    if y == 2*x:
        a = -1
        break

if x < 0 or y < 0:
    print(0)
    sys.exit()
if a == 1:
    print(int(nCr(key*2+y ,key)))
else:
    print(int(nCr(key*2+x ,key)))

Submission status: Wrong Answer

Solution code:
import operator as op
from functools import reduce



def fact(n):
    x = n
    t = 1
    while(x>0):
        t *= x
        t %= (10**9+7)
        x -= 1
    return t



valid = True
n = sorted([int(i) for i in input().split()])
a = n[0]
b = n[1]
x = 0
y = 0

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

if(a>=0 and b>=0 and a%3==0):
    x += a//3
    y += a//3
else:
    valid = False
        
if(valid):
    print ((fact(x+y)*pow(fact(x)*fact(y), 10**9+5, 10**9+7)) % (10**9+7))
else:
    print(0)

Submission status: Wrong Answer

Solution code:
def extgcd(a,b):
    r = [1,0,a]
    w = [0,1,b]
    while w[2]!=1:
        q = r[2]//w[2]
        r2 = w
        w2 = [r[0]-q*w[0],r[1]-q*w[1],r[2]-q*w[2]]
        r = r2
        w = w2
    #[x,y]
    return [w[0],w[1]]
    
def mod_inv(a,m):
    x = extgcd(a,m)[0]
    return (m+x%m)%m
    
X,Y = list(map(int,input().split()))

# a+2b = X
# 2a+b = Y を解く
# -> a = (2Y-X)/3, b = (2X-Y)/3
# (i+1,j+2) の移動が a 回
# (i+2,j+1) の移動が b 回

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

if not a.is_integer() or not b.is_integer():
    print(0)
    exit(0)

# a回とb回の移動の組み合わせは (a+b)!/a!b!
m = 10**9+7
res = 1
for i in range(1,int(a+b)+1):
    res = res*i%m
for i in range(1,int(a)+1):
    res = res*mod_inv(i,m)%m
for i in range(1,int(b)+1):
    res = res*mod_inv(i,m)%m
print(res)

Submission status: Wrong Answer

Solution code:
import sys

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

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

if n1 == 0 and n2 == 0:
    print(0)
    sys.exit()

if n1 % 3 != 0 or n2 % 3 != 0:
    print(0)
    sys.exit()
else:
    n1 = n1 // 3
    n2 = n2 // 3



P = 10**9 + 7
N = 10 ** 6
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(1, 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:
def extgcd(a,b):
    r = [1,0,a]
    w = [0,1,b]
    while w[2]!=1:
        q = r[2]//w[2]
        r2 = w
        w2 = [r[0]-q*w[0],r[1]-q*w[1],r[2]-q*w[2]]
        r = r2
        w = w2
    return [w[0],w[1]]

def mod_inv(a,m):
    x = extgcd(a,m)[0]
    return (m+x%m)%m

X, Y=map(int, input().split())
 
def f(x, y):
  s=max(x, y)
  t=min(x, y)
  st=s+t
  ans=1
  for i in range(1, t+1):
    ans=ans*(st+1-i)//i
    ans=ans%(10**9+6)
    
  return ans
  
      
b=(2*X-Y)//3
btemp=(2*X-Y)%3
if btemp>0:
  ans=0
else:
  a=(Y-b)//2
  
  #ans=mt.factorial(a+b)//(mt.factorial(a)*mt.factorial(b))
  #ans=tool.permutations(a+b)//(tool.permutations(a)*tool.permutations(b))
  #s=max(a, b)
  #t=min(a, b)
  #ans=comb(s+t, t, 10**9+7)
  m=10**9+7
  ans=1
  for i in range(1, a+b+1):
    ans=ans*i%m
  for i in range(1, a+1):
    ans=ans*mod_inv(i, m)%m
  for i in range(1, b+1):
    ans=ans*mod_inv(i, m)%m
print(ans)

Submission status: Wrong Answer

Solution code:
import sys


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):
        # 階乗のリストと階乗のmod逆元のリストを返す O(n)
        # self.make_modinv_list()が先に実行されている必要がある
        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):
        # 0からnまでのmod逆元のリストを返す O(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


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

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

if w.is_integer():
    w = int(w)
else:
    print(0)
    sys.exit()

a = min(b, w-b)
comb = Combination(10**6)
ans = comb(w, a)
print(ans)

Submission status: Wrong Answer

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


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

n=a+b

p1=1
p2=1
p3=1

for i in range(n):
    p1*=(n+1)%mod

for i in range(max(a,b)):
    p2*=pow(i+1,mod-2,mod)

    if i==b-1:
        p3=p2

if a+2*b==x and 2*a+b==y:
    print(p1*p2*p3)
else:
    print(0)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
A = [int(s) for s in input().split()]
X, Y = A[0], A[1]

def kaizyou(n):
    s = 1
    for i in range(2,n+1):
        s*=i
    return s
def c(n,r):
    s = 1
    for i in range(n-r,n+1):
        s *= i
    return s/kaizyou(n-r)

def count(X,Y):
    return c(int((X+Y)/3),X-int((X+Y)/3))%(10**9+7)

if X>=0 and Y>= 0 and Y<=2*X and Y>=0.5*X and (X+Y)%3 == 0:
    print(int(count(X,Y)))
else:
    print(0)

Submission status: Wrong Answer

Solution code:
a = list(map(int, input().split()))
import sys
sys.setrecursionlimit(100000)

if (2*a[0]- a[1])%3 != 0:
    print(0)
else:
    if (2*a[1] - a[0])%3 != 0:
        print(0)
    else:
        x = (2*a[1] - a[0])//3
        y = (2*a[0]- a[1])//3
        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(x+y,x))%(10**9 + 7))

Submission status: Wrong Answer

Solution code:
inf = 10**9+7

import sys

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 = (result * numerator[k])%inf
    return result

x, y = map(int, input().split())
key = 0
if x == 2*y:
    print(1)
    sys.exit()
if y == 2*x:
    print(1)
    sys.exit()
while x>0 and y>0:
    x, y = x-3, y-3
    key += 1
    if x == 2*y:
        a = 1
        break
    if y == 2*x:
        a = -1
        break
a = 0
if x < 0 or y < 0:
    print(0)
    sys.exit()
if a == 1:
    print(int(nCr(key*2+y ,key)))
else:
    print(int(nCr(key*2+x ,key)))

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
C21 = 0
C12 = 0

ans = 0
if (N) % 3 != 0 or X >= 2*Y or Y >= 2*X:
  print(ans)
else:
  while N != 0:
    if X >= 333333 and Y >= 333333:
      C21 += 111111
      C12 += 111111
      X -= 333333
      Y -= 333333
      N -= 666666
    elif X >= Y:
      C21 += 1
      X -= 2
      Y -= 1
      N -= 3
    else:
      C12 += 1
      X -= 1
      Y -= 2
      N -= 3

a = cmb(C21 + C12, C21)
print(a % (10**9 + 7))

Submission status: Wrong Answer

Solution code:
if __name__=='__main__':
    x,y = map(int,input().split())
    x0 = (2.0*x-y)/3.0
    y0 = (2.0*y-x)/3.0
    if x0<0 or y0<0 or not x0.is_integer() or not y0.is_integer():
        ans = 0
    elif x0==0 and y0==0:
        ans = 1
    else:
        x0,y0=map(int,[x0,y0])
        ans = 1
        for i in range(max(x0,y0)+1,x0+y0+1):
            ans = ans*i//(i-max(x0,y0)) %(10e9+7)
    print(int(ans))

Submission status: Wrong Answer

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)

Submission status: Wrong Answer

Solution code:
import math

N = 10 ** 9 + 7
X, Y = map(int, input().split())
B3 = 2 * X - Y
if B3 % 3:
    print(0)
    exit()
B = B3 // 3
A = X - 2 * B

# count = 1
# for i in range(A + 1, A + B + 1):
#     count *= i
# for i in range(1, A + 1):
#     count //= i
# print(count % N)

# def combinations_count(n, r):
#     return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
#
# print(combinations_count(A + B, A) % N)

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

Submission status: Wrong Answer

Solution code:
def comb(n, k):
    m = 1
    if n < 2 * k:
        k = n - k
    for i in range(1, k + 1):
        m = int(m * (n - i + 1) // i)    
    return m
x,y = map(int,input().split())
ans = 0
for i in range(x):
    if 2*(x-i) == y+i:
        ans = comb(x-i,i)
        print(comb(x-i,i))
print(int(ans//1000000007))

Submission status: Wrong Answer

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

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

mod = 10**9 + 7

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

x_ = max(x, y)
y = min(x, y)
x = x_

cnt_x = 0
while 2*x > y:
    x -= 2
    y -= 1
    cnt_x += 1



if 2*x == y:
    cnt_y = x

    n = cnt_x + cnt_y 
    k = cnt_y
    print(comb(n, k, mod))

else:
    print(0)

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())
if (x + y) % 3 == 0:
    n = (x + y) // 3
    k = x - n
    print(cmb(n, k) % (10**9 + 7))
else:
    print(0)

Submission status: Wrong Answer

Solution code:
import math
import sys


def Knight():
    def check(d):
        if not (d[0] % 3 == 0 and d[1] % 3 == 0) or (d[0] % 3 == 1 and d[1] % 3 == 2) or (d[0] % 3 == 2 and d[1] % 3 == 1):
            print(0)
            sys.exit()
    d = list(map(int, input().split()))
    check(d)

    x = d[0]
    y = d[1]
    diff = x - y if x > y else y - x  # aとbの回数の差
    d2 = [x - diff, y - diff * 2] if x < y else [x - diff * 2, y - diff]
    r = d2[0] // 3

    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**8
    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(r*2+diff, r, mod)

    print(a)


Knight()

Submission status: Wrong Answer

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

if not(-(-x//2) <= y and y <= x*2):
    print(0)
    exit()

flag = True

count = 0
while flag:
    count += 1
    x += 1
    y -= 1

    if y*2 == x: # yC0
        print(cmb(y, count)%1000000007)
        exit()
    if y*2 < x: # ない
        print(0)
        exit()

Submission status: Wrong Answer

Solution code:

X, Y = map(int, input().split())
num = max(X, Y) - ((max(X, Y) - min(X, Y)) * 2)
mod = 10 ** 9 + 7
print(num)
if num >= 0 and num % 3 == 0:
    num2 = num // 3
    a = num2
    b = num2 + max(X, Y) - min(X, Y)
    print(a, b)
    if a == 0:
        print(1)
    else:
        datalist = [[0 for i in range(a)] for j in range(b)]
        datalist[0][0] = 1
        for i in range(0, len(datalist)):
            for j in range(0, len(datalist[i])):
                if i == 0 and j == 0:
                    continue
                elif i == 0:
                    datalist[i][j] += datalist[i][j-1]
                elif j == 0:
                    datalist[i][j] += datalist[i-1][j]
                else:

                    datalist[i][j] += datalist[i - 1][j] + datalist[i][j-1]
        print(datalist[a-1][b-1] % mod)
else:
    print(0)

Submission status: Wrong Answer

Solution code:
import itertools
import sys
from math import factorial
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())
  
i = (2/3)*X - (1/3)*Y
j = (2/3)*Y - (1/3)*X

if i%1 != 0 or j%1 != 0:
  print(0)
  sys.exit()

n = i + j

a = cmb(int(n),int(i))#factorial(n) / factorial(i) / factorial(n - i)
print(int(a)%1000000007)

Submission status: Wrong Answer

Solution code:
def nCr(n, r):

    
    r = min(r, n-r)

    numerator = 1
    for i in range(n, n-r, -1):
        numerator =numerator*i%(10**9+7)
        if numerator==0:
          numerator=1

    denominator = 1
    for i in range(r, 1, -1):
        denominator =denominator*i%(10**9+7)
        if denominator==0:
          denominator=1

    return numerator // denominator%(10**9+7)
a,s=map(int,input().split())
x=(a-2*s)//(-3)
y=(s-2*a)//(-3)
v=(a-2*s)/(-3)
v2=(s-2*a)/(-3)
if x!=v or y!=v2:
  print("0")
else:
  d=nCr(x+y,x)
  print(d%(10**9+7))

Submission status: Wrong Answer

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

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

for i in range(X + 1):
    x = X - i
    y = Y - i * 2
    if x / 2 == y:
        print(comb((y+i), min(y, i), (10**9)+7))
        exit()
print(-1)

Submission status: Wrong Answer

Solution code:
import math

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

if((2*Y-X)%3 != 0 or (2*X-Y)%3 != 0):
    print("0")
else:
    a =  int((2*Y-X) / 3)
    b =  int((2*X-Y) / 3)


    numerator = [b + k + 1 for k in range(a)]
    denominator = [k + 1 for k in range(a)]

    for p in range(2,a+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (b) % p
            for k in range(p-1,a,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(a):
        if numerator[k] > 1:
            result *= int(numerator[k])

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

Submission status: Wrong Answer

Solution code:
# n+2m=i
# 2n+m=j
# (4n+2m=2j)
# n=(2j-i)/3
# m=(2i-j)/3
# n+m C n (n+m)!/n!/m!

MOD = 10**9+7
MAX = 10**6+5
fac = [0]*MAX
inv = [0]*MAX
finv = [0]*MAX
def COMinit():
    fac[0]=1
    fac[1]=1
    finv[0]=1
    finv[1]=1
    inv[1]=1
    for i in range(2,MAX):
        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):
    return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD

x,y=list(map(int,input().split()))
if (2*y-x)%3!=0 or (2*x-y)%3!=0:
    print(0)
else:
    n=(2*y-x)//3
    m=(2*x-y)//3
    COMinit()
    print(COM(n+m,n))

Submission status: Wrong Answer

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

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

N = 10**6
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

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

if X>Y:
    if X % 2 == 0:
        if Y - X//2 == 0:
            print(1)
            exit()
        else:
            print(0)
            exit()
    else:
        if Y - X//2 == 2:
            print(X//2)
            exit()
        else:
            print(0)
            exit()

elif X<Y:
    if Y % 2 == 0:
        if X - Y//2 == 0:
            print(1)
            exit()
        else:
            print(0)
            exit()

    else:
        if X - Y//2 == 0:
            print(Y//2)
            exit()
        else:
            print(0)
            exit()
        
else:
    if X % 3 == 0:
        #ans = math.factorial(2*(X/3)) // (math.factorial(2*(X/3) - X/3) * math.factorial(X/3))
        #print(ans%mod)
        print(cmb(2*(X//3),X//3,mod))
        exit()
    else:
        print(0)
        exit()

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(100000)

target_x,target_y = map(int,input().split())

if (target_x+target_y)%3 != 0:
    print(0)

COUNTER = 0
def dfs(x,y):
    if x == 0 and y == 0:
        global COUNTER
        COUNTER +=1
    elif x < 0 or y < 0:
        return 0

    x1 = x-1
    y1 = y-2
    #print(x1)
    dfs(x1,y1)

    x2 = x-2
    y2 = y-1
    dfs(x2,y2)

dfs(target_x,target_y)
mod = 10**9+7
print(COUNTER%mod)

Submission status: Wrong Answer

Solution code:
import sys

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

dp = {}
dp[(0, 0)] = 1
for i in range(3, x+y+1):
    for j in range(i//2):
        x = j
        y = i-j

Submission status: Wrong Answer

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

if ((2*Y-X)%3 != 0) or ((2*X-Y)%3 != 0) or (2*Y-X) < 0 or (2*X-Y) < 0:
    print(0)
elif 2 *Y == X or 2 * X == Y:
    print(1)
else:
    x = (2*Y-X) // 3
    y = (2*X-Y) // 3
    fac_list = [None for _ in range(x+y+2)]
    inv_fac_list = [None for _ in range(x+y+2)]

    fac_list[0] = 1
    for i in range(1, x+y+2):
        print(i)
        fac_list[i] = i * fac_list[i-1] % MOD

    inv_fac_list[x+y+1] = pow(fac_list[x+y+1],(MOD - 2), MOD)
    for i in range(x+y, 0, -1):
        inv_fac_list[i] = inv_fac_list[i+1] * (i+1) % MOD

    print((fac_list[x+y] * inv_fac_list[x] * inv_fac_list[y]) % MOD)

Submission status: Wrong Answer

Solution code:
x,y=map(int,input().split())
s=(x+y)//3
if (x+y)%3!=0 or (x-s)*(y-s)<=0:
  print(0)
  exit()
x,y=x-s,y-s
x,y=min(x,y),max(x,y)
#print(x,y)

def extgcd(a,b):
    r = [1,0,a]
    w = [0,1,b]
    while w[2]!=1:
        q = r[2]//w[2]
        r2 = w
        w2 = [r[0]-q*w[0],r[1]-q*w[1],r[2]-q*w[2]]
        r = r2
        w = w2
    return [w[0],w[1]]
def mod_inv(a,m):
    x = extgcd(a,m)[0]
    return (m+x%m)%m
m = 10**9+7
res = 1
for i in range(1,x+y+1):
    res = res*i%m
for i in range(1,x+1):
    res = res*mod_inv(i,m)%m
    res = res*mod_inv(i,m)%m
for i in range(x+1,y+1):
    res = res*mod_inv(i,m)%m
print(res)

Submission status: Wrong Answer

Solution code:
import math

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

if((2*Y-X)%3 != 0 or (2*X-Y)%3 != 0):
    print("No")
else:
    a =  int((2*Y-X) / 3)
    b =  int((2*X-Y) / 3)


    numerator = [b + k + 1 for k in range(a)]
    denominator = [k + 1 for k in range(a)]

    for p in range(2,a+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (b) % p
            for k in range(p-1,a,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(a):
        if numerator[k] > 1:
            result *= int(numerator[k])

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

Submission status: Wrong Answer

Solution code:
def combinations_count(n, r):
    if r < n - r:
        t = r
    else:
        t = n - r
    
    ans= 1
    for i in range(t):
        ans = (ans * (n - i) // (i + 1)) % (10 ** 9 + 7)
    return(ans)
X, Y = map(int, input().split())

if (X+Y)%3 == 0 and X < 2*Y and Y < 2 * X:
    print(combinations_count((X+Y)//3, (2*X-Y)//3))
else:
    print("0")

Submission status: Wrong Answer

Solution code:
import operator as op
from functools import reduce



def fact(n):
    x = n
    t = 1
    while(x>0):
        t *= x
        t %= (10**9+7)
        x -= 1
    return t



valid = True
n = sorted([int(i) for i in input().split()])
a = n[0]
b = n[1]
x = 0
y = 0

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

if(a>0 and b>0 and a%3==0):
    x += a//3
    y += a//3
else:
    valid = False
        
if(valid):
    print ((fact(x+y)*pow(fact(x)*fact(y), 10**9+5, 10**9+7)) % (10**9+7))
else:
    print(0)

Submission status: Wrong Answer

Solution code:
import sys
mod = 10**9+7
X, Y = map(int, input().split())
if (X+Y) % 3 != 0:
	print(0)
	sys.exit()

tot = (X+Y) // 3

y = abs(tot-X)
x = tot - y

if Y > 2*x or X > 2*y:
	print(0)
	sys.exit()

if x == 0 or y == 0:
	print(1)
	sys.exit()

ans = 1
for i in range(y+1, tot+1):
	ans *= i
	ans %= mod

for i in range(1,x+1):
	ans *= pow(i, mod-2, mod)
	ans %= mod

print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
A = [int(s) for s in input().split()]
X, Y = A[0], A[1]

def kaizyou(n):
    s = 1
    for i in range(2,n+1):
        s*=i
    return s
def c(n,r):
    s = 1
    for i in range(n-r,n+1):
        s *= i
    return s/kaizyou(n-r)

def count(X,Y):
    return c(int((X+Y)/3),X-int((X+Y)/3))%(10**9+7)

if Y<=2*X and Y>=0.5*X and (X+Y)%3 == 0:
    print(int(count(X,Y)))
else:
    print(0)

Submission status: Wrong Answer

Solution code:
import math
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


target_x, target_y = map(int, input().split())
max_times_of_two = math.floor(target_x / 2)
times_of_two = max_times_of_two
if target_x % 2 == 0:
    times_of_one = 0
else:
    times_of_one = 1
while (True):
    if times_of_two * 1 + times_of_one * 2 == target_y:
        # print("OK")
        break
    elif times_of_two * 1 + times_of_one * 2 > target_y:
        print("0")
        exit(0)
    else:
        times_of_two -= 1
        times_of_one += 2

# print("times_of_one:", times_of_one)
# print("times_of_two:", times_of_two)
print(combinations_count(times_of_two + times_of_one, times_of_two) % 1000000007)

Submission status: Wrong Answer

Solution code:
x,y=map(int,input().split())
s=(x+y)//3
if (x+y)%3!=0 or (x-s)*(y-s)<=0:
  print(0)
  exit()
x,y=x-s,y-s
x,y=min(x,y),max(x,y)
print(x,y)

def extgcd(a,b):
    r = [1,0,a]
    w = [0,1,b]
    while w[2]!=1:
        q = r[2]//w[2]
        r2 = w
        w2 = [r[0]-q*w[0],r[1]-q*w[1],r[2]-q*w[2]]
        r = r2
        w = w2
    return [w[0],w[1]]
def mod_inv(a,m):
    x = extgcd(a,m)[0]
    return (m+x%m)%m
m = 10**9+7
res = 1
for i in range(1,x+y+1):
    res = res*i%m
for i in range(1,x+1):
    res = res*mod_inv(i,m)%m
    res = res*mod_inv(i,m)%m
for i in range(x+1,y+1):
    res = res*mod_inv(i,m)%m
print(res)

Submission status: Wrong Answer

Solution code:
import sys
G = list(map(int, input().split()))
total = G[0] + G[1]
if total % 3 != 0:
  print(0)
  sys.exit(0)

total //= 3
dis = abs(G[0] - total)

mod = 10 ** 9 + 7
fact = [1]
fact_inv = [1]
for i in range(10**6):
    new_fact = fact[-1]*(i+1)%mod
    fact.append(new_fact)
    fact_inv.append(pow(new_fact,mod-2,mod))

def mod_comb_k(n,k,mod):
    result = fact[n] % mod
    result *= fact_inv[k] % mod
    result %= mod
    result *= fact_inv[n-k] % mod
    result %= mod
    return result

print(mod_comb_k(total, dis, mod))

Submission status: Wrong Answer

Solution code:
import sys


def alg_combination_mod(n, r, mod):
    r = min(n - r, r)
    if r == 0:
        return 1
    else:
        denominator = 1
        for i in range(n, n - r, -1):
            denominator = (denominator * i) % mod
        molecule = 1
        for i in range(1, r + 1):
            molecule = (molecule * i) % mod
        return denominator * pow(molecule, mod - 2, mod) % mod


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    x, y = list(map(int, readline().split()))
    xcnt = 0
    ycnt = 0
    cnt = min(x // 3, y // 3)
    if x / y == 2 or y / x == 2:
        print(1)
        exit()
    else:
        x -= cnt * 3
        y -= cnt * 3
        if x == 0 and y == 0:
            xcnt = cnt
            ycnt = cnt
        elif x != 0 and y / x == 2:
            xcnt = cnt
            ycnt = cnt + x
        elif y != 0 and x / y == 2:
            xcnt = cnt + y
            ycnt = cnt
        else:
            print(0)
            exit()
    print((alg_combination_mod(xcnt + ycnt, xcnt, mod) * alg_combination_mod(ycnt, ycnt, mod)) % mod)


if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

Solution code:
X, Y = map(int, input().split())
A = max(X, Y)
cnt = 0
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

for i in range(A//2+1):
    x = X - i
    y = Y - 2*i
    if x/2 == y:
        print(cmb(max(x, y), min(x, y)) % (10**9 + 7))
        exit()
print(0)

Submission status: Wrong Answer

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

chk = False
ct = 0
tx = X
ty = X * 2
for i in range(X+1):
    if tx == X and ty == Y:
        chk = True
        ct = i
        break
    ty -= 3
    if ty < Y:break
if not chk:
    print(0)
    exit()

p = X - (ct*2)
q = ct
#print(p,q)

md = 1000000007
r1 = 1
qn = 2
for i in range(p+1,(p+q)+1):
    r1 *= i
    if (r1 // qn) * qn == r1:
        r1 = r1 // qn
        if qn != 1:
            qn += 1
            if qn == q+1:
                qn = 1
    if qn == 1:
        r1 = r1 % md
print(r1)

Submission status: Wrong Answer

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

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

mod = 10**9 + 7

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

x_ = max(x, y)
y = min(x, y)
x = x_

cnt_x = 0
while 2*x > y:
    x -= 2
    y -= 1
    cnt_x += 1



if 2*x == y:
    cnt_y = x

    n = cnt_x + cnt_y -1
    k = cnt_y
    print(comb(n, k, mod)*2)

else:
    print(0)

Submission status: Wrong Answer

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

a = x+y

if a % 3 != 0:
    print(0)

else:
    #2の数
    c = x % (a//3)
    #1の数
    b = a//3 -c

    if c ==0:
        print(1)
    else:
        d = math.factorial(a//3) //(math.factorial(b)*math.factorial(c))
        print(int(d%(10**9 +7)))