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


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

n = 0
m = 0

for n in range(X + 1):
    if (X - n) % 2 != 0:
        continue
    else:
        m = (X - n) // 2
        if 2 * n + m == Y:
            break

if m > n:
    n, m = m, n

# print(n, m)

p = 1
q = 1
mod = 10 ** 9 + 7

for i in range(m):
    p *= (n + m - i)
    p %= mod
    q *= (m - i)
    q %= mod

ans = p * pow(q, mod - 2, mod)

print(ans % mod)

Submission status: Wrong Answer

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

min_value = min(x, y)
max_value = max(x, y)
#print(min_value, max_value)
dif_value = max_value - min_value
#print(dif_value)
a_value   = min_value - dif_value
a_num     = int(a_value*2*(1/3))
#print(a_value, a_num)
n = dif_value + a_num
r = int(a_num*0.5)
#print(n, r)

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

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

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

if a_value % 3 == 0:
    print(comb(n, r, mod))
else:
    print(0)

Submission status: Wrong Answer

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

min_value = min(x, y)
max_value = max(x, y)
#print(min_value, max_value)
dif_value = max_value - min_value
#print(dif_value)
a_value   = min_value - dif_value
a_num     = int(a_value*2*(1/3))
#print(a_value, a_num)
n = dif_value + a_num
r = int(a_num*0.5)
#print(n, r)

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

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

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


if a_value % 3 == 0:
    print(comb(n, r, mod))
else:
    print(0)

Submission status: Wrong Answer

Solution code:
import sys
from fractions import gcd
from itertools import permutations, combinations, accumulate
from collections import deque
from heapq import heappush, heappop, heapify
from collections import deque

input = sys.stdin.readline
sys.setrecursionlimit(10**6)

MOD = 10**9 + 7

def cmbmod(n, r, k):
    #nCr mod kを求める（kは素数）
    p, q = 1, 1
    for i in range(r):
        p = p * (n-i) % k
        q = q * (r-i) % k
    return p * pow(q, k-2, k) % k

def main():
    x, y = tuple(map(int,input().split()))
    ok = 0
    ng = x + 1
    ans = 0

    if 2*y - x >= 0 and 2 * x - y >= 0:
        while abs(ng - ok) > 1:
            mid = (ok + ng) // 2
            if 2*y - x >= 3*mid:
                ok = mid
            else:
                ng = mid

            a = mid
            b = y - 2 * mid
            if a + 2*b == x and 2*a + b == y:
                ans = cmbmod(a + b, a, MOD)


    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
from fractions import gcd
from itertools import permutations, combinations, accumulate
from collections import deque
from heapq import heappush, heappop, heapify
from collections import deque

input = sys.stdin.readline
sys.setrecursionlimit(10**6)

MOD = 10**9 + 7

def cmbmod(n, r, k):
    #nCr mod kを求める（kは素数）
    p, q = 1, 1
    for i in range(r):
        p = p * (n-i) % k
        q = q * (r-i) % k
    return p * pow(q, k-2, k) % k

def main():
    x, y = tuple(map(int,input().split()))
    ok = 0
    ng = x + 1
    ans = 0

    if 2*y - x >= 0:
        while abs(ng - ok) > 1:
            mid = (ok + ng) // 2
            if 2*y - x >= 3*mid:
                ok = mid
            else:
                ng = mid

            a = mid
            b = y - 2 * mid
            if a + 2*b == x and 2*a + b == y:
                ans = cmbmod(a + b, a, MOD)


    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

n = (-X+2*Y)//3
m = (2*X-Y)//3
MOD = 10**9+7
    
def comb(n,r,MOD):
    x = n+1
    y = min(r,n-r)
    
    numer = 1
    denom = 1
    
    for i in range(1,r+1):
        numer = numer*(x-i)%MOD
        denom = denom*(i)%MOD
    
    return numer * pow(denom,MOD-2,MOD) % MOD
  
import sys

if n < 0 or m < 0:
    print(0)
    sys.exit()
if X+Y%3 != 0:
    print(0)
    sys.exit()
    
print(comb(n+m,n,MOD))

Submission status: Wrong Answer

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

n = (-X+2*Y)//3
m = (2*X-Y)//3
MOD = 10**9+7
 
def comb(n,r,MOD):
    x = n+1
    y = min(r,n-r)
    
    numer = 1
    denom = 1
    
    for i in range(1,r+1):
        numer = numer*(x-i)%MOD
        denom = denom*(i)%MOD
    
    return numer * pow(denom,MOD-2,MOD) % MOD
  
if (-X+2*Y)%3 == 0 and (2*X-Y)%3 == 0:
    print(comb(n+m,n,MOD))
else:
    print(0)

Submission status: Wrong Answer

Solution code:
X,Y = map(int,input().split())
mod = pow(10,9)+7
if X>Y:X,Y = Y,X
n,m = -1,-1
for i in range(X):
    if (X-i) == 2*(Y-2*i):
        n,m = i,Y-2*i
        break
if n==-1:print(0)
else:
    if n>m:n,m = m,n
    a,b,m=1,1,n+m
    for i in range(1,n+1):
        a=(a*m)%mod
        b=(b*i)%mod
        m-=1
    b = pow(b,mod-2,mod)
    print((a*b)%mod)

Submission status: Wrong Answer

Solution code:
X,Y = map(int,input().split())
mod = pow(10,9)+7
if X>Y:X,Y = Y,X
n,m = -1,-1
for i in range(X):
    if (X-i) == 2*(Y-2*i):
        n,m = i,Y-2*i
        break
if n==-1:print(n,m)
else:
    if n>m:n,m = m,n
    a,b,m=1,1,n+m
    for i in range(1,n+1):
        a=(a*m)%mod
        b=(b*i)%mod
        m-=1
    b = pow(b,mod-2,mod)
    print((a*b)%mod)

Submission status: Wrong Answer

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

mod = 10 ** 9 + 7


def choose(n, r):
    cx = 1
    cy = 1
    for i in range(r):
        cx = cx * (n - i) % mod
        cy = cy * (i + 1) % mod
    cy = pow(cy, mod - 2, mod)
    return cx * cy % mod


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

Submission status: Wrong Answer

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

mod = 10 ** 9 + 7


def choose(n, r):
    cx = 1
    cy = 1
    for i in range(r):
        cx = cx * (n - i) % mod
        cy = cy * (i + 1) % mod
    cy = pow(y, mod - 2, mod)
    return cx * cy % mod


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

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 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 = float('inf')
mod = 10 ** 9 + 7

x, y = MAP()


def power(x, y):
    if y == 0:
        return 1
    elif y == 1:
        return x % mod
    elif y % 2 == 0:
        return power(x, int(y/2)) ** 2 % mod
    else:
        return power(x, int((y-1)/2)) ** 2 * x % mod
# nCaとしたときのaのmaxがa_max
a_max = 10 ** 6
# a, bの最大値+2
fact = [1] * (a_max + 2)
# 逆元
for i in range(1, a_max + 1):
    fact[i] = (fact[i-1] * i) % mod
# combination
def C(n, a):
    tmp = 1
    for i in range(n, n-a, -1):
        tmp = (tmp * i) % mod
    return tmp * power(fact[a], mod - 2)


if (x + y) % 3 != 0:
    print(0)
else:
    A =  (2 * x - y) // 3
    B = (-x + 2 * y) // 3
    N = A + B
    print(C(N, A) % mod)

Submission status: Wrong Answer

Solution code:
class Combination:
    """
    O(n)の前計算を1回行うことで，O(1)でnCr mod mを求められる
    n_max = 10**6のとき前処理は約950ms (PyPyなら約340ms, 10**7で約1800ms)
    使用例：
    comb = Combination(1000000)
    print(comb(5, 3))  # 10
    """
    def __init__(self, n_max, mod=10**9+7):
        self.mod = mod
        self.modinv = self.make_modinv_list(n_max)
        self.fac, self.facinv = self.make_factorial_list(n_max)

    def __call__(self, n, r):
        if n < r:
            return 0
        return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n-r] % self.mod

    def make_factorial_list(self, n):
        # 階乗のリストと階乗のmod逆元のリストを返す O(n)
        # self.make_modinv_list()が先に実行されている必要がある
        fac = [1]
        facinv = [1]
        for i in range(1, n+1):
            fac.append(fac[i-1] * i % self.mod)
            facinv.append(facinv[i-1] * self.modinv[i] % self.mod)
        return fac, facinv

    def make_modinv_list(self, n):
        # 0からnまでのmod逆元のリストを返す O(n)
        modinv = [0] * (n+1)
        modinv[1] = 1
        for i in range(2, n+1):
            modinv[i] = self.mod - self.mod//i * modinv[self.mod%i] % self.mod
        return modinv

def main():
    X, Y = map(int, input().split())
    if (X + Y) % 3 != 0:
        print(0)
        exit()
    comb = Combination(10 ** 6)
    M = (2 * X - Y) // 3
    N = (2 * Y - X) // 3

    ans = comb(M + N, M)
    print(ans)



if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
a,b=map(int,input().split())
mod=10**9+7
def nCr_mod(n,r,mod):
  x=1
  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
m = (-a+2*b)//3
n = (2*a-b)//3
if (a*b)%3!=0 or m*n<0:
  print(0)
else:
  print(nCr_mod(m+n,n,mod))

Submission status: Wrong Answer

Solution code:
x,y=map(int,input().split())
mod=10**9+7
def nCr_mod(n,r,mod):
  x=1
  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
m = (-x+2*y)//3
n = (2*x-y)//3
if (x*y)%3!=0 or m*n<0:
  print(0)
else:
  print(nCr_mod(m+n,n,mod))

Submission status: Wrong Answer

Solution code:
x,y=map(int,input().split())
mod=10**9+7
def nCr_mod(n,r,mod):
  x=1
  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
if (x*y)%3!=0:
  print(0)
else:
  n=(2*x-y)//3
  m=(2*y-x)//3
  if m*n<0:
    print(0)
  else:
    print(nCr_mod(m+n,n,mod))

Submission status: Wrong Answer

Solution code:
x,y=map(int,input().split())
mod=10**9+7
def nCr_mod(n,r,mod):
  x=1
  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
if (x*y)%3!=0:
  print(0)
else:
  m=(2*x-y)//3
  n=(2*y-x)//3
  if m<0 or n<0:
    print(0)
  else:
    print(nCr_mod(m+n,m,mod))

Submission status: Wrong Answer

Solution code:
x,y=map(int,input().split())
mod=10**9+7
def nCr_mod(n,r,mod):
  x=1
  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
if x*y%3!=0:
  print(0)
else:
  m=(2*x-y)//3
  n=(2*y-x)//3
  if m<0 or n<0:
    print(0)
  else:
    print(nCr_mod(m+n,n,mod))

Submission status: Wrong Answer

Solution code:
x,y=map(int,input().split())
mod=10**9+7
def nCr_mod(n,r,mod):
  x=1
  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
if x*y%3!=0:
  print(0)
else:
  m=(2*x-y)/3
  n=(2*y-x)/3
  if m<0 or n<0:
    print(0)
  else:
    print(nCr_mod(int(m+n),int(n),mod))

Submission status: Wrong Answer

Solution code:
x,y=map(int,input().split())
mod=10**9+7
def nCr_mod(n,r,mod):
  x=1
  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
if x*y%3!=0:
  print(0)
else:
  m=(2*x-y)//3
  n=x-2*m
  if m<0 or n<0:
    print(0)
  else:
    print(nCr_mod(m+n,n,mod))

Submission status: Wrong Answer

Solution code:
x,y=map(int,input().split())
mod=10**9+7
def nCr_mod(n,r,mod):
  x=1
  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
if x*y%3!=0:
  print(0)
else:
  m=int((2*x-y)/3)
  n=int(x-2*m)
  if m<0 or n<0:
    print(0)
  else:
    print(nCr_mod(m+n,n,mod))

Submission status: Wrong Answer

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

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

s=(X+Y)//3
n=(-X+2*Y)//3
m=(-Y+2*X)//3
# print('n={}'.format(n))
# print('m={}'.format(m))
if n<0 or m<0:
    print(0)
    exit()

nm=1
nn=1
# print('nm----')
for i in range(n,n+m+1):
    nm*=i
    nm%=mod
    # print(nm)
# print('nn----')
for i in range(1,n+1):
    nn*=i
    nn%=mod
    # print(nn)

print(nm//nn%mod)

Submission status: Wrong Answer

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

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

if (x+y)%3!=0:
    print(0)
elif x*2<y or y*2<x:
    print(0)
else:
    n,m=y//3,y//3
    p = 10**9+7
    N = 2*10**6+1  # 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) % p)
        inv.append((-inv[p % i] * (p // i)) % p)
        factinv.append((factinv[-1] * inv[-1]) % p)
    print(cmb(n+m,n,p))

Submission status: Wrong Answer

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

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

if (x+y)%3!=0:
    print(0)
elif x*2<y or y*2<x:
    print(0)
else:
    n,m=y//3,y//3
    p = 10**9+7
    N = 10**6+1  # 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) % p)
        inv.append((-inv[p % i] * (p // i)) % p)
        factinv.append((factinv[-1] * inv[-1]) % p)
    print(cmb(n+m,n,p))

Submission status: Wrong Answer

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

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

if (x+y)%3!=0:
    print(0)
else:
    n,m=y//3,y//3
    p = 10**9+7
    N = 10**6+1  # 必要分だけ用意する
    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) % p)
        inv.append((-inv[p % i] * (p // i)) % p)
        factinv.append((factinv[-1] * inv[-1]) % p)
    print(cmb(n+m,n,p))

Submission status: Wrong Answer

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

x,y=map(int,input().split())
if (x+y)%3 or max(x,y)>min(x,y)*2:
   print(0)
   exit()

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

print(nCr(int(f),int(m)))

Submission status: Wrong Answer

Solution code:
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys
import collections

mod = 10**9+7

#modに対応して高速なコンビネーションが求められる
# 階乗 & 逆元計算



d = collections.deque()
def LI(): return list(map(int, sys.stdin.readline().split()))

X,Y = LI()

if (X + Y) % 3 != 0:
    ans = 0
else:
    n = 10 ** 6
    factorial = [1]
    inverse = [1]
    for i in range(1, n+2):
        factorial.append(factorial[-1] * i % mod)
        inverse.append(pow(factorial[-1], mod-2, mod))

    def combinations_count(n,r):
        if n-r < 0:
            return 0
        return factorial[n]*inverse[r]*inverse[n-r]%mod
    m = int(X * 2 / 3 - Y / 3)
    n = int(Y * 2 / 3 - X / 3)
    if (X+Y) / 3 > X or (X + Y) / 3 > Y or m < 0 or n < 0:
        ans = 0
    
    else:
        ans = combinations_count(m + n, n)
print(ans)

Submission status: Wrong Answer

Solution code:
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys
import collections

mod = 10**9+7

#modに対応して高速なコンビネーションが求められる
# 階乗 & 逆元計算



d = collections.deque()
def LI(): return list(map(int, sys.stdin.readline().split()))

X,Y = LI()

if (X + Y) % 3 != 0:
    ans = 0
else:
    n = 10 ** 6
    factorial = [1]
    inverse = [1]
    for i in range(1, n+2):
        factorial.append(factorial[-1] * i % mod)
        inverse.append(pow(factorial[-1], mod-2, mod))

    def combinations_count(n,r):
        if n-r < 0:
            return 0
        return factorial[n]*inverse[r]*inverse[n-r]%mod
    m = int(X * 2 / 3 - Y / 3)
    n = int(Y * 2 / 3 - X / 3)
    if (X+Y) / 3 > X or (X + Y) / 3 > Y:
        ans = 0
    else:
        ans = combinations_count(m + n, n)
print(ans)

Submission status: Wrong Answer

Solution code:
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys
import collections

mod = 10**9+7

#modに対応して高速なコンビネーションが求められる
# 階乗 & 逆元計算



d = collections.deque()
def LI(): return list(map(int, sys.stdin.readline().split()))

X,Y = LI()

if (X + Y) % 3 != 0:
    ans = 0
else:
    n = 10 ** 6
    factorial = [1]
    inverse = [1]
    for i in range(1, n+2):
        factorial.append(factorial[-1] * i % mod)
        inverse.append(pow(factorial[-1], mod-2, mod))

    def combinations_count(n,r):
        if n-r < 0:
            return 0
        return factorial[n]*inverse[r]*inverse[n-r]%mod
    m = int(X * 2 / 3 - Y / 3)
    n = int(Y * 2 / 3 - X / 3)
    if (X+Y) / 3 > X or (X + Y) > Y:
        ans = 0
    else:
        ans = combinations_count(m + n, n)
print(ans)

Submission status: Wrong Answer

Solution code:
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys
import collections

mod = 10**9+7

#modに対応して高速なコンビネーションが求められる
# 階乗 & 逆元計算



d = collections.deque()
def LI(): return list(map(int, sys.stdin.readline().split()))

X,Y = LI()

if (X + Y) % 3 != 0:
    ans = 0
else:
    n = 10 ** 6
    factorial = [1]
    inverse = [1]
    for i in range(1, n+2):
        factorial.append(factorial[-1] * i % mod)
        inverse.append(pow(factorial[-1], mod-2, mod))

    def combinations_count(n,r):
        if n-r < 0:
            return 0
        return factorial[n]*inverse[r]*inverse[n-r]%mod
    m = int(X * 2 / 3 - Y / 3)
    n = int(Y * 2 / 3 - X / 3)
    if m < 0 or n < 0:
        ans = 0
    else:
        ans = combinations_count(m + n, n)
print(ans)

Submission status: Wrong Answer

Solution code:
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys
import collections

mod = 10**9+7

#modに対応して高速なコンビネーションが求められる
# 階乗 & 逆元計算



d = collections.deque()
def LI(): return list(map(int, sys.stdin.readline().split()))

X,Y = LI()

if (X + Y) % 3 != 0:
    ans = 0
else:
    n = 10 ** 6
    factorial = [1]
    inverse = [1]
    for i in range(1, n+2):
        factorial.append(factorial[-1] * i % mod)
        inverse.append(pow(factorial[-1], mod-2, mod))

    def combinations_count(n,r):
        if n-r < 0:
            return 0
        return factorial[n]*inverse[r]*inverse[n-r]%mod
    m = int(X * 2 / 3 - Y / 3)
    n = int(Y * 2 / 3 - X / 3)
    # print(m,n)
    ans = combinations_count(m + n, n)
print(ans)

Submission status: Wrong Answer

Solution code:
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys
import collections

mod = 10**9+7

#modに対応して高速なコンビネーションが求められる
# 階乗 & 逆元計算

n = 10 ** 6
factorial = [1]
inverse = [1]
for i in range(1, n+2):
    factorial.append(factorial[-1] * i % mod)
    inverse.append(pow(factorial[-1], mod-2, mod))

def combinations_count(n,r):
    if n-r < 0:
        return 0
    return factorial[n]*inverse[r]*inverse[n-r]%mod

d = collections.deque()
def LI(): return list(map(int, sys.stdin.readline().split()))

X,Y = LI()

if (X + Y) % 3 != 0:
    ans = 0
else:
    m = int(X * 2 / 3 - Y / 3)
    n = int(Y * 2 / 3 - X / 3)
    # print(m,n)
    ans = combinations_count(m + n, n)
print(ans)

Submission status: Wrong Answer

Solution code:
import math
#from scipy.special import comb
#def permod(n, r):
  #return (math.factorial(n) // math.factorial(n - r)) % (10 ** 9 + 7)

from operator import mul
from functools import reduce

def com(n, r):
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom

def main():
  X,Y = map(int,input().split())
  
  if (X + Y) % 3 != 0:
    print(0)
    
  else:
    a = Y - (X + Y) // 3
    b = X - (X + Y) // 3
    
    ans = com(a + b,b)
    
    print(ans)
    
main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/python3
# -*- coding:utf-8 -*-

MAX = 10**9 + 7

def pow_mod_p(n, k, p):
  x = 1
  while k:
    if k % 2 == 1:
      x *= n
      x %= p
    n **= 2
    n %= p
    k >>= 1
  return x

def comb_mod_p(n, k, p):
  x = 1
  for ik in range(k):
    x *= ((n-ik) * pow_mod_p(ik+1, p-2, p))
    x %= p
  return x

def main():
  x, y = map(int, input().strip().split())
  m = (2*x -   y)/3
  k = ( -x + 2*y)/3
  if m - int(m) != 0 or k - int(k) != 0:
    print(0)
    return 
  m, k = map(int, [m, k])
  if m < k:
    m, k = k, m
  print(comb_mod_p((m+k), k, MAX))
  
  
if __name__=='__main__':
  main()

Submission status: Wrong Answer

Solution code:

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


def prime_mod(n, m):
    S = 1
    for i in range(1, n+1):
        S *= i
        S %= m
    return S


def prime_inv_mod(n, m):
    invs = [0] * (n + 1)
    invs[1] = 1
    for i in range(2, n + 1):
        invs[i] = m - invs[m % i] * (m//i) % m
    return invs


a = 2 * Y - X
b = 2 * X - Y
if a % 3 != 0 or b % 3 != 0:
    print(0)
else:
    a //= 3
    b //= 3
    upper = prime_mod(a+b, mod)
    mod_inv = prime_inv_mod(max(a, b), mod)

    lower1 = 1
    lower2 = 1
    for i in range(1, a + 1):
        lower1 *= mod_inv[i]
        lower1 %= mod
    for i in range(1, b + 1):
        lower2 *= mod_inv[i]
        lower2 %= mod

    print((upper*lower1*lower2) % mod)

Submission status: Wrong Answer

Solution code:

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


def prime_mod(n, m):
    S = 1
    for i in range(1, n+1):
        S *= i
        S %= m
    return S


def prime_inv_mod(n, m):
    invs = [0] * (n + 1)
    invs[1] = 1
    for i in range(2, n + 1):
        invs[i] = m - invs[m % i] * (m//i) % m
    return invs


a = 2 * Y - X
b = 2 * X - Y
if a % 3 != 0 or b % 3 != 0:
    print(0)
else:
    a //= 3
    b //= 3
    upper = prime_mod(a+b, mod)
    mod_inv = prime_inv_mod(max(a, b), mod)

    lower1 = 1
    lower2 = 1
    for i in range(1, max(a, b)+1):
        lower1 *= mod_inv[i]
        lower1 %= mod
        if i == min(a, b):
            lower2 = lower1
    print((upper*lower1*lower2) % mod)

Submission status: Wrong Answer

Solution code:
import math
math.factorial(10000)

Submission status: Wrong Answer

Solution code:
import math

MOD = 1000000007

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

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

for i in range(X):
    n = i
    m = (X-n) // 2

    if n + 2*m == X and 2*n + m == Y:
        break

print((math.factorial(n+m) // (math.factorial(m) * math.factorial(n))) % MOD)

Submission status: Wrong Answer

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

print(ans%M)

Submission status: Wrong Answer

Solution code:
M=10**9+7
x,y=map(int,input().split())
if (2*x-y)%3!=0 or (2*y-x)%3!=0:
  print(0)
elif 2*x-y<0 or 2*y-x<0:
  print(0)
else:
  a=(2*y-x)//3
  b=(2*x-y)//3
  f1,f2=1,1
  for i in range(a+1,a+b+1):
    f1*=i
    f1%=M
  for i in range(1,a+1):
    f2*=i
    f2%=M
  ans=f1*pow(f2,M-2,M)
  print(ans%M)

Submission status: Wrong Answer

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

def func(a):
	if a > 1:
		a = a*(a-1)
		func(a)
	else:
		return a




if (X+Y) %3 != 0:
	print(0)
else:
	"""
	nを(+1,+2)の回数
	mを(+2,+1)の回数とする
	n+2m = X  
	2n+m = Y
	
	n = (2Y-X)/3
	m = (2X-Y)/3

	"""

	n = (2*Y-X)//3
	m = (2*X-Y)//3
	#print(n,m)
	if n<0 or m<0:
		print(0)
	else:
		count = 1
		for i in reversed(range(m+n+1)):
			if i == 0:
				break
			count = i*count
			#print(m+n)
		if count>10**9+7:
			count = count%(10**9+7)
		print(count)

Submission status: Wrong Answer

Solution code:
fac = [0] * 700000
finv = [0] * 700000
inv = [0] * 700000
mod = 1000000007

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

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

if (x + y) % 3 == 0:
    k = (2 * x - y) // 3
    l = (2 * y - x) // 3
    print(fac[k + l] * (finv[k] * finv[l] % mod) % mod)
else:
    print(0)

Submission status: Wrong Answer

Solution code:
import sys

fac = [0] * 700000
finv = [0] * 700000
inv = [0] * 700000
mod = 1000000007

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

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

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

k = (2 * x - y) // 3
l = (2 * y - x) // 3

print(fac[k + l] * (finv[k] * finv[l] % mod) % mod)

Submission status: Wrong Answer

Solution code:
import sys

fac = [0] * 700000
finv = [0] * 700000
inv = [0] * 700000
mod = 1000000007

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

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

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

k = (2 * x - y) // 3
l = (2 * y - x) // 3

print(fac[k + l] * (finv[k] * finv[l] % mod) % mod)

Submission status: Wrong Answer

Solution code:
import sys

fac = [0] * 700000
finv = [0] * 700000
inv = [0] * 700000
mod = 1000000007

def cominit():
    fac[0] = fac[1] = 0
    finv[0] = finv[1] = 0
    inv[1] = 0
    for i in range(2, 700000):
        fac[i] = fac[i - 1] * i % mod
        inv[i] = mod - inv[mod % i] * (mod // i) % mod
        finv[i] = finv[i - 1] * inv[i] % mod

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

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

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

k = (2 * x - y) // 3
l = (2 * y - x) // 3

print(com(k + l, k))

Submission status: Wrong Answer

Solution code:
def main():
    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 (2*Y-X)%3!=0 or (2*X-Y)%3!=0:
        print(0)
    else:
        s=abs((2*Y-X)//3)
        t=abs((2*X-Y)//3)
        print(cmb(s+t,s,mod))

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import math

#互いに素なa,bについて、a*x+b*y=1の一つの解
def extgcd(a,b):
    r = [1,0,a]
    w = [0,1,b]
    while w[2]!=1:
        q = r[2]//w[2]
        r2 = w
        w2 = [r[0]-q*w[0],r[1]-q*w[1],r[2]-q*w[2]]
        r = r2
        w = w2
    #[x,y]
    return [w[0],w[1]]

# aの逆元(mod m)を求める。(aとmは互いに素であることが前提)
def mod_inv(a,m):
    x = extgcd(a,m)[0]
    return (m+x%m)%m

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

print (d)

Submission status: Wrong Answer

Solution code:
import math

#互いに素なa,bについて、a*x+b*y=1の一つの解
def extgcd(a,b):
    r = [1,0,a]
    w = [0,1,b]
    while w[2]!=1:
        q = r[2]//w[2]
        r2 = w
        w2 = [r[0]-q*w[0],r[1]-q*w[1],r[2]-q*w[2]]
        r = r2
        w = w2
    #[x,y]
    return [w[0],w[1]]

# aの逆元(mod m)を求める。(aとmは互いに素であることが前提)
def mod_inv(a,m):
    x = extgcd(a,m)[0]
    return (m+x%m)%m

x,y = map(int,input().split())
m = 0.0
n = 0.0
m = (2*x-y) / 3
n = (2*y-x) / 3
if m.is_integer() and n.is_integer():
    n = int(n)
    m = int(m)
    z = [i for i in range(n+1,n+m+1)]


    d = 1
    for i in range(n+1,n+m+1):
        d = (d * i ) % (10**9 + 7)
    for i in range(2,m+1):
        d = (d * mod_inv(i,10**9 + 7)) % (10**9 + 7)

    print (d)
else:
    print (0)

Submission status: Wrong Answer

Solution code:
import sys
import math

def comb(n, r):
    x = 1
    for i in range(r):
        x *= (n - i)
    for i in range(r):
        x //= (r - i)
    return x

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

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

k = (2 * x - y) // 3
l = (2 * y - x) // 3

print(comb(k + l, k) % (10 ** 9 + 7))