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:
X, Y = map(int,input().split())

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

    mod = 10 ** 9 + 7
    k = total//2+diff

    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=list(map(int,input().split()))

import sys
if (2*Y-X)%3!=0 or (2*X-Y)%3!=0:
  print(0)
  sys.exit()
if 2*Y-X<0 or 2*X-Y<0:
  print(0)
  sys.exit()

x=(2*Y-X)//3
y=(2*X-Y)//3
#(x+y)Cxを求める
fac=[0 for i in range(x+y+1)]
inv=[0 for i in range(x+y+1)]
finv=[0 for i in range(x+y+1)]
#初期条件
p=1000000007
fac[0]=fac[1]=1
inv[1]=1
finv[0]=finv[1]=1
#テーブルの作成
for i in range(2,x+y+1):
  fac[i]=fac[i-1]*i%p
  #p=(p//a)*a+(p%a) a^(-1)=-(p//a)*(p%a)^(-1)
  inv[i]=(-(p//i)*inv[p%i])%p
  finv[i]=finv[i-1]*inv[i]%p
#求める
print(x+y)
print(x)
print(y)

print((fac[x+y]*finv[x]%p)*finv[y]%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()

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

ifact = 1
for i in range(2, m+1):
    ifact = (ifact * i) % mod
ifact = pow(ifact, mod-2, mod)
fact = 1
for i in range(a+b, a+b-m, -1):
    fact = (fact * i) % mod

print(fact*ifact % mod)

Submission status: Wrong Answer

Solution code:
def ex_euclid(a, b):
  x0, x1 = 1, 0
  y0, y1 = 0, 1
  z0, z1 = a, b
  
  while z1 != 0:
    q = z0 // z1
    z0, z1 = z1, z0 % z1
    x0, x1 = x1, x0 - q * x1
    y0, y1 = y1, y0 - q * y1
  
  return z0, x0, y0

def mod_inv(a, n):
  g, x, _ = ex_euclid(a, n)
  if g != 1:
    print("modular inverse does not exist")
  else:
    return x % n

def mod_factorial(x, modulo):
  ans = 1
  for i in range(1, x+1):
    ans *= i
    ans %= modulo
  return ans

X, Y = map(int, input().split())
M = 10 ** 9 + 7
a, b = (2*X-Y)/3, (2*Y-X)/3
if a%1 == 0 and b%1 == 0:
  a, b = int(a), int(b)
  answer = 1
  answer *= mod_factorial(a+b, M)
  answer *= mod_inv(mod_factorial(a, M), M)
  answer %= M
  answer *= mod_inv(mod_factorial(b, M), M)
  answer %= M
  print(answer)
else:
  print(0)

Submission status: Wrong Answer

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

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

diff = abs(x - y)
ref = (min(x, y) - diff)//3
total = ref*2 + diff
mod = 10**9 + 7
ans = 1

for i in range(min(ref, total - ref)):
    ans = ans*(total - i)%mod
    ie = pow((i + 1), (mod - 2), mod)
    ans = ans*ie%mod

print(ans)

Submission status: Wrong Answer

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

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

diff = abs(x - y)
ref = (min(x, y) - diff)//3
total = ref*2 + diff
mod = 10**9 + 7
ans = 1

for i in range(min(ref, total - ref)):
    ans = ans*(total - i)%mod
    ie = pow((i + 1), (mod - 2))%mod
    ans = ans*ie%mod

print(ans)

Submission status: Wrong Answer

Solution code:

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

n = int((-4*X+5*Y)/3)
m = int((2*X-Y)/3)

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

elif n<0 or m<0:
    print(0)

#コンビネーションを何回も計算する問題で使える関数
MAXN = (10**6)+10
MOD = 10**9 + 7
f = [1]
for i in range(MAXN):
    f.append(f[-1] * (i+1) % MOD)
def nCr(n, r, mod=MOD):
    return f[n] * pow(f[r], mod-2, mod) * pow(f[n-r], mod-2, mod) % mod


print(nCr(n+m,n,10**9 + 7))

Submission status: Wrong Answer

Solution code:

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

n = int((-4*X+5*Y)/3)
m = int((2*X-Y)/3)

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

elif n<0 or m<0:
    print(0)

else:
    #コンビネーションその1(速い)
    def comb(n,m,p=10**9+7):
        if n < m : return 0
        if n < 0 or m < 0:return 0
        m = min(m, n-m)
        top = bot = 1
        for i in range(m):
            top = top*(n-i) % p
            bot = bot*(i+1) % p
        bot = pow(bot, p-2, p)
        return top*bot % p

    print(comb(n+m,n) % (10**9 + 7))

Submission status: Wrong Answer

Solution code:
def product(n, r):
    S = max(r, 1)
    while n > r:
        S *= n
        n -= 1
    return S
def C(n,r):
    return(product(n,r)//product(n-r,1))
X, Y = map(int, input().split())
k = (X + Y) % 3
if k != 0:
    print(0)
else:
    k = (X + Y) // 3
    l = abs(X-2*k)
    print(C(k,l)%(10**9+7))

Submission status: Wrong Answer

Solution code:
fact = [1 for _ in range(1000000)]
inv = [1 for _ in range(1000000)]
fact_inv = [1 for _ in range(1000000)]

P = 10**9+7
for i in range(2, 1000000):
    fact[i] = (fact[i-1]*i) % P
    inv[i] = P - (inv[P % i] * (P // i)) % P
    fact_inv[i] = (fact_inv[i-1] * inv[i]) % P

X, Y = map(int, input().split())
res = 0
if (X+Y) % 3 == 0:
    a = (-X+2*Y) // 3
    b = (2*X-Y) // 3
    res = fact[a+b] * ((fact_inv[a] * fact_inv[b]) % P) % P
print(res)

Submission status: Wrong Answer

Solution code:
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**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 )

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

if diff > 0:
    x -= diff*2
    y -= diff
else:
    y -= diff*2
    x -= diff

if x%3 == 0:
    temp = x//3
    total = diff + temp*2
    ans = cmb(total, temp, mod)
else:
    ans = 0

print(ans)

Submission status: Wrong Answer

Solution code:
# 73

MOD = 10**9 + 7
x, y = map(int, input().split())

a = 2*y - x
b = 2*x - y

fac_l = [0] * (int((a + b) / 3) + 1)
inv_l = [0] * (int((a + b) / 3) + 1)
finv_l = [0] * (int((a + b) / 3) + 1)


def com_init():
    fac_l[1] = 1
    inv_l[0] = 1
    inv_l[1] = 1
    finv_l[0] = 1
    finv_l[1] = 1
    for i in range(2, a+b+1):
        fac_l[i] = (fac_l[i-1] * i) % MOD
        inv_l[i] = MOD - (inv_l[MOD % i] * int(MOD / i)) % MOD
        finv_l[i] = (finv_l[i-1] * inv_l[i]) % MOD

def ncr(n, r):
    return (fac_l[n] * (finv_l[r] * finv_l[n-r]) % MOD) % MOD


if a % 3 != 0 or b % 3 != 0 or a > 0 or b > 0:
    print("0")
else:
    a = int(a/3)
    b = int(b/3)

    com_init()
    print(ncr(a+b, a))

Submission status: Wrong Answer

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

import sys
if X + Y % 3 == 0:
    print(0)
    sys.exit()
offset = (X+Y)//3
X, Y = X-offset, Y-offset

if X<0 or Y<0:
    print(0)
    sys.exit()
    
X, Y = max(X, Y), min(X, Y)

def C(n, r, mod):
    num = 1
    den = 1
    for i in range(r):
        num*=n-i
        num%=mod
        den*=i+1
        den%=mod
    return (num*pow(den, mod-2, mod))%mod

print(C(X+Y, Y, mod))

Submission status: Wrong Answer

Solution code:
class Combination:
    '''mod上の
    計算量：階乗・逆元テーブルの作成O(N)
    nCkを求めるO(1)'''
 
    def __init__(self, n, mod):
        self.fact = [1]
        for i in range(1, n + 1):
            self.fact.append(self.fact[-1] * i % mod)
        self.inv_fact = [pow(self.fact[i], mod - 2, mod) for i in range(n + 1)]
        self.mod = mod
 
    def factorial(self, k):
        """k!を求める O(1)"""
        return self.fact[k]
 
    def inverse_factorial(self, k):
        """k!の逆元を求める O(1)"""
        return self.inv_fact[k]
 
    def permutation(self, k, r):
        """kPrを求める O(1)"""
        if k < r:
            return 0
        return (self.fact[k] * self.inv_fact[r]) % self.mod
 
    def combination(self, k, r):
        """kCrを求める O(1)"""
        if k < r:
            return 0
        return (self.fact[k] * self.inv_fact[k - r] * self.inv_fact[r]) % self.mod

    def combination_large(self, k, r):
        """kCrを求める O(r) kが大きいが、r <= nを満たしているときに使用"""
        if k < r:
            return 0
        res = 1
        for l in range(r):
            res *= (k - l)
            res %= self.mod
        return (res * self.inv_fact[r]) % self.mod

x, y = map(int, input().split())
mod = 10**9 + 7
comb = Combination(10**6,mod)

if (x+y)%3 != 0:
    print(0)
    exit(0)
i = (2*x-y)//3
j = (2*y-x)//3
print(comb.combination(i+j, i))

Submission status: Wrong Answer

Solution code:
class Combination:
    """階乗とその逆元のテーブルをO(N)で事前作成し、組み合わせの計算をO(1)で行う"""
    def __init__(self, n, mod):
        self.fact = [1]
        for i in range(1, n + 1):
            self.fact.append(self.fact[-1] * i % mod)
        self.inv_fact = [0] * (n + 1)
        self.inv_fact[n] = pow(self.fact[n], mod - 2, mod)
        for i in reversed(range(n)):
            self.inv_fact[i] = self.inv_fact[i + 1] * (i + 1) % mod
        self.mod = mod

    def factorial(self, k):
        """k!を求める O(1)"""
        return self.fact[k]

    def inverse_factorial(self, k):
        """k!の逆元を求める O(1)"""
        return self.inv_fact[k]

    def permutation(self, k, r):
        """kPrを求める O(1)"""
        if k < r:
            return 0
        return (self.fact[k] * self.inv_fact[k - r]) % self.mod

    def combination(self, k, r):
        """kCrを求める O(1)"""
        if k < r:
            return 0
        return (self.fact[k] * self.inv_fact[k - r] * self.inv_fact[r]) % self.mod

    def combination_large(self, k, r):
        """kCrを求める O(r) kが大きいが、r <= nを満たしているときに使用"""
        if k < r:
            return 0
        res = 1
        for l in range(r):
            res *= (k - l)
            res %= self.mod
        return (res * self.inv_fact[r]) % self.mod


x, y = map(int, input().split())
mod = 10**9 + 7
comb = Combination(10**6,mod)

if (x+y)%3 != 0:
    print(0)
    exit(0)
i = (2*x-y)//3
j = (2*y-x)//3
print(comb.combination(i+j, i))

Submission status: Wrong Answer

Solution code:
class Combination:
    """階乗とその逆元のテーブルをO(N)で事前作成し、組み合わせの計算をO(1)で行う"""
    def __init__(self, n, mod):
        self.fact = [1]
        for i in range(1, n + 1):
            self.fact.append(self.fact[-1] * i % mod)
        self.inv_fact = [0] * (n + 1)
        self.inv_fact[n] = pow(self.fact[n], mod - 2, mod)
        for i in reversed(range(n)):
            self.inv_fact[i] = self.inv_fact[i + 1] * (i + 1) % mod
        self.mod = mod

    def factorial(self, k):
        """k!を求める O(1)"""
        return self.fact[k]

    def inverse_factorial(self, k):
        """k!の逆元を求める O(1)"""
        return self.inv_fact[k]

    def permutation(self, k, r):
        """kPrを求める O(1)"""
        if k < r:
            return 0
        return (self.fact[k] * self.inv_fact[k - r]) % self.mod

    def combination(self, k, r):
        """kCrを求める O(1)"""
        if k < r:
            return 0
        return (self.fact[k] * self.inv_fact[k - r] * self.inv_fact[r]) % self.mod

    def combination_large(self, k, r):
        """kCrを求める O(r) kが大きいが、r <= nを満たしているときに使用"""
        if k < r:
            return 0
        res = 1
        for l in range(r):
            res *= (k - l)
            res %= self.mod
        return (res * self.inv_fact[r]) % self.mod


x, y = map(int, input().split())
mod = 10**9 + 7
comb = Combination(10**6,mod)

if (2*x-y) % 3 != 0 or (2*y-x) % 3 != 0:
    print(0)
    exit(0)
i = (2*x-y)//3
j = (2*y-x)//3
print(comb.combination(i+j, i))

Submission status: Wrong Answer

Solution code:
class Combination:
    """階乗とその逆元のテーブルをO(N)で事前作成し、組み合わせの計算をO(1)で行う"""
    def __init__(self, n, mod):
        self.fact = [1]
        for i in range(1, n + 1):
            self.fact.append(self.fact[-1] * i % mod)
        self.inv_fact = [0] * (n + 1)
        self.inv_fact[n] = pow(self.fact[n], mod - 2, mod)
        for i in reversed(range(n)):
            self.inv_fact[i] = self.inv_fact[i + 1] * (i + 1) % mod
        self.mod = mod

    def factorial(self, k):
        """k!を求める O(1)"""
        return self.fact[k]

    def inverse_factorial(self, k):
        """k!の逆元を求める O(1)"""
        return self.inv_fact[k]

    def permutation(self, k, r):
        """kPrを求める O(1)"""
        if k < r:
            return 0
        return (self.fact[k] * self.inv_fact[k - r]) % self.mod

    def combination(self, k, r):
        """kCrを求める O(1)"""
        if k < r:
            return 0
        return (self.fact[k] * self.inv_fact[k - r] * self.inv_fact[r]) % self.mod

    def combination_large(self, k, r):
        """kCrを求める O(r) kが大きいが、r <= nを満たしているときに使用"""
        if k < r:
            return 0
        res = 1
        for l in range(r):
            res *= (k - l)
            res %= self.mod
        return (res * self.inv_fact[r]) % self.mod


x, y = map(int, input().split())
mod = 10**9 + 7
comb = Combination(x+y,mod)

if (2*x-y) % 3 != 0 or (2*y-x) % 3 != 0:
    print(0)
    exit(0)
i = (2*x-y)//3
j = (2*y-x)//3
print(comb.combination(i+j, i))

Submission status: Wrong Answer

Solution code:
def comb(n, k, mod):
    a = 1
    b = 1
    for i in range(k):
        a = a * (n-i) % mod
        b = b * (i+1) % mod
    return a * pow(b, mod-2, mod) % mod


x, y = map(int, input().split())
mod = 10**9 + 7
if (2*x-y) % 3 != 0 or (2*y-x) % 3 != 0:
    print(0)
    exit(0)
i = (2*x-y)//3
j = (2*y-x)//3
print(comb(i+j, i, mod))

Submission status: Wrong Answer

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


def f(n):
    res = n
    for i in range(1, n):
        res *= i
        res %= MOD
    return res


def solve():
    ans = 0
    if (X + Y) % 3 == 0:
        n = (2 * X - Y) // 3
        m = (2 * Y - X) // 3
        if n > 0 and m > 0:
            ans += (f(n + m) * pow(f(n), MOD - 2, MOD) * pow(f(m), MOD - 2, MOD)) % MOD

    print(ans)


if __name__ == "__main__":
    solve()

Submission status: Wrong Answer

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

mod = 10**9+7
def factorial(N):
    if N==1 or N==1:
        return 1
    else:
        ans = N
        for i in range(1, N):
            ans*=N-i
            ans%=mod
        return ans

if 2*Y-X>=0 and (2*Y-X)%3==0 and 2*X-Y>=0 and (2*X-Y)%3==0:
    s = (2*X-Y)//3
    t = (2*Y-X)//3
    #print(s, t)
    a = factorial(s+t)
    b = pow(factorial(s), mod-2, mod)
    c = pow(factorial(t), mod-2, mod)
    #print(a, b, c)
    print((a*b*c)%mod)
else:
    print(0)

Submission status: Wrong Answer

Solution code:
import math
import sys
import collections
import bisect
from scipy import special
readline = sys.stdin.readline


def main():
    x, y = map(int, readline().rstrip().split())
    if ((x + y) % 3 != 0):
        print(0)
        return
    a, b = x - (x + y) // 3, y - (x + y) // 3
    print(conb(a + b, a))


mod = 10**9+7


def modpow(a, n):
    if n < 1:
        return 1
    ans = modpow(a, n//2)
    ans = (ans*ans) % mod
    if n % 2 == 1:
        ans *= a
    return ans % mod


def conb(n, i):
    inv, ans = 1, 1
    for j in range(1, i+1):
        ans = ans*(n-j+1) % mod
        inv = inv*j % mod
    return (ans*modpow(inv, mod-2)) % mod


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
X, Y = [int(x) for x in input().split()]
M = 10**9+7
if (X + Y) % 3:
  print(0)
else:
  x = X - (X+Y)//3
  y = Y - (X+Y)//3
  #print(x, y)
  #x+y c x
  #(x+y)!/x!/y!
  ans = 1
  for j in range(y):
    #print(j)
    #print(x+j+1, j+1)
    ans *= (x+j+1) * pow(j+1, -1, M)
    ans %= M
  print(ans)

Submission status: Wrong Answer

Solution code:
X, Y = [int(x) for x in input().split()]
M = 10**9+7
if (X + Y) % 3:
  print(0)
  
x = X - (X+Y)//3
y = Y - (X+Y)//3
#print(x, y)
#x+y c x
#(x+y)!/x!/y!
ans = 1
for j in range(y):
  #print(j)
  #print(x+j+1, j+1)
  ans *= (x+j+1) * pow(j+1, -1, M)
  ans %= M
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
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**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 )

x,y = map(int, input().split())
if (x+y) % 3 != 0:
    print(0)
    exit()
A = np.matrix([[1,2],[2,1]])
Y = np.matrix([[x],[y]])
n,m = np.linalg.inv(A)*Y
n = int(n.tolist()[0][0])
m = int(m.tolist()[0][0])
if n < 0 or m < 0:
    print(0)
    exit()
print(cmb(n+m,n,mod))

Submission status: Wrong Answer

Solution code:
MOD = 10 ** 9 + 7

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

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

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

if a < 0 or b < 0:
    print(0)
    exit()

#calculate (a+b)!/a!b!

fac = [1, 1]
for i in range(2, a+b+1):
    fac.append(fac[-1] * i % MOD)

print(fac[a+b] * pow(fac[a] * fac[b], MOD-2, MOD) % MOD)

Submission status: Wrong Answer

Solution code:
class Combination():
    def __init__(self, n, mod=10**9+7):
        self.mod = mod
        self.fac = [1]*(n+1)
        for i in range(1,n+1):
            self.fac[i] = self.fac[i-1] * i % self.mod
        self.invfac = [1]*(n+1)
        self.invfac[n] = pow(self.fac[n], self.mod - 2, self.mod)
        for i in range(n-1, 0, -1):
            self.invfac[i] = self.invfac[i+1] * (i+1) % self.mod

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

    def permutation(self, n, r):
        return self.factorial(n) * self.invfactorial(n-r) % self.mod

    def factorial(self, i):
        return self.fac[i]

    def invfactorial(self, i):
        return self.invfac[i]

def main():
    import sys

    def input(): return sys.stdin.readline().rstrip()

    x, y= map(int, input().split())
    if 2*x-y < 0 or (2*x-y)%3 != 0 or (x+2*y)%3 != 0:
        print(0)
        return
    l = (2*x-y)//3
    k = (x+2*y)//3
    c = Combination(l+k)
    print(c.combination(l+k, l))

    


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
class Combination():
    def __init__(self, n, mod=10**9+7):
        self.mod = mod
        self.fac = [1]*(n+1)
        for i in range(1,n+1):
            self.fac[i] = self.fac[i-1] * i % self.mod
        self.invfac = [1]*(n+1)
        self.invfac[n] = pow(self.fac[n], self.mod - 2, self.mod)
        for i in range(n-1, 0, -1):
            self.invfac[i] = self.invfac[i+1] * (i+1) % self.mod

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

    def permutation(self, n, r):
        return self.factorial(n) * self.invfactorial(n-r) % self.mod

    def factorial(self, i):
        return self.fac[i]

    def invfactorial(self, i):
        return self.invfac[i]

def main():
    import sys

    def input(): return sys.stdin.readline().rstrip()

    x, y= map(int, input().split())
    if 2*x-y < 0 or (2*x-y)%3 != 0 or (x+y)%6 != 0:
        print(0)
        return
    l = (2*x-y)//3
    k = (x+y)//6
    c = Combination(l+k)
    print(c.combination(l+k, l))

    


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from math import factorial as fac
x,y=map(int,input().split())
a=2/3*y-1/3*x
b=1/3*(2*x-y)
mod=10**9+7
if a>=0 and b>=0 and a==int(a) and b==int(b):
  a=int(a)
  b=int(b)
  a1=1
  a2=1  
  n3=10**9+7
  for i in range(a):
    a1*=a+b-i
    a2*=i+1
    a1%=n3
    a2%=n3
  a2=pow(a2,n3-2,n3)
  print((a1*a2)%n3)
else:
  print(0)

Submission status: Wrong Answer

Solution code:
from math import factorial as fac
x,y=map(int,input().split())
a=2/3*y-1/3*x
b=1/3*(2*x-y)
mod=10**9+7
if a>=0 and b>=0 and a==int(a) and b==int(b):
  ue=fac(a+b)%mod
  sita1=pow(fac(a),mod-2,mod)
  sita2=pow(fac(b),mod-2,mod)
  print((ue*sita1*sita2)%mod)
else:
  print(0)

Submission status: Wrong Answer

Solution code:
import sys

X, Y = map(int, input().split())
mod = int(1e9) + 7
N = 10**6
g1 = [1, 1]
g2 = [1, 1]
inverse = [0, 1]


# 組み合わせ(1e9+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


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 )

# 方針：Xについてすべての動かし方を列挙する。Yに符合すれば組み合わせ計算、それ以外であれば没
kake = 0
ans = 0
while X > 0:
    temp = X
    if temp*2 + kake*1 == Y:
        ans += cmb(temp + kake, kake, mod)
    kake += 1
    X -= 2
print(ans)

Submission status: Wrong Answer

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

def modpow(a,n):
    if n<1:
        return 1
    ans=modpow(a,n//2)
    ans=(ans*ans)%mod
    if n%2==1:
        ans*=a
    return ans%mod
    
def conb(n,i):
    inv,ans=1,1
    for j in range(1,i+1):
        ans=ans*(n-j+1)%mod
        inv=inv*j%mod
    return (ans*modpow(inv,mod-2))%mod


if (x+y)%3!=0:
    print(0)
else:
    n=(x+y)//3
    x=x-n
    y=y-n
    if x<=0 or y<=0:
        print(0)
    else:
        ans=conb(x+y,x)
        print(ans)

Submission status: Wrong Answer

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

else:
    print(0)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
# https://atcoder.jp/contests/abc145/tasks/abc145_d
import math
import numpy as np
X, Y = list(map(int, input().split()))

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


a = np.array([[2, 1], [1, 2]])
b = np.array([X, Y])

res = np.linalg.solve(a, b)
n = int(res[0])
m = int(res[1])
print(n, m)

if n < 0 or m < 0:
    print(0)
    exit()

MOD = 10 ** 9 + 7
result = math.factorial(n + m) // (math.factorial(n) * math.factorial(m)) % MOD
print(result)

Submission status: Wrong Answer

Solution code:
x, y  = map(int, input().split())
mod = 10 ** 9 + 7
if (x + y) % 3 != 0:
    print(0)
    exit()
n, m = (2 * x - y) // 3, (2 * y - x) // 3
ans = 1
for i in range(min(m, n)):
    ans = ans * (n + m - i) % mod 
    ans *= pow(i + 1, mod - 2, mod)

print(ans % mod)

Submission status: Wrong Answer

Solution code:
# nCk(mod p)の計算
from math import factorial
X, Y = map(int, input().split())
MOD = 10**9+7
MAX = 10**6+1

 # a!のテーブルfact
fact = [0] * MAX
# (a!)^-1のテーブルfinv
finv = [0] * MAX

def comb_init():
    # a!と(a!)^-1のテーブルを作る
    # 累積積のイメージ
    fact[0] = fact[1] = 1
    finv[0] = finv[1] = 1
    for i in range(2, MAX):
        fact[i] = i * fact[i-1] % MOD
        finv[i] = pow(i, MOD-2, MOD) * finv[i-1] % MOD

def comb(n, r):
    return fact[n] * (finv[n-r] * finv[r] % MOD) % MOD    

if (X+Y) % 3 != 0:
    print(0)
else:
    num = (X+Y)//3
    p = (Y - X + num) // 2
    q = (X + num - Y) // 2
    if num < min(p, q):
        print(0)
        exit()
    comb_init()
    print(comb(num, min(p, q)))

Submission status: Wrong Answer

Solution code:
# nCk(mod p)の計算
from math import factorial
X, Y = map(int, input().split())
MOD = 10**9+7
MAX = 2*10**6

 # a!のテーブルfact
fact = [0] * MAX
# (a!)^-1のテーブルfinv
finv = [0] * MAX

def comb_init():
    # a!と(a!)^-1のテーブルを作る
    # 累積積のイメージ
    fact[0] = fact[1] = 1
    finv[0] = finv[1] = 1
    for i in range(2, MAX):
        fact[i] = i * fact[i-1] % MOD
        finv[i] = pow(i, MOD-2, MOD) * finv[i-1] % MOD

def comb(n, r):
    return fact[n] * (finv[n-r] * finv[r] % MOD) % MOD    

if (X+Y) % 3 != 0:
    print(0)
else:
    num = (X+Y)//3
    p = (Y - X + num) // 2
    q = (X + num - Y) // 2
    comb_init()
    print(comb(num, p))

Submission status: Wrong Answer

Solution code:
# nCk(mod p)の計算
from math import factorial
X, Y = map(int, input().split())
MOD = 10**9+7
MAX = 10**6+1

 # a!のテーブルfact
fact = [0] * MAX
# (a!)^-1のテーブルfinv
finv = [0] * MAX

def comb_init():
    # a!と(a!)^-1のテーブルを作る
    # 累積積のイメージ
    fact[0] = fact[1] = 1
    finv[0] = finv[1] = 1
    for i in range(2, MAX):
        fact[i] = i * fact[i-1] % MOD
        finv[i] = pow(i, MOD-2, MOD) * finv[i-1] % MOD

def comb(n, r):
    return fact[n] * (finv[n-r] * finv[r] % MOD) % MOD    

if (X+Y) % 3 != 0:
    print(0)
else:
    num = (X+Y)//3
    p = (Y - X + num) // 2
    q = (X + num - Y) // 2
    comb_init()
    print(comb(num, p))

Submission status: Wrong Answer

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

from functools import reduce

def cmb(n, r, p = 10 ** 9 + 7):
    r = min(n - r, r)
    if r == 0:  return 1
    numer = reduce(lambda x, y: (x * y) % p, range(n, n - r, -1))
    denom = reduce(lambda x, y: (x * y) % p, range(1, r + 1))
    return (numer * pow(denom, p - 2, p)) % p

temp1 = 2 * X - Y
temp2 = 2 * Y - X
if temp1 % 3 or temp2 % 3:  print(0)
elif temp1 < 0 or temp2 < 0:  print(0)
else:
    a = temp1 // 3
    b = temp2 // 3
    print(a, b)
    print(cmb(a + b, a, 10 ** 9 + 7))

Submission status: Wrong Answer

Solution code:
def C(n, r, MOD):
    num = 1
    den = 1
    for i in range(r):
        num *= n - i
        num %= MOD
        den *= i + 1
        den %= MOD
    return ((num * pow(den, MOD - 2, MOD)) % MOD)

X, Y = map(int, input().split())
MOD = 1_000_000_007
n = min(X // 3, Y // 3) * 2
x = X - min(X // 3, Y // 3) * 3
y = Y - min(X // 3, Y // 3) * 3
if x == 0 and y == 0:
    print(C(n, n//2, MOD))
elif x * 2 == y:
    r = n//2 + x
    n += x
    print(C(n, r, MOD))
elif x == y * 2:
    r = n//2 + y
    n += y
    print(C(n, r, MOD))
else:
    print(0)

Submission status: Wrong Answer

Solution code:
def C(n, r, MOD):
    num = 1
    den = 1
    for i in range(r):
        num *= n - i
        num %= MOD
        den *= i + 1
        den %= MOD
    return ((num * pow(den, MOD - 2, MOD)) % MOD)

X, Y = map(int, input().split())
MOD = 1_000_000_007
n = min(X // 3, Y // 3) * 2
x = X - min(X // 3, Y // 3) * 3
y = Y - min(X // 3, Y // 3) * 3
if x == 0 and y == 0:
    print(C(n, n//2, MOD))
elif x * 2 == y:
    r = x
    n += r
    print(C(n, r, MOD))
elif x == y * 2:
    r = y
    n += r
    print(C(n, r, MOD))
else:
    print(0)

Submission status: Wrong Answer

Solution code:
def C(n, r, MOD):
    num = 1
    den = 1
    for i in range(r):
        num *= n - i
        num %= MOD
        den *= i + 1
        den %= MOD
    return ((num * pow(den, MOD - 2, MOD)) % MOD)

X, Y = map(int, input().split())
MOD = 1_000_000_007
n = min(X // 3, Y // 3) * 2
x = X - min(X // 3, Y // 3) * 3
y = Y - min(X // 3, Y // 3) * 3
if x == 0 and y == 0:
    print(C(n, n//2, MOD))
elif x == y / 2:
    r = x
    n += r
    print(C(n, r, MOD))
elif x / 2 == y:
    r = y
    n += r
    print(C(n, r, MOD))
else:
    print(0)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
from collections import deque
from collections import OrderedDict
import itertools
from sys import stdin
input = stdin.readline


class PrimeComb:
  def __init__(self, MAX=666670, MOD=1000000007):
    # preprocessing: O(MAX)
    self.MAX  = MAX
    self.MOD  = MOD
    self.fac  = [0]*MAX
    self.inv  = [0]*MAX
    self.finv = [0]*MAX
    self.fac[0]  = self.fac[1] = 1
    self.finv[0] = self.finv[1] = 1
    self.inv[1]  = 1
    for i in range(2, MAX):
      self.fac[i]  = self.fac[i-1] * i % MOD
      self.inv[i]  = MOD - self.inv[MOD % i] * int(MOD / i) % MOD
      self.finv[i] = self.finv[i-1] * self.inv[i] % MOD

  def com(self, n, k):
    # compute -> nCk % self.P : O(1)
    if (n < k): return 0
    if (n < 0 or k < 0): return 0
    return self.fac[n] * (self.finv[k] * self.finv[n-k] % self.MOD) % self.MOD


def main():
  X, Y = list(map(int, input().split()))
  PC = PrimeComb()

  num_trans1 = 0
  num_trans2 = 0

  # min_ = min(X, Y) // 3
  # X -= 3*min_
  # Y -= 3*min_
  # num_trans1 += min_
  # num_trans2 += min_
  ans = 0
  for i in range(min(X, Y)//3 + 1):
    tempX = X - 3*i
    tempY = Y - 3*i
    num_trans1 = i
    num_trans2 = i

    if tempX==tempY==0:
      ans += PC.com(num_trans1+num_trans2, num_trans1)

    elif X > Y:
      if X % 2:
        # print(0)
        continue
      if X//2 != Y:
        # print(0)
        continue
      num_trans2 += Y
      ans += PC.com(num_trans1+num_trans2, num_trans1)
    elif X < Y:
      if Y % 2:
        # print(0)
        continue
      if Y//2 != X:
        # print(0)
        continue
      num_trans1 += X
      ans += PC.com(num_trans1+num_trans2, num_trans1)

  # print(num_trans1, num_trans2)
  print(ans % 1_000_000_007)


if(__name__ == '__main__'):
  main()

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
from collections import deque
from collections import OrderedDict
import itertools
from sys import stdin
input = stdin.readline


class PrimeComb:
  def __init__(self, MAX=666670, MOD=1000000007):
    # preprocessing: O(MAX)
    self.MAX  = MAX
    self.MOD  = MOD
    self.fac  = [0]*MAX
    self.inv  = [0]*MAX
    self.finv = [0]*MAX
    self.fac[0]  = self.fac[1] = 1
    self.finv[0] = self.finv[1] = 1
    self.inv[1]  = 1
    for i in range(2, MAX):
      self.fac[i]  = self.fac[i-1] * i % MOD
      self.inv[i]  = MOD - self.inv[MOD % i] * int(MOD / i) % MOD
      self.finv[i] = self.finv[i-1] * self.inv[i] % MOD

  def com(self, n, k):
    # compute -> nCk % self.P : O(1)
    if (n < k): return 0
    if (n < 0 or k < 0): return 0
    return self.fac[n] * (self.finv[k] * self.finv[n-k] % self.MOD) % self.MOD


def main():
  X, Y = list(map(int, input().split()))
  PC = PrimeComb()

  num_trans1 = 0
  num_trans2 = 0

  # min_ = min(X, Y) // 3
  # X -= 3*min_
  # Y -= 3*min_
  # num_trans1 += min_
  # num_trans2 += min_
  ans = 0
  for i in range(min(X, Y)//3 + 1):
    tempX = X - 3*i
    tempY = Y - 3*i
    num_trans1 = i
    num_trans2 = i

    if tempX==tempY==0:
      ans += PC.com(num_trans1+num_trans2, num_trans1)

    elif X > Y:
      if X % 2:
        # print(0)
        continue
      if X//2 != Y:
        # print(0)
        continue
      num_trans2 += Y
      ans += PC.com(num_trans1+num_trans2, num_trans1)
    elif X < Y:
      if Y % 2:
        # print(0)
        continue
      if Y//2 != X:
        # print(0)
        continue
      num_trans1 += X
      ans += PC.com(num_trans1+num_trans2, num_trans1)

  # print(num_trans1, num_trans2)
  print(ans)


if(__name__ == '__main__'):
  main()