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())
MOD = 10**9+7

N = 10**6+1
def pow_mod(x, n):
    if n == 0:
        return 1
    elif n % 2 == 0:
        return pow_mod(x * x % MOD, n // 2) % MOD
    else:
        return x * pow_mod(x * x % MOD, n // 2) % MOD

fact = [1]
for i in range(1,N+1):
    fact.append( (fact[i-1] * i) % MOD )

inv = [1] * (N+1)
inv[N] = pow_mod(fact[N], MOD-2)
for i in range(N, 1, -1):
    inv[i-1] = inv[i] * (i) % MOD

def cmb_mod(n,r):
    return fact[n] * inv[r] * inv[n-r] % MOD


cnt = 0
x,y = X,Y
while x > 0 and y > 0:
    if x == 2*y or y == 2*x:
        break
    x -= 3
    y -= 3
    cnt += 1

ans = 0
if x == 0 and y == 0:
    ans = cmb_mod(cnt*2, cnt)
elif x == 2*y or y == 2*x:
    ans = cmb_mod(cnt+2, cnt) * (cnt+1) % MOD
print(ans)

Submission status: Wrong Answer

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

def pow_k(xx, n):
    """
    O(log n)
    """
    if n == 0:
        return 1

    K = 1
    while n > 1:
        if n % 2 != 0:
            K = (K*xx)%di
        xx = (xx*xx)%di
        n //= 2

    return (K * xx)%di

if (2*y-x)%3>0 and (2*x-y)%3>0:
    print(0)
else:
    a = (2*y-x)//3
    b = (2*x-y)//3
    lis = [i for i in range(a+b+1)]
    lis[0]=1
    for i in range(1,a+b+1):
        lis[i] = (lis[i-1]*lis[i])%di
    lisr = [pow_k(i,di-2) for i in range(max(a,b)+1)]
    lisr[0]=1
    #print(lis,lisr)
    for i in range(1,max(a,b)+1):
        lisr[i] = (lisr[i-1]*lisr[i])%di
    tmp = (lis[a+b]*lisr[a])%di
    print((tmp*lisr[b])%di)

Submission status: Wrong Answer

Solution code:

class ModOperator:
    def __init__(self, MOD: int = 10 ** 9 + 7):
        self.MOD = MOD

    # x^n % MOD
    def mod_pow(self, x: int, n: int):
        bi = str(format(n, "b"))
        res = 1
        a = x
        for i in range(len(bi)):
            if n >> i & 1:
                res = (res * a) % self.MOD
            a = (a * a) % self.MOD
        return res
    
    # x! % MOD
    def mod_fact(self, x: int):
        res = 1
        for i in range(1, x + 1):
            res = res * i % self.MOD
        return res % self.MOD

    # x * (x - 1) * ... * (x - y + 1) % MOD
    def mod_partial_fact(self, x: int, y: int):
        res = 1
        for i in range(x - y + 1, x + 1):
            res = res * i % self.MOD
        return res % self.MOD

    # inverse of a number
    def mod_inv(self, x: int):
        return self.mod_pow(x, self.MOD - 2)
    
    # conmination nCk
    def mod_comb(self, n: int, k: int):
        numerator = self.mod_partial_fact(n, k)
        denomintator = self.mod_fact(k)
        return numerator * self.mod_inv(denomintator) % self.MOD


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

    p = (X + Y) // 3
    q = (X + Y) % 3
    if q == 0 and p < X < 2 * p and p < Y < 2 * p:
        op = ModOperator()
        res = op.mod_comb(p, X - p)
    else:
        res = 0
    print(res)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
mod = 10**9 + 7

class Combination:
    def __init__(self, n):
        self.facts = [1 for i in range(n+1)]
        self.invs = [1 for i in range(n+1)]
        
        for i in range(1, n+1):
            self.facts[i] = self.facts[i-1] * i % mod
            self.invs[i] = pow(self.facts[i], mod-2, mod)

    def ncr(self, n, r):
        return self.facts[n] * self.invs[r] * self.invs[n-r] % mod

    def nhr(self, n, r): 
        return self.ncr(n+r-1, n-1)

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

comb = Combination(max(X, Y))

if (2*Y - X) % 3 != 0 or (2*X - Y) % 3 != 0:
    print("0")
else:
    M = (2*Y - X) // 3
    N = (2*X - Y) // 3
    print(comb.ncr(M+N,M))

Submission status: Wrong Answer

Solution code:
# a + 2b = X
# 2a + b = Y
# 3b = 2X-Y
# b = (2X-Y)/3 ①
# 6a + (2X-Y) = 3Y
# 6a = 4Y-2X
# a = (2Y-X)/3 ②

# X=3,Y=3 の時
# b = 1, a = 1


def nCr(n, r, mod):
    if n < 0 or r < 0:
        return 0
    r = min(r, n - r)
    x = y = 1
    for i in range(r):
        x = (x * (n - i)) % mod
        y = (y * (i + 1)) % mod

    return (x * pow(y, mod - 2, mod)) % mod


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

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

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

print(nCr(a + b, a, 10**9 + 7))

Submission status: Wrong Answer

Solution code:
# a + 2b = X
# 2a + b = Y
# 3b = 2X-Y
# b = (2X-Y)/3 ①
# 6a + (2X-Y) = 3Y
# 6a = 4Y-2X
# a = (2Y-X)/3 ②

# X=3,Y=3 の時
# b = 1, a = 1


def nCr(n, r, mod):
    if n < 0 or r < 0:
        return 0
    r = min(r, n - r)
    x = y = 1
    for i in range(r):
        x = (x * (n - i)) % mod
        y = (y * (i + 1)) % mod

    return (x * pow(y, mod - 2, mod)) % mod


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

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

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

print(nCr(a + b, a, 10**9 + 7))

Submission status: Wrong Answer

Solution code:
# a + 2b = X
# 2a + b = Y
# 3b = 2X-Y
# b = (2X-Y)/3 ①
# 6a + (2X-Y) = 3Y
# 6a = 4Y-2X
# a = (2Y-X)/3 ②

# X=3,Y=3 の時
# b = 1, a = 1


def nCr(n, r, mod):
    r = min(r, n - r)
    x = y = 1
    for i in range(r):
        x = (x * (n - i)) % mod
        y = (y * (i + 1)) % mod

    return (x * pow(y, mod - 2, mod)) % mod


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

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

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

print(nCr(a + b, a, 10**9 + 7))

Submission status: Wrong Answer

Solution code:
# a + 2b = X
# 2a + b = Y
# 3b = 2X-Y
# b = (2X-Y)/3 ①
# 6a + (2X-Y) = 3Y
# 6a = 4Y-2X
# a = (2Y-X)/3 ②

# X=3,Y=3 の時
# b = 1, a = 1


def nCr(n, r, mod):
    r = min(r, n - r)
    x = y = 1
    for i in range(r):
        x = (x * (n - i)) % mod
        y = (y * (i + 1)) % mod

    return (x * pow(y, mod - 2, mod)) % mod


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

if (2 * X - Y) % 3 != 0 and (2 * Y - X) % 3 != 0:
    print(0)
    exit(0)

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

print(nCr(a + b, a, 10**9 + 7))

Submission status: Wrong Answer

Solution code:
MOD=10**9+7
def print_ans(a,b):
    print((a*b+1)%MOD)

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

x=X
y=Y
a=0
b=0
if X % 2 == 1:
    x -= 1
    y -= 2
    a+=1
if Y % 2 == 1:
    x -= 2
    y -= 1
    b+=1
if x < 0 or  y < 0 or abs(x - y) % 2 == 1:
    print(0)
else:
    if x > y:
        c=x-y
        a+=c
        x-=c*2
        y-=c
    elif y < x:
        c=y-x
        b+=c
        x-=c
        y-=c*2
    if x < 0 or y < 0:
        print(0)
    else:
        if x % 3 == 0:
            a+=x/3
            b+=y/3
            print_ans(a,b)
        else:
            print(0)

Submission status: Wrong Answer

Solution code:
X, Y = map(int, input().split())
n, mod = divmod(X + Y, 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 mod != 0:
    print(0)
else:
    r = Y - n
    print(combination(n, r))

Submission status: Wrong Answer

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

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

    # nCn2xを求める
    def combs(n,n2x,mod):
        facs = [1] * (n+1)
        # invs = [1] * (n+1)
        nfac = 1
        for i in range(1, n+1):
            nfac = nfac * i % mod
            facs[i] = nfac
            # invs[i] = pow(nfac, mod-2, mod)
        return nfac * (pow(facs[n2x], mod-2, mod) * pow(facs[n2x], mod-2, mod)) % mod

    print(combs(n, n2x, mod))

Submission status: Wrong Answer

Solution code:
import sys

stdin = sys.stdin
inf = 1 << 60
mod = 1000000007

sys.setrecursionlimit(10 ** 7)

ni      = lambda: int(ns())
nin     = lambda y: [ni() for _ in range(y)]
na      = lambda: list(map(int, stdin.readline().split()))
nan     = lambda y: [na() for _ in range(y)]
nf      = lambda: float(ns())
nfn     = lambda y: [nf() for _ in range(y)]
nfa     = lambda: list(map(float, stdin.readline().split()))
nfan    = lambda y: [nfa() for _ in range(y)]
ns      = lambda: stdin.readline().rstrip()
nsn     = lambda y: [ns() for _ in range(y)]
ncl     = lambda y: [list(ns()) for _ in range(y)]
nas     = lambda: stdin.readline().split()

class Combination:
    def __init__(self, max_n=100007, mod=mod):
        self.mod = mod
        self.fac = [0] * max_n
        self.finv = [0] * max_n
        self.inv = [0] * max_n

        self.fac[0] = 1
        self.fac[1] = 1
        self.finv[0] = 1
        self.finv[1] = 1
        self.inv[1] = 1
        for i in range(2, max_n):
            self.fac[i] = self.fac[i - 1] * i % self.mod
            self.inv[i] = self.mod - self.inv[self.mod % i] * (self.mod // i) % self.mod
            self.finv[i] = self.finv[i - 1] * self.inv[i] % self.mod
    
    def choose(self, n, k):
        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


x, y = na()

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

n, m = 0, 0
for i in range(10 ** 6 + 7):
    if (x - i) // 2 + 2 * i == y:
        n = i
        m = (x - i) // 2
        break

if n < 0 or m < 0:
    print(0)
    exit()
c = Combination(10 ** 6 + 7)
print(c.choose(n + m, n) % mod)

Submission status: Wrong Answer

Solution code:
import sys

stdin = sys.stdin
inf = 1 << 60
mod = 1000000007

sys.setrecursionlimit(10 ** 7)

ni      = lambda: int(ns())
nin     = lambda y: [ni() for _ in range(y)]
na      = lambda: list(map(int, stdin.readline().split()))
nan     = lambda y: [na() for _ in range(y)]
nf      = lambda: float(ns())
nfn     = lambda y: [nf() for _ in range(y)]
nfa     = lambda: list(map(float, stdin.readline().split()))
nfan    = lambda y: [nfa() for _ in range(y)]
ns      = lambda: stdin.readline().rstrip()
nsn     = lambda y: [ns() for _ in range(y)]
ncl     = lambda y: [list(ns()) for _ in range(y)]
nas     = lambda: stdin.readline().split()

class Combination:
    def __init__(self, max_n=100007, mod=mod):
        self.mod = mod
        self.fac = [0] * max_n
        self.finv = [0] * max_n
        self.inv = [0] * max_n

        self.fac[0] = 1
        self.fac[1] = 1
        self.finv[0] = 1
        self.finv[1] = 1
        self.inv[1] = 1
        for i in range(2, max_n):
            self.fac[i] = self.fac[i - 1] * i % self.mod
            self.inv[i] = self.mod - self.inv[self.mod % i] * (self.mod // i) % self.mod
            self.finv[i] = self.finv[i - 1] * self.inv[i] % self.mod
    
    def choose(self, n, k):
        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


x, y = na()

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

n, m = 0, 0
for i in range(10 ** 6 + 7):
    if (x - i) // 2 + 2 * i == y:
        n = i
        m = (x - i) // 2

if n < 0 or m < 0:
    print(0)
    exit()
c = Combination(10 ** 6 + 7)
print(c.choose(n + m, n) % mod)

Submission status: Wrong Answer

Solution code:
import sys

stdin = sys.stdin
inf = 1 << 60
mod = 1000000007

sys.setrecursionlimit(10 ** 7)

ni      = lambda: int(ns())
nin     = lambda y: [ni() for _ in range(y)]
na      = lambda: list(map(int, stdin.readline().split()))
nan     = lambda y: [na() for _ in range(y)]
nf      = lambda: float(ns())
nfn     = lambda y: [nf() for _ in range(y)]
nfa     = lambda: list(map(float, stdin.readline().split()))
nfan    = lambda y: [nfa() for _ in range(y)]
ns      = lambda: stdin.readline().rstrip()
nsn     = lambda y: [ns() for _ in range(y)]
ncl     = lambda y: [list(ns()) for _ in range(y)]
nas     = lambda: stdin.readline().split()

class Combination:
    def __init__(self, max_n=100007, mod=mod):
        self.mod = mod
        self.fac = [0] * max_n
        self.finv = [0] * max_n
        self.inv = [0] * max_n

        self.fac[0] = 1
        self.fac[1] = 1
        self.finv[0] = 1
        self.finv[1] = 1
        self.inv[1] = 1
        for i in range(2, max_n):
            self.fac[i] = self.fac[i - 1] * i % self.mod
            self.inv[i] = self.mod - self.inv[self.mod % i] * (self.mod // i) % self.mod
            self.finv[i] = self.finv[i - 1] * self.inv[i] % self.mod
    
    def choose(self, n, k):
        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


x, y = na()

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

n, m = 0, 0
for i in range(10 ** 6 + 7):
    if (x - i) // 2 + 2 * i == y:
        n = i
        m = (x - i) // 2

if n < 0 or m < 0:
    print(0)
    exit()
c = Combination(10 ** 6 + 7)
print(c.choose(n + m, n))

Submission status: Wrong Answer

Solution code:
mx = 1000000
md = int((1e+9)+7)

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

for i in range(2,mx+5):
    fac.append((fac[-1] * i) % md)
    inv.append((-inv[md%i] * (md // i)) % md)
    finv.append((finv[-1] * inv[-1]) % md)

def combination(n,k):
    return fac[n] * finv[k] * finv[n-k] % md

x,y = map(int,input().split())
if (x+y)%3 == 0 and abs(x-y) <= min(x,y):
    deps = (x+y)//3
    place = (deps//2 + deps%2) - (abs(x-y))//2
    print(combination(deps,place))
else:
    print(0)

Submission status: Wrong Answer

Solution code:
mx = 1000000
md = int((1e+9)+7)

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

for i in range(2,mx+1):
    fac.append((fac[-1] * i) % md)
    inv.append((-inv[md%i] * (md // i)) % md)
    finv.append((finv[-1] * inv[-1]) % md)

def combination(n,k):
    return fac[n] * finv[k] * finv[n-k] % md

x,y = map(int,input().split())
if (x+y)%3 == 0 and max(x,y) <= min(x,y)*2:
    deps = (x+y)//3
    place = (deps//2 + deps%2) - (max(x,y)-min(x,y))//2
    print(combination(deps,place))
else:
    print(0)

Submission status: Wrong Answer

Solution code:
mx = 1000000
md = int((1e+9)+7)

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

for i in range(2,mx+1):
    fac.append((fac[-1] * i) % md)
    inv.append((-inv[md%i] * (md // i)) % md)
    finv.append((finv[-1] * inv[-1]) % md)

def combination(n,k):
    return fac[n] * finv[k] * finv[n-k] % md

x,y = map(int,input().split())
if (x+y)%3 == 0:
    deps = (x+y)//3
    place = (deps//2 + deps%2) - (max(x,y)-min(x,y))//2
    print(combination(deps,place))
else:
    print(0)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

def comb(N, x):
    X = 1
    for i in range(N-x+1, N+1):
        X = X * i % mod
    Y = 1
    for j in range(1, x+1):
        Y = Y * j % mod
    Ym = pow(Y, mod-2, mod)
    return X * Ym

if (X+Y)%3 !=0:
  print(0)
  
else:
  n=(X+Y)//3
  r=(-2*X+Y)//(-3)
  ans=comb(n,r)
  print(ans%mod)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**7) 
x,y=map(int,input().split())
sum=0
def chess(i,j):
  a=0
  if i == x and j == y:
    a+=1
    return a
  elif i>x or j>y:
    return 0
  elif i<x and j<y:
    return chess(i+1,j+2)+chess(i+2,j+1)
  return a
  
print(chess(0,0)//10**9+7)

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

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

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

print(cmb(A+B, A, mod))

Submission status: Wrong Answer

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

def nCr(n,r,p):
    r=min(r,n-r)
    if r==0:
        return 1
    x,y=1,1
    for i in range(r):
        x=x*(n-i)%p
        y=y*(i+1)%p
    return x*pow(y,p-2,p)%p

if (x + y) % 3 != 0:
    print(0)
else:
    ans = 0
    n = (x + y)//3
    for i in range(n):
        a = n - i
        b = i
        if a + 2 * b == x and 2 * a + b == y:
            ans += nCr(n, min(a, b), 10**9 + 7)
            ans = ans % (10**9 + 7)
    print(ans)

Submission status: Wrong Answer

Solution code:
MOD = 10**9+7
X, Y = map(int, input().split())
x, y = X, Y
while 0 <= y:
    if x == 2*y:
        break
    x += 1
    y -= 1
else:
    print(0)
    exit()


def com(n, r):
    X = Y = 1
    if n-r < r:
        r = n-r
    for i in range(1, r+1):
        Y = Y*i % MOD
        X = X*(n-i+1) % MOD
    Y = pow(Y, MOD-2, MOD)
    return X*Y


print(com(x//2, x-X) % MOD)

Submission status: Wrong Answer

Solution code:
import sys
def input(): return sys.stdin.readline().rstrip()
from functools import reduce
def mod_comb4(n,r,mod=10**9+7):
    if r==1:return n
    elif r==0:return 1
    else:
        num=reduce(lambda x,y:x*y%mod,range(n,n-r,-1))
        den=reduce(lambda x,y:x*y%mod,range(1,r+1))
        return num*pow(den,mod-2,mod)%mod
def main():
    x,y=map(int,input().split())
    mod=10**9+7
    n=2*x-y
    m=2*y-x
    if n%3==0 and m%3==0 and n>0 and m>0:
        print(mod_comb4(n//3+m//3,n//3,mod))
    else:
        print(0)


if __name__=='__main__':
    main()

Submission status: Wrong Answer

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

mod=10**9+7
def C(n, r ,mod=10**9+7):
    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]) %mod

    return result % mod

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

Submission status: Wrong Answer

Solution code:
x,y=map(int,input().split())
if (x+y)%3!=0: print(0) ; exit()
mod=10**9+7
def C(n, r ,mod=10**9+7):
    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]) %mod

    return result % mod

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

print(C(a+b,a))

Submission status: Wrong Answer

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

mod=10**9+7
def C(n, r ,mod=10**9+7):
    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]) %mod

    return result % mod

a=(-x+2*y)/3
b=(2*x-y)/3
if a%1!=0 or b%1!=0:
    print(0) 
    exit()
a=int(a) ; b=int(b)
print(C(a+b,a))

Submission status: Wrong Answer

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

mod=10**9+7
def C(n, r ,mod=10**9+7):
    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]) %mod

    return result % mod

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

Submission status: Wrong Answer

Solution code:
from scipy.misc import comb
x, y = map(int, input().split())
t = (2*y-x)/3
s = (2*x-y)/3
if not t.is_integer() or t<0 or not s.is_integer() or s<0:
  print(0)
else:
  print(comb(s+t, min(s, t))%1000000007)

Submission status: Wrong Answer

Solution code:
from scipy.misc import comb
x, y = map(int, input().split())
t = (2*y-x)/3
s = (2*x-y)/3
if not t.is_integer() or t<0 or s.is_integer() or s<0:
  print(0)
else:
  print(comb(s+t, min(s, t))%1000000007)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
large_p = 10**9 + 7

def comb_mod(n, r, large_p):
    a, b = 1, 1
    r = min(r, n - r)
    for i in range(r):
        a = a * (n - i) % large_p
        b = b * (r - i) % large_p
    return a * pow(b, large_p - 2, large_p) % large_p

def main():
    x, y = map(int, input().split())
    if (x + y) % 3 != 0:
        print(0)
        sys.exit()
    p1, p2 = 0, 0
    for i1 in range(0, x + 1):
        if x - i1 == (y - i1 * 2) * 2:
            p1 = i1
            p2 = y - i1 * 2
            break
    if p1 < 0 or p2 < 0:
        print(0)
        sys.exit()

    r = comb_mod(p1 + p2, p1, large_p)
    print(r)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:

import sys
input = sys.stdin.readline
from math import factorial
large_p = 10**9 + 7

def comb_mod(n, r, large_p):
    a, b = 1, 1
    r = min(r, n - r)
    for i in range(r):
        a = a * (n - i) % large_p
        b = b * (r - i) % large_p
    return a * pow(b, large_p - 2, large_p) % large_p

def main():
    x, y = map(int, input().split())
    if (x + y) % 3 != 0:
        print(0)
        sys.exit()
    p1, p2 = 0, 0
    for i1 in range(1, x + 1):
        if x - i1 == (y - i1 * 2) * 2:
            p1 = i1
            p2 = y - i1 * 2
            break
    if p1 <= 0 or p2 <= 0:
        print(0)
        sys.exit()

    r = comb_mod(p1 + p2, p1, large_p)
    print(r)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
from math import factorial
large_p = 10**9 + 7

def comb_mod(n, r, large_p):
    a, b = 1, 1
    r = min(r, n - r)
    for i in range(r):
        a = a * (n - i) % large_p
        b = b * (r - i) % large_p
    return a * pow(b, large_p - 2, large_p) % large_p

def main():
    x, y = map(int, input().split())
    if (x + y) % 3 != 0:
        print(0)
        sys.exit()
    p1, p2 = 0, 0
    for i1 in range(1, x + 1):
        if x - i1 == (y - i1 * 2) * 2:
            p1 = i1
            p2 = y - i1 * 2
            break
    if p1 < 0 or p2 < 0:
        print(0)
        sys.exit()

    r = comb_mod(p1 + p2, p1, large_p)
    print(r)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
from math import factorial
large_p = 10**9 + 7

def comb_mod(n, r, large_p):
    a, b = 1, 1
    r = min(r, n - r)
    for i in range(r):
        a = a * (n - i) % large_p
        b = b * (r - i) % large_p
    return a * pow(b, large_p - 2, large_p) % large_p

def main():
    x, y = map(int, input().split())
    if (x + y) % 3 != 0:
        print(0)
        sys.exit()
    p1, p2 = 0, 0
    p1_2, p2_2 = 0, 0
    for i1 in range(1, x//2 + 1):
        if x - i1 == (y - i1 * 2) * 2:
            p1 = i1
            p2 = y - i1 * 2
            break
    for i2 in range(1, y//2 + 1):
        if (x - i2 * 2) * 2 == y - i2:
            p1_2 = i2
            p2_2 = x - i2 * 2

    p1 = min(p1, p1_2)
    p2 = min(p2, p2_2)
    if p1 < 0 or p2 < 0:
        print(0)
        sys.exit()

    r = comb_mod(p1 + p2, p1, large_p)
    print(r)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
from math import factorial
large_p = 10**9 + 7

def comb_mod(n, r, large_p):
    a, b = 1, 1
    r = min(r, n - r)
    for i in range(r):
        a = a * (n - i) % large_p
        b = b * (r - i) % large_p
    return a * pow(b, large_p - 2, large_p) % large_p

def main():
    x, y = map(int, input().split())
    p1, p2 = 0, 0
    p1_2, p2_2 = 0, 0
    for i1 in range(1, x//2 + 1):
        if x - i1 == (y - i1 * 2) * 2:
            p1 = i1
            p2 = y - i1 * 2
            break
    for i2 in range(1, y//2 + 1):
        if (x - i2 * 2) * 2 == y - i2:
            p1_2 = i2
            p2_2 = x - i2 * 2

    p1 = min(p1, p1_2)
    p2 = min(p2, p2_2)
    r = comb_mod(p1 + p2, p1, large_p)
    print(r)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
from math import factorial
large_p = 10**9 + 7

def comb_mod(n, r, large_p):
    a, b = 1, 1
    r = min(r, n - r)
    for i in range(r):
        a = a * (n - i) % large_p
        b = b * (r - i) % large_p
    return a * pow(b, large_p - 2, large_p) % large_p

def main():
    x, y = map(int, input().split())
    p1, p2 = 0, 0

    for i1 in range(1, x//2 + 1):
        if x - i1 == (y - i1 * 2) * 2:
            p1 = i1
            p2 = y - i1 * 2
            break
    r = comb_mod(p1 + p2, p1, large_p)
    print(r)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import math
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

X1, Y1 = map(int, input().split())

if X1 >= Y1:
  X = X1
  Y = Y1
  pass
else:
  X = Y1
  Y = X1
print(X, Y)  
if X > 2 * Y:
  print(0)
  exit()
else:
  pass

cnt1 = 0

while X < 2 * Y:
  X = X - 1
  Y = Y - 2
  cnt1 += 1

if X != 2 *Y:
  print(0)
  exit()
else:
  pass

cnt2 = Y
ans = combinations_count((cnt1 + cnt2), cnt2) % (10 ** 9 + 7)
print(ans)

Submission status: Wrong Answer

Solution code:
import math
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

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

if X >= Y:
  pass
else:
  X = Y
  Y = X
  
if X > 2 * Y:
  print(0)
  exit()
else:
  pass

cnt1 = 0

while X < 2 * Y:
  X = X - 1
  Y = Y - 2
  cnt1 += 1

if X != 2 *Y:
  print(0)
  exit()
else:
  pass

cnt2 = Y
ans = combinations_count((cnt1 + cnt2), cnt2) % (10 ** 9 + 7)
print(ans)

Submission status: Wrong Answer

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

def modpow(a, n):
    ret = 1
    while n > 0:
        if n & 1:
            ret = ret * a % MOD
        a = a * a % MOD
        n >>= 1
    return ret

def modinv(a):
    return modpow(a, MOD - 2)

def modfac(x):
    ret = 1
    for i in range(2, x + 1):
        ret *= i
        ret %= MOD
    return ret

if (X + Y) % 3 == 0:
    a = (2 * X - Y) // 3
    b = (2 * Y - X) // 3
    n = a + b
    r = a
    ans = modfac(n)
    ans *= modinv(modfac(n - r) * modfac(r))
    ans %= MOD
else:
    ans = 0
print(ans)

Submission status: Wrong Answer

Solution code:
a,b = map(int,input().split())
def fac(n):
    p = 1
    for i in range(1,n+1):
        p = (p*i) % (10**9+7)
    return p
if (2*a-b) % 3 == 0 and (-a+2*b) % 3 == 0:
    x = (2*a-b) // 3
    y = (-a+2*b) // 3
    print((fac(x+y)*pow(fac(x),10**9+5,10**9+7)*pow(fac(y),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

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

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

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

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




# 2項係数
def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0

    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n - r] % p

p = 10 ** 9 + 7
N = 10 ** 6
fact = [1, 1]
factinv = [1, 1]
inv = [0, 1]

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

print(cmb(int(n + m), int(m), p))

Submission status: Wrong Answer

Solution code:
# https://atcoder.jp/contests/abc145/tasks/abc145_d

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

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

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

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




# 2項係数
def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0

    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n - r] % p

p = 10 ** 9 + 7
N = 10 ** 6
fact = [1, 1]
factinv = [1, 1]
inv = [0, 1]

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

print(cmb(int(n + m), int(m), p))

Submission status: Wrong Answer

Solution code:
x, y  = map(int, input().split())
import itertools
mod = 10**9 + 7
def comb(a,b):
    x,y = 1,1
    for i in range(a):
        x *= (a+b-i)
        y *= (i+1)
        x %= mod 
        y %= mod
    gyakugen = pow(y,mod-2,mod)
    return x*gyakugen %mod
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)
    print(int(comb(a,b)))

Submission status: Wrong Answer

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

MOD = 1000000007
if (2*X-Y)%3!=0:
    print(0)
    sys.exit()

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

if A<0 or B<0:
    print(0)
    sys.exit()

ans = 1
inv = 1
for i in range(B):
    ans = ans * (A+B-i) %MOD
    inv = inv * (i+1) %MOD

ans = ans * pow(inv, MOD-2, MOD) %MOD
print(ans)

Submission status: Wrong Answer

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

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

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

ans = 1
inv = 1
for i in range(B):
    ans = ans * (A+B-i) %MOD
    inv = inv * (i+1) %MOD

ans = ans * pow(inv, MOD-2, MOD) %MOD
print(ans)

Submission status: Wrong Answer

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

MOD = 1000000007
if (2*X-Y)%3!=0:
    print(0)
    sys.exit()

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

ans = 1
inv = 1
for i in range(B):
    ans = ans * (A+B-i) %MOD
    inv = inv * (i+1) %MOD

ans = ans * pow(inv, MOD-2, MOD) %MOD
print(ans)