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:
import sys
input = lambda: sys.stdin.readline().rstrip()

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


def combination(n, r, mod):
    r = min(r, n-r)

    numer = 1
    denom = 1

    for i in range(r):
        numer = numer * (n-i) % mod
        denom = denom * (r-i) % mod

    return numer * pow(denom, mod-2, mod) % mod

m_n = (X+Y) // 3
m = X - m_n
n = Y - m_n

if X+Y % 3 == 0 or m < 0 or n < 0:
    print(0)
    exit()

print(combination(m_n, m, mod))

Submission status: Wrong Answer

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

def pow(a,b,M):
    if b == 0:
        return 1
    else:
        if b % 2 == 0:
            return pow((a**2)%M,b//2,M) % M
        else:
            return (a * pow((a**2)%M,b//2,M)) % M

def inv(a,M):
    return pow(a,M-2,M)

def comb(n,k,M):
    nume,deno = 1,1
    for i in range(1,k+1):
        deno = (deno * (n-i+1)) % M
        nume = (nume * i) % M
    return (deno * inv(nume,M)) % M

if (x+y) % 3 != 0 and (2*x < y or 2*y < x):
    print(0)
else:
    mov = (x+y)//3
    x,y = x-mov,y-mov
    print(comb(mov,x,M))

Submission status: Wrong Answer

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

def pow(a,b,M):
    if b == 0:
        return 1
    else:
        if b % 2 == 0:
            return pow((a**2)%M,b//2,M) % M
        else:
            return (a * pow((a**2)%M,b//2,M)) % M

def inv(a,M):
    return pow(a,M-2,M)

def comb(n,k,M):
    nume,deno = 1,1
    for i in range(1,k+1):
        deno = (deno * (n-i+1)) % M
        nume = (nume * i) % M
    return (deno * inv(nume,M)) % M

if (x+y) % 3 != 0:
    print(0)
else:
    mov = (x+y)//3
    x,y = x-mov,y-mov
    print(comb(mov,x,M))

Submission status: Wrong Answer

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

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

n = (x + y) // 3
x -= n
y -= n
if x < 0 or y < 0:
    print(0)
    exit()
mod = 10 ** 9 + 7

def extGCD(a, b):
    if b == 0:
        return a, 1, 0
    g, y, x = extGCD(b, a%b)
    y -= a//b * x
    return g, x, y

def moddiv(a, b):
    _, inv, _ = extGCD(b, mod)
    return (a * inv) % mod

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

def comb(a, b):
    return moddiv(moddiv(fact[a+b], fact[b]), fact[b])

print(comb(x, y))

Submission status: Wrong Answer

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

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

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

def extGCD(a, b):
    if b == 0:
        return a, 1, 0
    g, y, x = extGCD(b, a%b)
    y -= a//b * x
    return g, x, y

def moddiv(a, b):
    _, inv, _ = extGCD(b, mod)
    return (a * inv) % mod

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

def comb(a, b):
    return moddiv(moddiv(fact[a+b], fact[b]), fact[b])

print(comb(x, y))

Submission status: Wrong Answer

Solution code:
MOD=10**9+7
def modpow(a,n,mod):
    res=1
    a=a%mod
    while(n>0):
        if(n&1):
            res=res*a%mod
        a=a*a%mod
        n>>=1
    return res

def com(n,k,mod):
    res=1
    tmp=1
    for i in range(1,k+1):
        res=res*(n-i+1)%mod
        tmp=tmp*i%mod
    a=modpow(tmp,1000000005,mod)
    return res*a%mod

X,Y=map(int,input().split())
if((X+Y)%3!=0):
    print(0)
    exit()
m=(2*X-Y)//3
n=(2*Y-X)//3
print(com(m+n,m,MOD))

Submission status: Wrong Answer

Solution code:
MOD=10**9+7

def powmod(a,p):
  if p==0:
    return 1
  elif p==1:
    return a
  elif p%2==0:
    powsq=powmod(a,p//2)
    return (powsq**2)%MOD
  elif p%2==1:
    powsq=powmod(a,p//2)
    return (a*powsq**2)%MOD

def invmod(a):
  return powmod(a,MOD-2)

X,Y=map(int,input().split())
u=X*2/3-Y/3
v=-X/3+Y*2/3

if u==int(u) and u>=0 and v==int(v) and v>=0:
  #print(int(u),int(v))
  ui=int(u)
  vi=int(v)
  
  bunshi=1
  for i in range(vi):
    bunshi*=ui+vi-i
    bunshi%=MOD
  bumbo=1
  for i in range(vi):
    bumbo*=vi-i
    bumbo%=MOD
    
  #calculate bunshi/bumbo%MOD as bunshi*bumbo^-1%MOD
  print(bunshi*invmod(bumbo)%MOD)  
else:
  print(0)

Submission status: Wrong Answer

Solution code:
MOD=10**9+7

def powmod(a,p):
  if p==0:
    return 1
  elif p==1:
    return a
  elif p%2==0:
    powsq=powmod(a,p//2)
    return (powsq**2)%MOD
  elif p%2==1:
    powsq=powmod(a,p//2)
    return (a*powsq**2)%MOD

def invmod(a):
  return powmod(a,MOD-2)

X,Y=map(int,input().split())
u=X*2/3-Y/3
v=-X/3+Y*2/3

if u==int(u) and u>=0 and v==int(v) and v>=0:
  #print(int(u),int(v))
  ui=int(u)
  vi=int(v)
  
  bunshi=1
  for i in range(ui):
    bunshi*=ui+vi-i
    bunshi%=MOD
  bumbo=1
  for i in range(vi):
    bumbo*=vi-i
    bumbo%=MOD
    
  #calculate bunshi/bumbo%MOD as bunshi*bumbo^-1%MOD
  print(bunshi*invmod(bumbo)%MOD)  
else:
  print(0)

Submission status: Wrong Answer

Solution code:
#組み合わせ総数
mod = 10 ** 9 + 7
def comb(n, k):
    res = 1
    for i in range(n - k + 1, n + 1):
        res = res * i % mod
    for i in range(1, k + 1):
        res = res * pow(i, mod - 2, mod) % mod
    return res

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

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

m = (2 * x - y) // 3
n = x - 2 * m

if n > 0 and m > 0:
    print(comb(m + n,min(m,n)))
else:
    print(0)

Submission status: Wrong Answer

Solution code:
#組み合わせ総数
mod = 10 ** 9 + 7
def comb(n, k):
    res = 1
    for i in range(n - k + 1, n + 1):
        res = res * i % mod
    for i in range(1, k + 1):
        res = res * pow(i, mod - 2, mod) % mod
    return res

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

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

m = (2 * x - y) // 3
n = x - 2 * m

print(comb(m + n,min(m,n)))

Submission status: Wrong Answer

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

def comb(n, r, mod):
    X = 1
    Y = 1
    for i in range(1,r+1):
        X = (X*(n-i+1))%mod
        Y = (Y*i)%mod
    return (X*pow(Y, mod-2, mod))%mod

if (X+Y)%3 != 0 :
    print(0)
else :
    i = X - (X+Y)//3
    print(comb((X+Y)//3, i, mod))

Submission status: Wrong Answer

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

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

def modinv(a, mod=10**9+7):
    return pow(a, mod-2, mod)

def combination(n, r, mod=10**9+7):
    r = min(r, n-r)
    res = 1
    for i in range(r):
        res = res * (n - i) * modinv(i+1, mod) % mod
    return res

if rent_a != 0 or rent_b != 0:
    ans = 0
else:
    n = a + b
    ans = combination(n, a)

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
input = lambda: sys.stdin.readline().rstrip()
input_nums = lambda: list(map(int, input().split()))

MOD = 10**9+7

def calc(x, y):
    return int((x + y) / 3), int((2*x - y) / 3)

def mod_cmb(n, r, mod):
    """nCrを計算する。高速。
    """
    x = 1
    y = n
    for i in range(2,r+1):
        x *= i
        x %= mod
        y *= n-i+1
        y %= mod
    return y * pow(x, mod-2, mod) % mod


def main():
    x, y = input_nums()
    if (x+y) % 3 != 0:
        print(0)
        exit(0)
    n, m = calc(x, y)
    if n < 0 or m < 0:
        print(0)
        exit(0)
    ans = mod_cmb(n, m, MOD)
    print(ans % MOD)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

#フェルマーの小定理を用いてcombの計算を行う
def comb(n, k, mod, frac):
    a=frac[n]
    b=frac[k]
    c=frac[n-k]
    return (a * pow(b, mod-2, mod) * pow(c, mod-2, mod)) % mod

if 2*y-x <= 0 or 2*x-y <= 0:
  print(0)
elif (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)
  mod = 10**9 + 7
  frac = [1]
  for i in range(a+b):
      frac.append(frac[i]*(i+1)%mod)
  print(comb(a + b, a, mod, frac))

Submission status: Wrong Answer

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

#フェルマーの小定理を用いてcombの計算を行う
def comb(n, k, mod, frac):
    a=frac[n]
    b=frac[k]
    c=frac[n-k]
    return (a * pow(b, mod-2, mod) * pow(c, mod-2, mod)) % mod

if 2*y-x <= 0 or 2*x-y <= 0:
  print(0)
elif (2*y-x)%3 != 0 or (2*x -y) % 3 != 0:
  print(0)
else:
  a = (2*y-x)//3
  b = (2*x-y)//3
  mod = 10**9 + 7
  frac = [1]
  for i in range(a+b):
      frac.append(frac[i]*(i+1)%mod)
  print(comb(a + b, a, mod, frac))

Submission status: Wrong Answer

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

MOD = 10 ** 9 + 7
class modint:
    def __init__(self, x):
        self.x = x.x if isinstance(x, modint) else x % MOD
    def __str__(self): return str(self.x)
    __repr__ = __str__
    def __int__(self): return self.x
    __index__ = __int__
    def __add__(self, other): return modint(self.x + modint(other).x)
    def __sub__(self, other): return modint(self.x - modint(other).x)
    def __mul__(self, other): return modint(self.x * modint(other).x)
    def __pow__(self, other): return modint(pow(self.x, modint(other).x, MOD))
    def __floordiv__(self, other): return modint(self.x * pow(modint(other).x, MOD - 2, MOD))
    def __lt__(self, other): return self.x < modint(other).x
    def __gt__(self, other): return self.x > modint(other).x
    def __le__(self, other): return self.x <= modint(other).x
    def __ge__(self, other): return self.x >= modint(other).x
    def __eq__(self, other): return self.x == modint(other).x
    def __ne__(self, other): return self.x != modint(other).x
    def inv(self): return pow(self.x, MOD - 2, MOD)

def modC(n, r):  # nCr = n!/(n-r)!r!
    r = min(r, n - r)
    ans = modint(1)
    for i in range(n, n - r, -1):
        ans *= i
    for i in range(2, r + 1):
        ans //= i
    return ans

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

Submission status: Wrong Answer

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7

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

N = 10 ** 6 + 100  # N は必要分だけ用意する
fact = [1, 1]  # fact[n] = (n! mod p)
#factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
#inv = [0, 1]  # factinv 計算用

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

x, y = MAP()
ans = 0
if (x + y) % 3 == 0:
    a = (2 * y - x) // 3
    b = (2 * x - y) // 3
    ans = cmb(a + b, a)
print(ans)

Submission status: Wrong Answer

Solution code:
def main():
    X, Y = (int(i) for i in input().split())
    if (X+Y) % 3 != 0:
        return print(0)
    MOD = 10**9 + 7
    m = X + Y + 5
    fac = [0] * m
    finv = [0] * m
    inv = [0] * m

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

    COMBinitialize(m)

    n = (X+Y)//3
    r = n - (X//3)
    print(COMB(n, r))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def cmb(n,r,mod):
    r=min(r,n-r)
    X=1
    Y=1
    for i in range(r):
        X*=n-i
        X%=mod
        Y*=i+1
        Y%=mod
    Y=pow(Y,mod-2,mod)
    X*=Y
    return X%mod

if __name__ == "__main__":    
    X,Y=map(int,input().split())
    if (2*Y-X)%3!=0 or (2*X-Y)%3!=0:
        print(0)
    else:
        xd=(2*X-Y)//3
        yd=(2*Y-X)//3
        print(cmb(xd+yd,yd,10**9+7))

Submission status: Wrong Answer

Solution code:
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 cmb(n,r,mod):
    r=min(r,n-r)
    X=1
    Y=1
    for i in range(r):
        X*=n-i
        X%=mod
        Y*=i+1
        Y%=mod
    Y=pow(Y,mod-2,mod)
    X*=Y
    return X%mod

X,Y=map(int,input().split())
if (2*Y-X)%3!=0 or (2*X-Y)%3!=0:
    print(0)
else:
    xd=(2*X-Y)//3
    yd=(2*Y-X)//3
    print(cmb(xd+yd,yd,10**9+7)%(10**9+7))

Submission status: Wrong Answer

Solution code:
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 cmb(n,r,mod):
    r=min(r,n-r)
    X=1
    Y=1
    for i in range(r):
        X*=n-i
        X%=mod
        Y*=i+1
        Y%=mod
    Y=pow(Y,mod-2,mod)
    X*=Y
    return X%mod

X,Y=map(int,input().split())
if (2*Y-X)%3!=0:
    print(0)
else:
    xd=(2*X-Y)//3
    yd=(2*Y-X)//3
    print(cmb(xd+yd,yd,10**9+7)%(10**9+7))

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!

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

# mod. m での a の逆元 a^{-1} を計算する
# b * a^{-1} (mod m)を計算したい場合はb * modinv(a, m) % m
def modinv(a, m):
    b = m
    u = 1
    v = 0
    while b:
        t = int(a / b)
        a -= t * b
        a, b = b, a
        u -= t * v
        u, v = v, u
    u %= m
    if u < 0:
        u += m
    return u

max_xy = max(X, Y)
min_xy = min(X, Y)
if (X + Y) % 3 == 0 and (max_xy - min_xy) <= 2 * min_xy:
    a = 2 * (min_xy - (max_xy - min_xy)) // 6
    num_max = a + max_xy - min_xy
    num_min = a
    count = 1
    for i in range(num_max+1, num_max+num_min+1):
        count = (count * i) % int(1e9+7)
    for i in range(1, num_min+1):
        count = (count * modinv(i, int(1e9+7))) % int(1e9+7)
    print(count)
else:
    print(0)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!

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

# mod. m での a の逆元 a^{-1} を計算する
# b * a^{-1} (mod m)を計算したい場合はb * modinv(a, m) % m
def modinv(a, m):
    b = m
    u = 1
    v = 0
    while b:
        t = int(a / b)
        a -= t * b
        a, b = b, a
        u -= t * v
        u, v = v, u
    u %= m
    if u < 0:
        u += m
    return u

max_xy = max(X, Y)
min_xy = min(X, Y)
if (X + Y) % 3 == 0 and (max_xy - min_xy) / min_xy <= 2:
    a = 2 * (min_xy - (max_xy - min_xy)) // 6
    num_max = a + max_xy - min_xy
    num_min = a
    count = 1
    for i in range(num_max+1, num_max+num_min+1):
        count = (count * i) % int(1e9+7)
    for i in range(1, num_min+1):
        count = (count * modinv(i, int(1e9+7))) % int(1e9+7)
    print(count)
else:
    print(0)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!

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

# mod. m での a の逆元 a^{-1} を計算する
# b * a^{-1} (mod m)を計算したい場合はb * modinv(a, m) % m
def modinv(a, m):
    b = m
    u = 1
    v = 0
    while b:
        t = int(a / b)
        a -= t * b
        a, b = b, a
        u -= t * v
        u, v = v, u
    u %= m
    if u < 0:
        u += m
    return u

max_xy = max(X, Y)
min_xy = min(X, Y)
if (X + Y) % 3 == 0 and (max_xy - min_xy) / min_xy <= 2:
    a = 2 * (min_xy - (max_xy - min_xy)) // 6
    num_max = a + max_xy - min_xy
    num_min = a
    count = 1
    for i in range(num_max+1, num_max+num_min+1):
        count = (count * i) % int(1e9+7)
    for i in range(1, num_max+1):
        count = (count * modinv(i, int(1e9+7))) % int(1e9+7)
    print(count)
else:
    print(0)

Submission status: Wrong Answer

Solution code:
def solve():
    mod = 10 ** 9 + 7
    fac, finv, inv = COMinit(10 ** 6, mod)

    X, Y = map(int, input().split())
    if (X + Y) % 3 != 0:
        print(0)
        return
    
    ans = 0
    for one_cnt in range(10 ** 6):
        x1 = one_cnt * 2
        y1 = one_cnt * 1
        remain_x = X - x1
        remain_y = Y - y1
        if remain_x * 2 != remain_y or remain_x <= 0:
            continue
        two_cnt = remain_x
        ans += COM(one_cnt+two_cnt, one_cnt,mod,fac,finv,inv)
    
    print(ans)

def n_combination(n, r, mod):
    numer_sum = 1
    denom_sum = 1
    for i in range(r):
        numer_sum *= n - i
        numer_sum % mod
        denom_sum *= r - i
        numer_sum % mod
    
    return numer_sum * modinv(denom_sum, mod) % mod

def modinv(a, mod):
    return pow(a, mod-2, mod)
    
def COMinit(N, mod):
    fac = [0] * N
    finv = [0] * N
    inv = [0] * N

    fac[0] = 1
    fac[1] = 1
    finv[0] = 1
    finv[1] = 1
    inv[1] = 1

    for i in range(2, N):
        fac[i] = fac[i-1] * i % mod
        inv[i] = mod - inv[mod%i] * (mod // i) % mod
        finv[i] = finv[i-1] * inv[i] % mod
    
    return fac, finv, inv

def COM(n, r, mod, fac, finv, inv):
    if n < r:
        return 0
    if n < 0 or r < 0:
        return 0
    return fac[n] * (finv[r] * finv[n-r] % mod) % mod

if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

Solution code:
'''
https://atcoder.jp/contests/abc145/tasks/abc145_d
'''
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10000000)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate
    #from itertools import product
    from bisect import bisect_left,bisect_right
    import heapq
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    mod = 10**9 + 7

    X,Y = map(int, input().split())
    if (X+Y)%3 != 0:
        print(0)
        exit()
    a = (2*X-Y)//3
    b = (2*Y-X)//3

    def extgcd(a, b):
        if b == 0:
            return a, 1, 0
        else:
            d, x, y = extgcd(b, a % b)
            x -= (a // b) * y
            return d, y, x
        
    def modinv(a, mod): 
        return extgcd(a, mod)[1] % mod

    def modcomb(n, k, mod):
        q, a = 1, 1
        for i in range(n-k+1, n+1):
            q = (q * i) % mod
        for i in range(2, k+1):
            a = (a * i) % mod
        return int(q * modinv(a, mod) % mod)

    print(modcomb(a+b, a, mod))

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

def comb(n,r,mod):
  ans = 1
  for i in range(r):
    ans *= n-i
    ans %= mod
  for i in range(1,n-r+1):
    ans *= pow(i,mod-2,mod)
    ans %= mod
  return ans
  #for i in range(r):
  
if (2*X-Y)%3!=0 or 2*X-Y<0 or (-1)*X+2*Y<0:
  print(0)
else:
  p = (2*X-Y)//3
  q = ((-1)*X+2*Y)//3
  print(comb(p+q,p,mod))

Submission status: Wrong Answer

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

def comb(n,r,mod):
  ans = 1
  for i in range(r):
    ans *= n-i
    ans %= mod
  for i in range(1,n-r+1):
    ans *= pow(i,mod-2,mod)
    ans %= mod
  return ans
  #for i in range(r):
  
if (2*X-Y)%3!=0:
  print(0)
else:
  p = (2*X-Y)//3
  q = ((-1)*X+2*Y)//3
  print(comb(p+q,p,mod))

Submission status: Wrong Answer

Solution code:
# https://atcoder.jp/contests/abc145/tasks/abc145_d
from math import factorial
x, y = map(int, input().split())
mod = 10 ** 9 + 7

# two_steps = x // 2
# one_steps = x % 2
# ans = 0
# while two_steps:
#     if one_steps * 2 + two_steps * 1 == y:
#         ans += (factorial(one_steps + two_steps) * (pow(factorial(one_steps), mod - 2, mod) * pow(factorial(two_steps), mod - 2, mod))) % mod
#     two_steps -= 1
#     one_steps += 2
# print(ans)

MAX = 10 ** 6 + 1

def com_init(MAX, mod):
    fac = [0] * MAX
    finv = [0] * MAX
    inv = [0] * MAX
    fac[0] = fac[1] = 1
    finv[0] = 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
    return fac, finv

fac, finv = com_init(MAX, mod)

def nCr(n,r):
    return fac[n] * (finv[r] * finv[n - r] % mod) % mod 

if (-x + 2 * y) % 3 == 0 and (2 * x - y) % 3 == 0 and (-y + 2 * x) % 3 == 0 and (2 * y - x) % 3 == 0:
    a = (-x + 2 * y) // 3
    b = (2 * x - y) // 3
    ans = nCr(a + b, a)
    # ans = (factorial(a + b) * (pow(factorial(a), mod - 2, mod) * pow(factorial(b), mod - 2, mod))) % mod
else:
    ans = 0

print(ans)

Submission status: Wrong Answer

Solution code:
# https://atcoder.jp/contests/abc145/tasks/abc145_d
from math import factorial
x, y = map(int, input().split())
mod = 10 ** 9 + 7

# two_steps = x // 2
# one_steps = x % 2
# ans = 0
# while two_steps:
#     if one_steps * 2 + two_steps * 1 == y:
#         ans += (factorial(one_steps + two_steps) * (pow(factorial(one_steps), mod - 2, mod) * pow(factorial(two_steps), mod - 2, mod))) % mod
#     two_steps -= 1
#     one_steps += 2
# print(ans)

MAX = 10 ** 6 + 1

def com_init(MAX, mod):
    fac = [0] * MAX
    finv = [0] * MAX
    inv = [0] * MAX
    fac[0] = fac[1] = 1
    finv[0] = 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
    return fac, finv

fac, finv = com_init(MAX, mod)

def nCr(n,r):
    return fac[n] * (finv[r] * finv[n - r] % mod) % mod 

if (-x + 2 * y) % 3 == 0 and (2 * x - y) % 3 == 0 and (-y + 2 * x) % 3 == 0 and (2 * y - x) % 3 == 0:
    a = (-x + 2 * y) // 3
    b = (2 * x - y) // 3
    ans = nCr(a + b, a) % mod
    # ans = (factorial(a + b) * (pow(factorial(a), mod - 2, mod) * pow(factorial(b), mod - 2, mod))) % mod
else:
    ans = 0

print(ans)

Submission status: Wrong Answer

Solution code:
# https://atcoder.jp/contests/abc145/tasks/abc145_d
from math import factorial
x, y = map(int, input().split())
mod = 10 ** 9 + 7

# two_steps = x // 2
# one_steps = x % 2
# ans = 0
# while two_steps:
#     if one_steps * 2 + two_steps * 1 == y:
#         ans += (factorial(one_steps + two_steps) * (pow(factorial(one_steps), mod - 2, mod) * pow(factorial(two_steps), mod - 2, mod))) % mod
#     two_steps -= 1
#     one_steps += 2
# print(ans)

MAX = 10 ** 6 + 1

def com_init(MAX, mod):
    fac = [0] * MAX
    finv = [0] * MAX
    inv = [0] * MAX
    fac[0] = fac[1] = 1
    finv[0] = 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
    return fac, finv

fac, finv = com_init(MAX, mod)

def nCr(n,r):
    return fac[n] * (finv[r] * finv[n - r] % mod) % mod 

if x % 3 == 0 and y % 3 == 0:
    a = (-x + 2 * y) // 3
    b = (2 * x - y) // 3
    ans = nCr(a + b, a) % mod
    # ans = (factorial(a + b) * (pow(factorial(a), mod - 2, mod) * pow(factorial(b), mod - 2, mod))) % mod
else:
    ans = 0

print(ans)

Submission status: Wrong Answer

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


def comb(n, r, mod):
    numerator = denominator = 1
    for i in range(r):
        numerator = numerator * (n - i) % mod
        denominator = denominator * (i + 1) % mod
    return numerator * inv(denominator, mod) % mod


# 逆元を返す関数(非再帰拡張Euclidの互除法))
# pow(a, mod-2, mod)と等価
def inv(a, mod):
    b = mod
    p, q = 1, 0
    while b > 0:
        c = a // b
        a, b = b, a-c*b
        p, q = q, p-c*q
    return p + mod if p < 0 else p


i = (2*y - x) / 3
j = (2*x - y) / 3
if i.is_integer() and j.is_integer():
    i = int(i)
    j = int(j)
    ans = comb(i+j, i, mod)
else:
    ans = 0
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
mod = 10**9+7
def bpow(x,n,m) :
  if n == 0 :
    return 1
  ans = 1
  while n > 1 :
    if n%2 != 0 :
      ans = ans*x%mod
    x = x*x%mod
    n //= 2
  return ans*x%mod
      
x,y = map(int,input().split())

for i in range(0,10**6+1) :
  xa = x - 1*i
  ya = y - 2*i
  if xa%2 == 0 and ya == 1*(xa//2) and xa > 0 :
    n = i+xa//2
    # n!のあまりを求める
    np = 1
    for j in range(1,n+1) :
      np = (np*j)%mod
    #1/p!のあまりを求める
    pp = 1
    for j in range(1,i+1) :
      pp = pp*bpow(j,mod-2,mod)%mod
    #1/q!のあまりを求める
    qp = 1
    for j in range(1,(n-i)+1) :
      qp = qp*bpow(j,mod-2,mod)%mod
    print(np*pp*qp%mod)
    sys.exit()
print(0)

Submission status: Wrong Answer

Solution code:
import sys
mod = 10**9+7
def bpow(x,n,m) :
  if n == 0 :
    return 1
  ans = 1
  while n > 1 :
    if n%2 != 0 :
      ans = ans*x%mod
    x = x*x%mod
    n //= 2
  return ans*x%mod
      
x,y = map(int,input().split())

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

for i in range(0,10**6+1) :
  xa = x - 1*i
  ya = y - 2*i
  if xa%2 == 0 and ya == 1*(xa//2) :
    n = i+xa//2
    # n!のあまりを求める
    np = 1
    for j in range(1,n+1) :
      np = (np*j)%mod
    #1/p!のあまりを求める
    pp = 1
    for j in range(1,i+1) :
      pp = pp*bpow(j,mod-2,mod)%mod
    #1/q!のあまりを求める
    qp = 1
    for j in range(1,(n-i)+1) :
      qp = qp*bpow(j,mod-2,mod)%mod
    print(np*pp*qp%mod)
    sys.exit()

Submission status: Wrong Answer

Solution code:
import sys
mod = 10**9+7
def bpow(x,n,m) :
  if n == 0 :
    return 1
  ans = 1
  while n > 1 :
    if n%2 != 0 :
      ans = ans*x%mod
    x = x*x%mod
    n //= 2
  return ans*x%mod
      
x,y = map(int,input().split())

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

for i in range(0,10**6+1) :
  xa = x - 1*i
  ya = y - 2*i
  if xa%2 == 0 and ya == 1*(xa//2) :
    n = i+xa//2
    # n!のあまりを求める
    np = 1
    for j in range(1,n+1) :
      np = (np*j)%mod
    #1/p!のあまりを求める
    pp = 1
    for j in range(1,i+1) :
      pp = pp*bpow(j,mod-2,mod)%mod
    #1/q!のあまりを求める
    qp = 1
    for j in range(1,(n-i)+1) :
      qp = qp*bpow(j,mod-2,mod)%mod
    print(np*pp*qp%mod)
    sys.exit()

Submission status: Wrong Answer

Solution code:
import sys
mod = 10**9+7
def bpow(x,n,m) :
  if n == 0 :
    return 1
  ans = 1
  while n > 1 :
    if n%2 != 0 :
      ans = ans*x%mod
    x = x*x%mod
    n //= 2
  return ans*x%mod
      
x,y = map(int,input().split())

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

for i in range(0,10**6+1) :
  xa = x - 1*i
  ya = y - 2*i
  if xa%2 == 0 and ya == 1*(xa//2) :
    n = i+xa//2
    # n!のあまりを求める
    np = 1
    for j in range(1,n+1) :
      np = (np*j)%mod
    #1/p!のあまりを求める
    pp = 1
    for j in range(1,i+1) :
      pp = pp*bpow(j,mod-2,mod)%mod
    #1/q!のあまりを求める
    qp = 1
    for j in range(1,(n-i)+1) :
      qp = qp*bpow(j,mod-2,mod)%mod
    print(np*pp*qp%mod)
    sys.exit()

Submission status: Wrong Answer

Solution code:
import sys
mod = 10**9+7
def bpow(x,n,m) :
  if n == 0 :
    return 1
  ans = 1
  while n > 1 :
    if n%2 != 0 :
      ans = ans*x%mod
    x = x*x%mod
    n //= 2
  return ans*x%mod
      
x,y = map(int,input().split())

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

for i in range(0,10**6+1) :
  xa = x - 1*i
  ya = y - 2*i
  if xa%2 == 0 and ya == 1*(xa//2) :
    n = i+xa//2
    # n!のあまりを求める
    np = 1
    for j in range(1,n+1) :
      np = (np*j)%mod
    #1/p!のあまりを求める
    pp = 1
    for j in range(1,i+1) :
      pp = pp*bpow(j,mod-2,mod)%mod
    #1/q!のあまりを求める
    qp = 1
    for j in range(1,(n-i)+1) :
      qp = qp*bpow(j,mod-2,mod)%mod
    print(np*pp*qp%mod)
    print(i,xa//2)
    sys.exit()

Submission status: Wrong Answer

Solution code:
import sys
mod = 10**9+7
def bpow(x,n,m) :
  if n == 0 :
    return 1
  ans = 1
  while n > 1 :
    if n%2 != 0 :
      ans = ans*x%mod
    x = x*x%mod
    n //= 2
  return ans*x%mod
      
x,y = map(int,input().split())

for i in range(0,10**6+1) :
  xa = x - 1*i
  ya = y - 2*i
  if xa%2 == 0 and ya == 1*(xa//2) :
    n = i+xa//2
    # n!のあまりを求める
    np = 1
    for j in range(1,n+1) :
      np = (np*j)%mod
    #1/p!のあまりを求める
    pp = 1
    for j in range(1,i+1) :
      pp = pp*bpow(j,mod-2,mod)%mod
    #1/q!のあまりを求める
    qp = 1
    for j in range(1,(n-i)+1) :
      qp = qp*bpow(j,mod-2,mod)%mod
    print(np*pp*qp%mod)
    sys.exit()

print(0)

Submission status: Wrong Answer

Solution code:
import sys
mod = 10**9+7
def bpow(x,n,m) :
  if n == 0 :
    return 1
  ans = 1
  while n > 1 :
    if n%2 != 0 :
      ans = ans*x%mod
    x = x*x%mod
    n //= 2
  return ans*x%mod
      
x,y = map(int,input().split())

for i in range(1,10**6+1) :
  xa = x - 1*i
  ya = y - 2*i
  if xa%2 == 0 and ya == 1*(xa//2) :
    n = i+xa//2
    # n!のあまりを求める
    np = 1
    for j in range(1,n+1) :
      np = (np*j)%mod
    #1/p!のあまりを求める
    pp = 1
    for j in range(1,i+1) :
      pp = pp*bpow(j,mod-2,mod)%mod
    #1/q!のあまりを求める
    qp = 1
    for j in range(1,(n-i)+1) :
      qp = qp*bpow(j,mod-2,mod)%mod
    print(np*pp*qp%mod)
    sys.exit()

print(0)

Submission status: Wrong Answer

Solution code:
def com(n,r,mod):
    k=min(r,n-r)
    C=1
    for i in range(1,k+1):
        C=(C*(n+1-i)*pow(i,mod-2,mod))%mod
    return C
x,y=map(int,input().split())
mod = 10 ** 9 + 7
n = (2 * y - x) // 3
m = (2 * x - y) // 3
if (x + y) % 3 != 0 or (n<0 and m<0):
    print(0)
    exit()

print(com(n+m,n,mod))

Submission status: Wrong Answer

Solution code:
def com(n,r,mod):
    k=min(r,n-r)
    C=1
    for i in range(1,k+1):
        C=(C*(n+1-i)*pow(i,mod-2,mod))%mod
    return C
x,y=map(int,input().split())
mod = 10 ** 9 + 7
n = (2 * y - x) // 3
m = (2 * x - y) // 3
if (x + y) % 3 != 0 or (n<=0 and m<=0):
    print(0)
    exit()

print(com(n+m,n,mod))

Submission status: Wrong Answer

Solution code:
def factorial(N,MOD,r=True):
    fact = [1]*(N+1)
    rfact = [1]*(N+1)
    r = 1
    for i in range(1,N+1):
        fact[i] = r = r * i % MOD
    rfact[N] = r = pow(fact[N],MOD-2,MOD)
    for i in range(N, 0, -1):
        rfact[i-1] = r = r * i % MOD
    if r:
        return fact,rfact
    else:
        return fact
mod = 10**9 + 7
fact,rfact = factorial(10**6,mod)

def perm(n,k): #上のfactorialと併用
    return fact[n]*rfact[n-k]%mod
def comb(n,k): #上のfactorialと併用
    return fact[n]*rfact[k]*rfact[n-k]%mod

x,y = map(int,input().split())
if (x+y)%3:
    print(0)
    exit()
a = (-x+2*y)//3
b = (2*x-y)//3

print(comb(a+b,a) if a > 0 and b > 0 else 0)