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 math

X, Y = map(int, input().split())
a = (2*X-Y)/3
b = (2*Y-X)/3

def fact_mod(n):
  ans = 1
  numOfMod = 0
  while n > 0:
    ans *= n
    while ans > (10**9 + 7):
      ans /= (10**9 + 7)
      numOfMod += 1
    n -= 1
  return ans, numOfMod

if a.is_integer() and b.is_integer():
  x, y = fact_mod(a+b)
  x_1, y_1 = fact_mod(a)
  x_2, y_2 = fact_mod(b)
  
  while x/(x_1*x_2) < 0:
    x *= (10**9 + 7)
    y -= 1
  print(x/(x_1*x_2))
  
else:
  print(0)

Submission status: Wrong Answer

Solution code:
def two_int():
    N, K = map(int, input().split())
    return N,K

def one_int():
    return int(input())

def one_str():
    return input()

def many_int():
    return list(map(int, input().split()))

import itertools

X, Y = two_int()

def comb(n,k,p):
  """power_funcを用いて(nCk) mod p を求める"""
  from math import factorial
  if n<0 or k<0 or n<k: return 0
  if n==0 or k==0: return 1
  a=factorial(n) %p
  b=factorial(k) %p
  c=factorial(n-k) %p
  return (a*power_func(b,p-2,p)*power_func(c,p-2,p))%p
def power_func(a,b,p):
  """a^b mod p を求める"""
  if b==0: return 1
  if b%2==0:
    d=power_func(a,b//2,p)
    return d*d %p
  if b%2==1:
    return (a*power_func(a,b-1,p ))%p

def calc(a, b, p):
    if b==0:
        return 1
    elif b%2==0:
        d=calc(a,b//2, p)
        return (d*d)%p
    else:
        return (a*calc(a,b-1,p))%p

dan = (X+Y)/3
if dan.is_integer():
    n = int(dan+1)
    k = X-(n-1)+1
    print(n,k)
    print(int(comb(n-1,k-1,(10**9+7))))
else:
    print(0)

Submission status: Wrong Answer

Solution code:
import math

X, Y = map(int, input().split())
a = (2*X-Y)/3
b = (2*Y-X)/3

def fact_mod(n):
  ans = 1
  numOfMod = 0
  while n > 0:
    ans *= n
    while ans > (10**9 + 7):
      ans /= (10**9 + 7)
      numOfMod += 1
    n -= 1
  return ans, numOfMod

if a.is_integer() and b.is_integer():
  x, y = fact_mod(a+b)
  x_1, y_1 = fact_mod(a)
  x_2, y_2 = fact_mod(b)
  
  while x/(x_1*x_2) < 0:
    x *= (10**9 + 7)
    y -= 1
  print(y)
  print(y_1)
  print(y_2)
  print(x/(x_1*x_2))
  
else:
  print(0)

Submission status: Wrong Answer

Solution code:
def is_integer(n):
    try:
        float(n)
    except ValueError:
        return False
    else:
        return float(n).is_integer()

def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

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

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

    return result

X,Y = map(int,input().split())
a = (2*Y-X)/3
b = (2*X-Y)/3
if (X == 0 or Y == 0):
    print(0)
    exit()
if is_integer(a):
    a = (2*Y-X)//3
else:
    print(0)
    exit()
if is_integer(b):
    b = (2*X-Y)//3
else:
    print(0)
    exit()
n = a+b
mod = 10**9+7 
ans = cmb(n,a)% mod
print(ans)

Submission status: Wrong Answer

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

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

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

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

Submission status: Wrong Answer

Solution code:
def comb(n,k,p):
  """power_funcを用いて(nCk) mod p を求める"""
  from math import factorial
  if n<0 or k<0 or n<k: return 0
  if n==0 or k==0: return 1
  a=factorial(n) %p
  b=factorial(k) %p
  c=factorial(n-k) %p
  return (a*power_func(b,p-2,p)*power_func(c,p-2,p))%p
def power_func(a,b,p):
  """a^b mod p を求める"""
  if b==0: return 1
  if b%2==0:
    d=power_func(a,b//2,p)
    return d*d %p
  if b%2==1:
    return (a*power_func(a,b-1,p ))%p


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

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

val = [X,Y]
val_min = min(val)

val_min_sho = int(val_min/3)

X_henkan = X - 3*val_min_sho
Y_henkan = Y - 3*val_min_sho
if (X_henkan == 1 and Y_henkan == 2) or (X_henkan == 2 and Y_henkan == 1):
    n = (val_min_sho)*2 + 1
    n_2 = int(n/2)
    print(comb(n,n_2,10**9+7))
elif (X_henkan == 0 and Y_henkan == 0):
    n = (val_min_sho)*2
    n_2 = int(n/2)
    print(comb(n,n_2,10**9+7))
else:
    print(0)

Submission status: Wrong Answer

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

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

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

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

MOD = 10**9+7

if (-Y + 2*X) % 3 == 0 and (2*Y - X) %3 == 0:
    x = (-Y + 2*X) // 3
    y = (2*Y - X) // 3
    
    result = comb(x+y,x,MOD) 
    print(result % MOD)
    
else:
    print(0)

Submission status: Wrong Answer

Solution code:
def nCr(n, r):

    
    r = min(r, n-r)

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

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

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

Submission status: Wrong Answer

Solution code:
def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

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

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

    return result

x,y=map(int,input().split())
if (2*y-x)%3==0 and (2*x-y)%3==0:
    a=(2*y-x)//3
    b=(2*x-y)//3
    ans=cmb(a+b,a)
    print(ans%(10**9+7))
else:
    print('0')

Submission status: Wrong Answer

Solution code:
import math
from operator import mul
from functools import reduce

def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

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

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

    return result

x,y=map(int,input().split())
if (x+y)%3!=0:
    print(0)
    exit()
if (-x+2*y)/3%1!=0:
    print(0)
    exit()
if (-y+2*x)/3%1!=0:
    print(0)
    exit()
x_=int((-x+2*y)/3)
y_=int((2*x-y)/3)

print(cmb(x_+y_,x_)%(10**9+7))

Submission status: Wrong Answer

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

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 )

Z=X+Y
if Z%3 == 0:
    D=int(Z/3)
    if X>=Y:
        print(cmb(D,abs(D-Y),MOD))
    else:
        print(cmb(D,abs(D-X),MOD))
else:
    print(0)

Submission status: Wrong Answer

Solution code:
from operator import mul
from functools import reduce

def cmb(n,r):
  r = min(r, n-r)
  ans = 1
  for i in range(1,r+1):
    ans *= n
    n -= 1
    ans //= i
    ans %= (10**9+7)
  return ans

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

max_diff = min(X,Y)
if (X+Y) % 3 == 0:
  n = (X + Y) // 3
  k = max_diff - n
  print(n,k)
  ans = cmb(n, k)
else:
  ans = 0

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import math
stdin = sys.stdin
mod = 10**9 + 7

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
sa = lambda h: [list(map(int, stdin.readline().split())) for i in range(h)]
def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

N = 10**6
g1 = [1, 1]
g2 = [1, 1]
inverse = [0, 1]

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

x, y = na()
a = (-1/3) * x + (2/3) * y
b = (2/3) * x - (1/3) * y
if a.is_integer() and b.is_integer() and a>0 and b>0:
    print(cmb(int(a+b),int(a), mod))
else:
    print(0)

Submission status: Wrong Answer

Solution code:
import math
import sys
sys.setrecursionlimit(10**7)
x,y = list(map(int, input().split()))
mod = 7 + (10**9)
ans = 0
def factorial(x):
    if x == 0 or x == 1:
        return 1
    k = (x * factorial(x - 1)) % mod
    return k
if (x + y) % 3 != 0:
    print(0)
else:
    for i in range(x+1):
        if (x - i) % 2 != 0:
            continue
        else:
            l = (x - i) // 2
            if y == 2 * i + l:
                #print("k {},l {}".format(k,l))
                ans += factorial(i+l) / (factorial(i) * factorial(l))
                ans %= mod
print(int(ans))

Submission status: Wrong Answer

Solution code:
INF = 1000000000+7

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

n = a//3
m = b//3
nm = n+m

def cmb(n,r):
    if r > n:
        return 0
    if n - r < r:
         r = n - r
    if r > n:
        return 0
    if r == 0:
        return 1
    if r == 1:
        return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

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

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

    return result

ans = cmb(nm,n)
print(ans%INF)

Submission status: Wrong Answer

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

if X==0 or Y==0:
    print(0)
    exit()

N=min(X,Y)
factl=[1]
for i in range(1,N+1):
    factl.append(factl[-1]*i%mod)
invl=[pow(factl[-1],mod-2,mod)]
for i in range(N,0,-1):
    invl.append(invl[-1]*i%mod)
invl.reverse()
def Comb(a,b):
    return factl[a]*invl[a-b]*invl[b]%mod
if X//Y == 2 and X%Y==0:
    print(Y)
    exit()

div=Y//3
x,y=div,div
X,Y=X-3*div,Y-3*div
if X==0 and Y==0:
    pass
elif X==0 or Y==0:
    print(0)
    exit()
elif X//Y == 2 and X%Y==0:
    x+=Y
else:
    print(0)
    exit()

print(Comb(x+y,y))

Submission status: Wrong Answer

Solution code:
import math
x, y = map(int, input().split())
mnum = math.ceil(x/2)
ans = math.factorial(mnum)
print(ans//(10**9+7))

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
l=[[0 for i in range(m+1)] for j in range(n+1)]
l[0][0]=1
for i in range(n+1):
    for j in range(m+1):
        if l[i][j]>0:
            try:
                l[i+1][j+2]=(l[i+1][j+2]+1)%(10**9+7)
            except:
              pass
            try:
                l[i+2][j+1]+(l[i+2][j+1]+1)%(10**9+7)
            except:
                pass
# print(*l,sep="\n")
print(l[n][m]%(10**9+7))

Submission status: Wrong Answer

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

MOD = 10 ** 9 + 7


def no():
  print(0)
  exit(0)


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

if not 1 / 2 <= x / y <= 2:
  no()

if x % 3 == 1:
  x -= 1
  y -= 2

if x % 3 == 2:
  x -= 2
  y -= 1


n = x // 3 + y // 3
r = x // 3
# c = 1
# for i in range(n, n - r, -1):
#   c *= i
#   c %= MOD
# for i in range(1, r + 1):
#   c //= i
# c %= MOD
# import math
# print(math.factorial(n)//math.factorial(n-r)//math.factorial(r)%MOD)


# def c(n, r):
#   if r == 1:
#     return n
#   if c == 1:
#     return 1
#   return (c(n - 1, r) + c(n - 1, r - 1)) % MOD
#print(c(n, r))

# https://fishi.devtail.io/weblog/2015/06/25/computing-large-binomial-coefficients-modulo-prime-non-prime/

"""
Using Fermat's little theorem to calculate nCk mod m, m is prime
Computation O(n)
"""

# modular exponentiation: b^e % mod
# python's built-in pow(b,e,mod) would be faster than this function,
# but I am still keeping it here for completion


def mod_exp(b, e, mod):
  r = 1
  while e > 0:
    if (e & 1) == 1:
      r = (r * b) % mod
    b = (b * b) % mod
    e >>= 1

  return r

# get degree of p in n! (exponent of p in the factorization of n!)


def fact_exp(n, p):
  e = 0
  u = p
  t = n
  while u <= t:
    e += t // u
    u *= p

  return e

# Using Fermat's little theorem to compute nCk mod p
# considering cancelation of p in numerator and denominator
# Note: p must be prime


def fermat_binom_advanced(n, k, p):
  # check if degrees work out
  num_degree = fact_exp(n, p) - fact_exp(n - k, p)
  den_degree = fact_exp(k, p)
  if num_degree > den_degree:
    return 0

  if k > n:
    return 0

  # calculate numerator and cancel out occurrences of p
  num = 1
  for i in range(n, n - k, -1):
    cur = i
    while cur % p == 0:
      cur //= p
    num = (num * cur) % p

  # calculate denominator and cancel out occurrences of p
  denom = 1
  for i in range(1, k + 1):
    cur = i
    while cur % p == 0:
      cur //= p
    denom = (denom * cur) % p

  # numerator * denominator^(p-2) (mod p)
  return (num * mod_exp(denom, p - 2, p)) % p


if __name__ == '__main__':
  # mod = 1000000007 # prime

  # (950 choose 100) mod 1000000007
  print(fermat_binom_advanced(n, r, MOD))  # should be 640644226

Submission status: Wrong Answer

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

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 )

Z=X+Y
if Z%3 == 0:
    D=int(Z/3)
    print(cmb(D,min(abs(D-X),abs(D-Y)),MOD))
else:
    print(0)

Submission status: Wrong Answer

Solution code:
MAX = 1000000
MOD = 1000000007

fac = [0] * MAX
finv = [0] * MAX
inv = [0] * MAX

def COMinit():
    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

def cmb(n,k):
    if n < k:
        return 0
    if n < 0 or k < 0:
        return 0
    return int(fac[n] * (finv[k] * finv[n - k] % MOD) % MOD)

x,y = input().split()
x = int(x)
y = int(y)
COMinit()
flag = True
if (2 * y - x) % 3 != 0 or (2*y-x) %3 != 0:
    out = 0
    flag = False
a = (2 * y - x) // 3
b = (2 * x - y) // 3 
if flag:
     print(cmb(a+b,b))
else:
     print(0)

Submission status: Wrong Answer

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

if (X+Y)%3==0 and Y<=2*X and Y>=X/2:
    temp=(X+Y)//3
    temp2=X-Y
    x=(temp+temp2)//2
    y=(temp-temp2)//2
    
    m=10**9+7
    ans=1
    for i in range(x+y):
        ans=ans*(i+1)%m
    for i in range(x):
        ans=ans*mod_inv(i+1,m)%m
    for i in range(y):
        ans=ans*mod_inv(i+1,m)%m
    print(ans%m)
    
else:
    print("No")

Submission status: Wrong Answer

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

for i in range(min(X, Y)):
    for j in range(min(X, Y)):
        if i * 1 + j * 2 == X and i * 2 + j * 1 == Y:
            answer += 1
        elif i * 2 + j == X and i + j * 2 == Y:
            answer += 1

print(answer)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
import collections
import copy
import heapq
from collections import defaultdict
from heapq import heappop, heappush
import itertools
input = sys.stdin.readline

##### リストの 二分木検索 #####
# bisect_left(lists, 3)
# bisect_right(lists, 3)

##### プライオリティキュー #####
# heapq.heapify(a) #リストaのheap化
# heapq.heappush(a,x) #heap化されたリストaに要素xを追加
# heapq.heappop(a) #heap化されたリストaから最小値を削除＆その最小値を出力

# heapq.heappush(a, -x) #最大値を取り出す時は、pushする時にマイナスにして入れよう
# heapq.heappop(a) * (-1) #取り出す時は、-1を掛けて取り出すこと

##### タプルリストのソート #####
# sorted(ans) #(a, b) -> 1st : aの昇順, 2nd : bの昇順
# sorted(SP, key=lambda x:(x[0],-x[1])) #(a, b) -> 1st : aの昇順, 2nd : bの降順
# sorted(SP, key=lambda x:(-x[0],x[1])) #(a, b) -> 1st : aの降順, 2nd : bの昇順
# sorted(SP, key=lambda x:(-x[0],-x[1])) #(a, b) -> 1st : aの降順, 2nd : bの降順

# sorted(SP, key=lambda x:(x[1])) #(a, b) -> 1st : bの昇順
# sorted(SP, key=lambda x:(-x[1])) #(a, b) -> 1st : bの降順

def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))

def main():
	X,Y = inputMap()

	#画面外
	if Y < X:
		tmp = X / 2
		if tmp > Y:
			print(0)
			sys.exit()

	if X < Y:
		tmp = Y / 2
		if tmp > X:
			print(0)
			sys.exit()

	#画面端
	if X < Y:
		if Y % 2 == 0 and Y / 2 == X:
			print(1)
			sys.exit()
	elif Y > X:
		if X % 2 == 0 and X / 2 == Y:
			print(1)
			sys.exit()

	#中心
	if X == Y:
		if X % 3 == 0:
			tmp = int(X / 3)
			print(2**tmp)
			sys.exit()
		else:
			print(0)
			sys.exit()

	print(0)


if __name__ == "__main__":
	main()

Submission status: Wrong Answer

Solution code:
d = 10**9 + 7

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

def numerator(n,  k, p):
    l = 1;
    for j in range(k+1,n+1):
        l = (l*j)%p;
    return l

def denominator(n, k, p):
    l = 1;
    for j in range(2,n-k+1):
        l = (l*j)%p;
    return l


def power(a, k, p):
    if (k == 0):
        return 1
    r = power((a*a)%p,k>>0x01,p);
    if ((k&0x01) == 0x01): #odd number
        r = (r*a)%p;
    return r


def n_choose_K(n, k, p):
    num = numerator(n,k,p)
    den = denominator(n,k,p)
    return (num*power(den,p-2,p))%p
    

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

if n-int(n) != 0 or m-int(m) != 0:
    print(0)
else:
    n = int(n)
    m = int(m)
    ans = n_choose_K(n+m,n,d)
    print(int(ans))

Submission status: Wrong Answer

Solution code:
def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

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

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

    return result

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

if (x + y) % 3 != 0:
    print(0)
else:
    xn = int((x + y) / 6 + (x - y) / 2)
    yn = int((x + y) / 6 + (y - x) / 2)
    # n = math.factorial(xn + yn) / math.factorial(xn) / math.factorial(yn)
    n = cmb((xn + yn), xn)
    s = pow(int(n), 1, 1000000007)
    print(s)
    #print(int(n % (10e9 + 7)))

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())
N = X + Y
C21 = 0
C12 = 0

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

  print('C12=', C12, 'C21=', C21) 
  print(combinations_count(C21 + C12, C21))

Submission status: Wrong Answer

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

import sys
sys.setrecursionlimit(1000000)

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

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

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

MOD = 10**9+7

if (-Y + 2*X) % 3 == 0 and (2*Y - X) %3 == 0:
    x = (-Y + 2*X) // 3
    y = (2*Y - X) // 3
    
    result = comb(x+y,x,MOD)
    print(result)
    
else:
    print(0)

Submission status: Wrong Answer

Solution code:
import itertools
x, y = map(int, input().split())
mod = 10 ** 9 + 7
if (x == 1 and y == 2) or (x == 2 and y == 1):
    print(1)
    quit()
if (x % 3 == 0 and y % 3 != 0) or (x % 3 != 0 and y % 3 == 0):
    print(0)
    quit()
a_x = x // 3
a_y = y // 3
j = sorted(set(itertools.permutations([1]*a_x + [2]*a_y)))
print(len(j) % mod)

Submission status: Wrong Answer

Solution code:
import numpy as np
v=np.array(list(map(int, input().split())) )
mod = 10**9 +7
import math
def cmb(n, r,mod):
    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 = (result*int(numerator[k]))%mod

    return result
  
A = np.array([[2,1],[1,2]])
inv_A = np.linalg.inv(A)

k = np.dot(inv_A,v)
if abs(round(k[0]+ k[1])-(k[0]+k[1]))<10**(-10) and k[0]* k[1] >0:
  print(cmb(int(k[0]+k[1]),int(k[0]),mod))
else:
  print(0)

Submission status: Wrong Answer

Solution code:
import math
from operator import mul
from functools import reduce

def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

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

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

    return result

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

print(cmb(x_+y_,x_)%(10**9+7))

Submission status: Wrong Answer

Solution code:
MOD = 1000000007

def modinv(a, m):
    b, u, v = m, 1, 0
    while b != 0:
        t = 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

a, b = 12345678900000, 100000
a %= MOD
#print(a * modinv(b, MOD) % MOD)

def solve(x, y):
    if (x + y) % 3 != 0:
        return 0
    m = (x + y) // 3
    n = m 
    k = x - m
    return C2(n, k)

def C2(n, k):
    d = 1
    for i in range(n-k+1, n+1):
        d *= i 
        d %= MOD
    r = 1
    for i in range(1, k+1):
        r *= i 
        r %= MOD
    return (d * modinv(r, MOD)) % MOD



def test(x, y):
    print((x,y), solve(x,y))
    assert solve(x,y) == solve(y,x)

if 0==1:
    test(0, 0)

    test(1, 2)
    test(2, 1)

    test(2, 4)
    test(3, 3)
    test(4, 2)

    test(3, 6)
    test(4, 5)
    test(5, 4)
    test(6, 3)

    test(4, 8)
    test(5, 7)
    test(6, 6)
    test(7, 5)
    test(8, 4)
else:
    x, y = map(int, input().split())
    if x > y:
        x, y = y, x
    answer = solve(x, y) % MOD
#print(dp)
    print(answer)

Submission status: Wrong Answer

Solution code:
x, y = [int(_) for _ in input().split(' ')]

M = int(1e9+7)

def modpow(a, n):
    if n == 0:
        return 1
    elif n == 1:
        return a
    elif n == 2:
        return (a * a) % M
    elif n % 3 == 0:
        tmp = modpow(a, n // 3)
        return (tmp * tmp * tmp) % M
    elif n % 3 == 1:
        tmp = modpow(a, n // 3)
        return (tmp * tmp * tmp * a) % M
    else:
        tmp = modpow(a, n // 3)
        return (tmp * tmp * tmp * a * a) % M

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

f = [1] * 1000000
for i in range(1, 1000000):
    f[i] = (f[i - 1] * i % M)

if (x + y) % 3 == 0:
    a, b = (-x + 2 * y) // 3, (2 * x - y) // 3
    answer = (f[a + b] * modinv(f[a]) * modinv(f[b])) % M
    print(answer)
else:
    print(0)

Submission status: Wrong Answer

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

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 (2*y-x)%3!=0 or (2*x-y)%3!=0:
    print('0')
else:
    a=round((2*y-x)/3)
    b=round((2*x-y)/3)
    n=a+1
    r=b
    ans=comb(n+r-1,r,mod)
    print(int(ans%mod))

Submission status: Wrong Answer

Solution code:
import math

def main():

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

    if (2*Y-X) % 3 != 0 or (2*X-Y)% 3 != 0:
        return 0
    if (2*Y-X) < 0 or (2*X-Y) < 0: return 0

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

    mod = pow(10, 9) + 7
    p1 = 1
    for i in range(1, n+m+1):
        p1 *= i
        p1 %= mod

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

    p3 = 1
    for i in range(1, m+1):
        p3 *= i
        p3 %= mod

    p2 = powfast(p2, mod-2, mod)
    p3 = powfast(p3, mod-2, mod)
    return ((p1 * p2) % mod) * p3 % mod


def powfast(x, y, mod):
    if y == 0: return 1
    if x == 0: return 0
    if y % 2 == 0:
        return pow(powfast(x, y//2, mod), 2) % mod
    else:
        return (x * pow(powfast(x, y//2, mod), 2)) % mod


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

Submission status: Wrong Answer

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

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

flag = True
ans = 0

def mod_Combination(n, k, mod):
    def ext_gcd(a, b):
        if b == 0:
            return a, 1, 0
        else:
            d,x,y = ext_gcd(b,a%b)
            x-=(a//b)*y 
        return d,y,x
    p,q=1,1
    for i in range(n-k+1, n+1):
        p=(p*i)%mod
    for i in range(2, k+1):
        q=(q*i)%mod
    return int(p*(ext_gcd(q, mod)[1]%mod)%mod)
    
if a%1!=0 or b%1!=0:
    pass
else:
    ans = mod_Combination(int(a + b), int(a), 10**9 + 7)

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import itertools
from math import sqrt
input = sys.stdin.readline
mod = 10 ** 9 + 7

X, Y = map(int, input().split())
a_3 = -X + 2 * Y
b_3 = 2 * X - Y
if a_3 % 3 != 0 or b_3 % 3 != 0:
    print(0)
    exit()

a = a_3 // 3
b = b_3 // 3

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

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

comb = Combination(1000000)
print(comb(a+b, b))

Submission status: Wrong Answer

Solution code:
x, y = [int(x) for x in input().split()]

def c(n, r):
    u = 1
    l = 1
    for i in range(min(r, n - r)):
        u *= n - i
        l *= i + 1
    return u // l

def solve(x, y):
    if (x + y) % 3 != 0:
        return 0
    if x * 2 < y or y * x < x:
        return 0
    
    n = (x + y) // 3
    r = ((x - y) + n) // 2
    return c(n, r)

print(solve(x, y) % 1000000007)

Submission status: Wrong Answer

Solution code:
x,y=map(int,input().split())
if (x+y)%3!=0:
  print(0)
else:
  z=(x+y)//3
  if x<z:
    print(0)
  else:
    def modinv(a, mod=10**9+7):
      return pow(a, mod-2, mod)
    def comb(n, r, mod=10**9+7):
      r = min(r, n-r)
      res = 1
      if n==r:
        return 1
      for i in range(r):
        res = res * (n - i) * modinv(i+1, mod) % mod
      return res 
    print(comb(z,x-z)%(10**9+7))