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:

def s0():return input()
def s1():return input().split()
def s2(n):return [input() for x in range(n)]
def s3(n):return [input().split() for _ in range(n)]
def s4(n):return [[x for x in s] for s in s2(n)]
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]
def t3(n):return [tuple(int(x) for x in input().split()) for _ in range(n)]
def p0(b,yes="Yes",no="No"): print(yes if b else no)
# from sys import setrecursionlimit
# setrecursionlimit(1000000)
from collections import Counter,deque,defaultdict
# import itertools
# import math
# import networkx as nx
# from bisect import bisect_left,bisect_right
# from heapq import heapify,heappush,heappop
x,y=n1()
# memory error
# s=[[0]*(x+1)+[-1,-1] for _ in range(y+1)]
# s.append([-1]*(x+3))
# s.append([-1]*(x+3))
# s[0][0]=1

# d=deque([(0,0)])
# while len(d)>0:
#     a,b=d.popleft()
#     if s[a+1][b+2]>=0:
#         if s[a+1][b+2]==0:
#             d.append((a+1,b+2))
#         s[a+1][b+2]+=s[a][b]
#     if s[a+2][b+1]>=0:
#         if s[a+2][b+1]==0:
#             d.append((a+2,b+1))
#         s[a+2][b+1]+=s[a][b]
# s[x][y]
def comb(n,k):
    nCk = 1
    MOD = 10**9+7

    for i in range(n-k+1, n+1):
        nCk *= i
        nCk %= MOD

    for i in range(1,k+1):
        nCk *= pow(i,MOD-2,MOD)
        nCk %= MOD
    return nCk

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

Submission status: Wrong Answer

Solution code:
import sys

input = lambda: sys.stdin.readline().rstrip()


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


def solve():
    X, Y = map(int, input().split())
    sm = min(X, Y)
    mod = 10**9 + 7
    m = [0] * (sm + 1)
    n = [-1] * (sm + 1)
    m[0] = 1
    n[0] = pow(m[0], mod - 2, mod)

    for i in range(1, sm + 1):
        m[i] = m[i - 1] * i % mod

    ans = 0
    for i in range(sm + 1):
        if (sm - i) % 2 == 0:
            b = (sm - i) // 2
            if b + i * 2 == Y:
                if n[i] == -1:
                    n[i] = pow(m[i], mod - 2, mod)
                if n[b] == -1:
                    n[b] = pow(m[b], mod - 2, mod)
                ans = (ans + m[i + b] * n[i] * n[b]) % mod
                #print(i, b, m[i + b], n[i], n[b])

    print(ans)


if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

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

fac=[1,1]
inv_t=[0,1]
finv=[1,1]
for i in range(2,MAX):
    fac.append(fac[-1]*i%mod)
    inv_t += [inv_t[mod % i] * (mod - mod // i) % mod]
    finv.append(finv[i-1]*inv_t[i]%mod)

x=2*X-Y
y=2*Y-X
over=1
under=1
i=x+y
if x%3!=0 or y%3!=0:
    print(0)
else:
    x=x//3
    y=y//3
    n=x+y
    r=min(x,y)
    print((fac[n]*finv[r]*finv[n-r])%mod)

Submission status: Wrong Answer

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

fac=[1,1]
inv_t=[0,1]
finv=[1,1]
for i in range(2,MAX):
    fac.append(fac[-1]*i%mod)
    inv_t += [inv_t[mod % i] * (mod - mod // i) % mod]
    finv.append(finv[i-1]*inv_t[i]%mod)

x=2*X-Y
y=2*Y-X
over=1
under=1
i=x+y
if x%3!=0 or y%3!=0:
    print(0)
else:
    x=x//3
    y=y//3
    n=x+y
    r=min(x,y)
    print((fac[n]*finv[r]*finv[n-r])%mod)

Submission status: Wrong Answer

Solution code:
def nCr(n_, r_, m_):
  c = min(r_ , n_ - r_)
  bunshi = 1
  bunbo = 1
  for i in range(1,c+1):
    bunshi = bunshi * (n_+1-i) % m_
    bunbo = bunbo * i % m_
  return bunshi * pow(bunbo, m_-2, m_) % m_


x,y = map(int,input().split())
s = max(x,y)
t = min(x,y)
u = 2*t-s
if u%3 != 0:
  print(0)
else:
  a = u//3
  b = a + s - t
  ans = nCr(a+b,b,10**9+7)
  print(ans)

Submission status: Wrong Answer

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

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

tmp=(x+y)//3
x=x-tmp
y=y-tmp
sosu=10**9+7

def combination(x,y):
    n=x+y
    r=min(x,y)
    upper=1
    lower=1
    for i in range(r):
        upper=(upper*(n-i))%sosu
        lower=(lower*(i+1))%sosu
    return (upper * pow(lower,sosu-2,sosu))%sosu
print(combination(x,y))

Submission status: Wrong Answer

Solution code:
MOD = 10 ** 9 + 7

def Z(): return int(input())
def ZZ(): return [int(_) for _ in input().split()]

def main():
    X, Y = ZZ()
    if (X + Y)%3 != 0:
        print(0)
        return

    N = 1400000
    fact = [0] * (N + 1) # fact[n] = n!
    ifact = [0] * (N + 1)

    for i in range(N+1):
        if i == 0:
            fact[i] = 1
            continue
        fact[i] = i * fact[i-1]
        fact[i] %= MOD
    ifact[N] = pow(fact[N], MOD-2, MOD)
    for i in range(N)[::-1]:
        ifact[i] = ((i+1) * ifact[i+1])%MOD

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

    output = fact[m+n] * ifact[m] * ifact[n] % MOD
    print(output)

    return

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

def combination(n, r, mod=10**9+7):
    if r == 0:
        return 1
    elif r < 0:
        return 0
    r = min(r, n-r)
    res = 1
    for i in range(r):
        res = res * (n - i) * pow(i+1, mod-2, mod) % mod
    return res
 

if (m + n) % 3 != 0:
    print(0)
else:
    p = (m + n) // 3
    k = m - p
    print(combination(p,k))

Submission status: Wrong Answer

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

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

if (m + n) % 3 != 0:
    print(0)
else:
    p = (m + n) // 3
    k = m - p
    print(combination(p,k))

Submission status: Wrong Answer

Solution code:
import math
#from scipy.special import comb

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

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


ans = 0
md = 10**9+7
if((x+y)%3 != 0 or (2*y-x)%3 != 0 or (2*x-y)%3 != 0):
    print(0)
else:
    a = (2*x - y)//3
    n = (x+y)//3
    ans = comb(n,a,md)
    print(ans)

Submission status: Wrong Answer

Solution code:
import math
#from scipy.special import comb

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

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


ans = 0
md = 10**9+7
if((x+y)%3 != 0 or (2*y-x)%3 != 0 or (2*x-y)%3 != 0):
    print(0)
else:
    a = (2*x - y)//3
    n = (x+y)//3
    ans = comb(n,a,md)
    print(ans)

Submission status: Wrong Answer

Solution code:
import math
#from scipy.special import comb

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

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


ans = 0
md = 10**9+7
if((x+y)%3 != 0):
    print(0)
else:
    a = (2*x - y)//3
    n = (x+y)//3
    ans = comb(n,a,md)
    print(ans)

Submission status: Wrong Answer

Solution code:
MOD=10**9+7

def cmb(n, r):
    if n < r: return 0 #date added
    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])
            result = result%MOD

    return result

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

print(a, b)

if a.is_integer() and b.is_integer() and a>=0 and b>=0:
    print(cmb(int(a+b), int(a)))
else:
    print(0)

Submission status: Wrong Answer

Solution code:
MOD=10**9+7

def cmb(n, r):
    if n < r: return 0 #date added
    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])
            result = result%MOD

    return result

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

#print(a, b)

if a.is_integer() and b.is_integer() and a>0 and b>0:
    print(cmb(int(a+b), int(a)))
else:
    print(0)

Submission status: Wrong Answer

Solution code:
MOD=10**9+7

def cmb(n, r):
    if n < r: return 0 #date added
    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])
            result = result%MOD

    return result

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

#print(a, b)

if a.is_integer() and b.is_integer():
    print(cmb(int(a+b), int(a)))
else:
    print(0)

Submission status: Wrong Answer

Solution code:
def egcd(a, b):
    if a == 0:
        return b, 0, 1
    else:
        g, y, x = egcd(b % a, a)
        return g, x - (b // a) * y, y

# mを法とするaの乗法的逆元
def modinv(a, m):
    g, x, y = egcd(a, m)
    if g != 1:
        raise Exception('modular inverse does not exist')
    else:
        return x % m

# nCr mod m
# modinvが必要
# rがn/2に近いと非常に重くなる
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

x,y = map(int, input().split())
b = (2*y - x) / 3
a = (2*x - y) / 3
if not b.is_integer() or not a.is_integer():
    print(0)
else:
    print(combination(int(a+b), int(a)))

Submission status: Wrong Answer

Solution code:
import math
def inv(a,mod=10**9+7):
    return(pow(a,mod-2,mod))

x,y = map(int,input().split())
mod = 10**9+7
reuslt = 0
if (x+y) %3 == 0:

    n = (2*x-y)//3
    m = (2*y-x)//3
    r = min(n,m)
    result = 1
    for i in range(r):
        result = result*(n+m-i)*inv(i+1,mod)%mod
    
else :
    result = 0

print(result)

Submission status: Wrong Answer

Solution code:
import math
x,y = map(int,input().split())
mod = 10**9+7
reuslt = 0
if (x+y) %3 == 0:

    n = (2*x-y)//3
    m = (2*y-x)//3
    result = 1
    for i in range(n+m,n-1,-1):
        result = result*i
    
    result = result%mod
else :
    result = 0

print(result)

Submission status: Wrong Answer

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

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

if (x+y)%3!=0:
    print(0)
else:
    n=(x+y)//3
    m=(-x+2*y)//3
    if n<0 or m<0:
        print(0)
        exit()
    else:
        print(mod_combinations_count(n,m,mod)%mod)

Submission status: Wrong Answer

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

def modinv(a, mod=10**9+7):
    return pow(a, mod-2, mod)
# rがn/2に近いと非常に重くなる
def mod_combinations_cont(n, r, mod):
    r = min(r, n-r)
    res = 1
    for i in range(r):
        res = res * (n - i) * modinv(i+1, mod) % mod
    return res

if (x+y)%3!=0:
    print(0)
else:
    n=int((x+y)/3)
    m=int((-x+2*y)/3)
    if n<0 or m<0:
        print(0)
        exit()
    else:
        print(mod_combinations_cont(n,m,mod))

Submission status: Wrong Answer

Solution code:
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  # N は必要分だけ用意する
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)


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

x = X % 3
y = Y % 3

ans = 1

if x == 0 and y == 0:
  a = X // 3
  b = Y // 3
  
  print(cmb(a+b, a, p))

elif x == 1 and y == 2:
  a = (X-1) // 3
  b = (Y+1) // 3
        
  print(cmb(a+b, a, p))
        
elif x == 2 and y == 1:
  a = (X+1) // 3
  b = (Y-1) // 3
        
  print(cmb(a+b, a, p))
else:
  print(0)

Submission status: Wrong Answer

Solution code:
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  # N は必要分だけ用意する
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)


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

x = X % 3
y = Y % 3

ans = 1

if x == 0 and y == 0:
  a = X // 3
  b = Y // 3
  
  print(cmb(a+b, a, p))

elif x == 1 and y == 2:
  a = (X+2) // 3
  b = (Y-2) // 3
        
  print(cmb(a+b, a, p))
        
elif x == 2 and y == 1:
  a = (X+1) // 3
  b = (Y-1) // 3
        
  print(cmb(a+b, a, p))
else:
  print(0)

Submission status: Wrong Answer

Solution code:
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  # N は必要分だけ用意する
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)


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

x = X % 3
y = Y % 3

ans = 1

if x == 0 and y == 0:
  a = X // 3
  b = Y // 3
  
  print(cmb(a+b, a, p))

elif x == 1 and y == 2:
  a = (X+2) // 3
  b = (Y+1) // 3
        
  print(cmb(a+b, a, p))
        
elif x == 2 and y == 1:
  a = (X+1) // 3
  b = (Y+2) // 3
        
  print(cmb(a+b, a, p))
else:
  print(0)

Submission status: Wrong Answer

Solution code:
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  # N は必要分だけ用意する
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)


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

x = X % 3
y = Y % 3

ans = 1

if x == 0 and y == 0:
  a = X // 3
  b = Y // 3
  
  print(cmb(a+b, a, p))

elif x == 1 and y == 2:
  a = (X-1) // 3
  b = (Y-2) // 3
        
  print(cmb(a+b, a, p))
        
elif x == 2 and y == 1:
  a = (X-2) // 3
  b = (Y-1) // 3
        
  print(cmb(a+b, a, p))
else:
  print(0)

Submission status: Wrong Answer

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

x = X % 3
y = Y % 3
mod = 10**9 + 7

if x == 0 and y == 0:
  a = X // 3
  b = Y // 3
  print(int( (2**a) * (2**b) % mod ))
elif x == 1 and y == 2:
  a = (X-1) // 3
  b = (Y-2) // 3
  print(int( (2**a) * (2**b) % mod ))
elif x == 2 and y == 1:
  a = (X-2) // 3
  b = (Y-1) // 3
  print(int( (2**a) * (2**b) % mod ))
else:
  print(0)

Submission status: Wrong Answer

Solution code:
#ABC145D
def main():
    import sys, math
    X, Y = map(int, sys.stdin.readline().split())
    '''
    i +2*j ==X
    2*i +j ==Y
    '''
    if (2*Y-X)%3==0:
        i = (2*Y-X)//3
        j = Y-2*i
    else:
        i, j =0,0
    #print(i, j)
    mod = 10**9+7
    def calc(n):
        ans = 1
        for i in range(n, 1, -1):
            ans *= i
            ans %= mod
        return ans
    
    ans = calc(i+j)
    
    #print(ans)
    
    #calc2(calc(i), mod-2)
    gg1 = pow(calc(i), mod-2, mod)
    gg2 = pow(calc(j), mod-2, mod)
    if i<=0 and j<=0:
        ans =0
    print(ans*gg1*gg2%mod)

if __name__=='__main__':
    main()

Submission status: Wrong Answer

Solution code:
#ABC145D
def main():
    import sys, math
    X, Y = map(int, sys.stdin.readline().split())
    '''
    i +2*j ==X
    2*i +j ==Y
    '''
    if (2*Y-X)%3==0:
        i = (2*Y-X)//3
        j = Y-2*i
    else:
        i, j =0,0
    #print(i, j)
    mod = 10**9+7
    def calc(n):
        ans = 1
        for i in range(n, 1, -1):
            ans *= i
            ans %= mod
        return ans
    
    ans = calc(i+j)
    
    #print(ans)
    
    #calc2(calc(i), mod-2)
    gg1 = pow(calc(i), mod-2, mod)
    gg2 = pow(calc(j), mod-2, mod)
    if i==0 and j==0:
        ans =0
    print(ans*gg1*gg2%mod)

if __name__=='__main__':
    main()

Submission status: Wrong Answer

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

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

if (X / Y == 2) and (X % Y == 0):
    print(1)
    exit()
elif (Y / X == 2) and (Y % X == 0):
    print(1)
    exit()
    
    
import math

if X == Y:
    n = X // 3
    c = math.factorial(2 * n) // (math.factorial(2 * n - n) * math.factorial(n))
    print(c % (10**9+7))

sub = X - Y if X > Y else Y - X

n = X - 2 * sub if X > Y else Y - 2 * sub
n //= 3

try:
    c = math.factorial(2 * n + sub) // (math.factorial(2 * n + sub - n) * math.factorial(n))
except:
    print(0)
    exit()

print(c % (10**9+7))

Submission status: Wrong Answer

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

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

n = 0
m = 0
MOD = 10**9 + 7
if (x+y)%3 != 0:
    print(0)
    exit()
elif x < 3 or y < 3:
    n = min(x,y)
    m = 0
else:
    m = x - int(x/3) - int(y/3)
    n = int((x+y)/3) - m
ans = combination(n+m,n)
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()

def resolve():
    
    def main():
        X,Y=map(int,input().split())
        n=(-X+2*Y)/3
        m=(2*X-Y)/3

        # https://atcoder.jp/contests/abc156/submissions/11621672
        def modpow(a, b, mod=10 ** 9 + 7):
            ret = 1
            while b > 0:
                if b % 2 == 1:
                    ret = ret * a % mod
                a = a * a % mod
                b //= 2
            return ret
        
        
        def modcomb(n, c, mod=10 ** 9 + 7):
            if c > n - c:
                c = n - c
            u, d = 1, 1
            for i in range(c):
                u = u * (n - i) % mod
                d = d * (i + 1) % mod
            return u * modpow(d, mod - 2) % mod
        
        
        """mod = 10 ** 9 + 7
        n, a, b = map(int, input().split())
        ans = (modpow(2, n) - 1) % mod
        ans = (ans-modcomb(n, a)) % mod
        ans = (ans-modcomb(n, b)) % mod
        print(ans)"""
        
        # combどうしの積をとると余りがずれるので避ける！　普通のcombを計算して最後にmodをとって。
        
        # comb(n + k - 1, n) # 重複組み合わせkHn．k種類の箱にn個の玉        
        if (not n.is_integer() or not m.is_integer()):
            return 0
        else:
            return modcomb(int(n+m),int(n))
    print(main())
    
resolve()

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()

def resolve():
    
    def main():
        X,Y=map(int,input().split())
        n=(-X+2*Y)/3
        m=(2*X-Y)/3

        # https://atcoder.jp/contests/abc156/submissions/11621672
        def modpow(a, b, mod=10 ** 9 + 7):
            ret = 1
            while b > 0:
                if b % 2 == 1:
                    ret = ret * a % mod
                a = a * a % mod
                b //= 2
            return ret
        
        
        def modcomb(n, c, mod=10 ** 9 + 7):
            if c > n - c:
                c = n - c
            u, d = 1, 1
            for i in range(c):
                u = u * (n - i) % mod
                d = d * (i + 1) % mod
            return u * modpow(d, mod - 2) % mod
        
        
        """mod = 10 ** 9 + 7
        n, a, b = map(int, input().split())
        ans = (modpow(2, n) - 1) % mod
        ans = (ans-modcomb(n, a)) % mod
        ans = (ans-modcomb(n, b)) % mod
        print(ans)"""
        
        # combどうしの積をとると余りがずれるので避ける！　普通のcombを計算して最後にmodをとって。
        
        # comb(n + k - 1, n) # 重複組み合わせkHn．k種類の箱にn個の玉        
        if not n.is_integer() or not m.is_integer():
            return 0
        else:
            return modcomb(int(n+m),int(n))
    print(main())
    
resolve()

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()

def resolve():
    
    def main():
        X,Y=map(int,input().split())
        n=(-X+2*Y)/3
        m=(2*X-Y)/3
        def framod(n, mod = 10 ** 9 + 7, a=1):
            for i in range(1, n + 1):
                a = a * i % mod
            return a
        
        def power(n, r, mod = 10 ** 9 + 7):
            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 = 10 ** 9 + 7):
            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
        
        # combどうしの積をとると余りがずれるので避ける！　普通のcombを計算して最後にmodをとって。
        
        # comb(n + k - 1, n) # 重複組み合わせkHn．k種類の箱にn個の玉
        if not n.is_integer() or not m.is_integer():
            return 0
        else:
            return comb(int(n+m),int(n))
    print(main())
    
resolve()

Submission status: Wrong Answer

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

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

m = 2 * x - y
n = 2 * y - x
if m > 0 and n > 0 and m % 3 == 0 and n % 3 == 0:
    print(com((n + m) // 3, n // 3, mod))
else:print(0)

Submission status: Wrong Answer

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

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

m = 2 * x - y
n = 2 * y - x
if m > 0 and n > 0 and m % 3 == 0 and n % 3 == 0:
    print(com((n + m) // 3, n // 3, mod))

Submission status: Wrong Answer

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

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

#2 * left + up * 4 = 2 * x
#left * 2 + up = y

up = (2 * x - y) // 3
left = (2 * y - x) // 3

#互いに素な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

#(up + left)C(up)
mod = 10**9 + 7
res = 1
for i in range(1, left + up + 1):
    res = res * i % mod
for i in range(1, up + 1):
    res = res * mod_inv(i, mod) % mod
for i in range(1, left + 1):
    res = res * mod_inv(i, mod) % mod
print(res % mod)

Submission status: Wrong Answer

Solution code:
import sys
from collections import deque

sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


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


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 comb_with_repetition(self, n, r):
        # 重複組み合わせ
        return self.__call__(n + r - 1, r)


def main():
    X, Y = map(int, input().split())
    if (X + Y) % 3 != 0:
        print(-1)
        return
    else:
        if Y > 2 * X:
            print(-1)
            return
        if 2 * Y < X:
            print(-1)
            return

        comb = Combination(n_max=10 ** 6 + 1)
        n = (X + Y) // 3
        r = X - n
        ans = comb(n, r)

        print(ans)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

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


if x%3==0 and y%3==0:
	s= math.factorial(a+b)
	d=math.factorial(a)*math.factorial(b)
	print(s//d)

else:
	print(0)

Submission status: Wrong Answer

Solution code:
X,Y=map(int,input().split())
def power(a,n):
    x=1
    L=list(format(n,'b'))
    l=len(L)
    for i in range(l):
        if int(L[l-i-1])==1:        
            x=(x*a)%(10**9+7)
        a=(a*a)%(10**9+7)
    return x
if X==0 and Y==0:
    print(0)
else:
    if (2*X-Y)%3==0 and (2*Y-X)%3==0:
        x=int((2*X-Y)/3)
        y=int((2*Y-X)/3)
        z=1
        c=1
        for i in range(x):
            z=(z*(x+y-i))%(10**9+7)
            c=(c*(i+1))%(10**9+7)
        z=z%(10**9+7)
        c=c%(10**9+7)
        c=power(c,10**9+5)
        print((z*c)%(10**9+7))
        
        

    else:
        print(0)

Submission status: Wrong Answer

Solution code:
X,Y=map(int,input().split())
def power(a,n):
    x=1
    L=list(format(n,'b'))
    l=len(L)
    for i in range(l):
        if int(L[l-i-1])==1:        
            x=(x*a)%(10**9+7)
        a=(a*a)%(10**9+7)
    return x
if X==0 and Y==0:
    print(0)
else:
    if (2*X-Y)%3==0 and (2*Y-X)%3==0:
        x=int((2*X-Y)/3)
        y=int((2*Y-X)/3)
        z=1
        c=1
        for i in range(x):
            z=(z*(x+y-i))%(10**9+7)
            c=(c*(i+1))%(10**9+7)
        c=power(c,10**9+5)
        print((z*c)%(10**9+7))
        
        

    else:
        print(0)

Submission status: Wrong Answer

Solution code:
X,Y=map(int,input().split())
def power(a,n):
    x=1
    L=list(format(n,'b'))
    l=len(L)
    for i in range(l):
        if int(L[l-i-1])==1:        
            x=(x*a)%(10**9+7)
        a=(a*a)%(10**9+7)
    return x
if (2*X-Y)%3==0 and (2*Y-X)%3==0:
    x=int((2*X-Y)/3)
    y=int((2*Y-X)/3)
    z=1
    c=1
    for i in range(x):
        z=(z*(x+y-i))%(10**9+7)
        c=(c*(i+1))%(10**9+7)
    c=power(c,10**9+5)
    print((z*c)%(10**9+7))
    
    

else:
    print(0)

Submission status: Wrong Answer

Solution code:
X, Y = map(int, input().split())
mod = 10**9+7
b = (2*Y-X)//3
a = Y - 2*b
print(a, b)
max_num = a + b + 5
facts = [1 for i in range(max_num)]
invs = [1 for i in range(max_num)]
 
def inv(x):
    return pow(x,mod-2,mod)
 
for i in range(1,max_num):
    facts[i] = facts[i-1]*i%mod
    invs[i] = inv(facts[i])
 
def nCk(n,k):
    try:
        return facts[n]*invs[k] * invs[n-k] % mod
    except IndexError:
        print(n, k, len(facts), len(invs))
if (X+Y)%3 == 0 and a>=0 and b >=0:
    print(nCk(a+b, a))
else:
    print(0)

Submission status: Wrong Answer

Solution code:

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

def div(a, b):
    return a*power(b, mod-2)%mod

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

if (x+y)%3!=0:
    print(0)
else:
    w1=(2*y-x)//3
    h1=(2*x-y)//3

    mod=10**9+7

    ic=1
    ih=1
    for i in range(h1):
        ic=ic*(w1+1+i)%mod
        ih=ih*(i+1)%mod

    ic=div(ic,ih)

    print(ic)

Submission status: Wrong Answer

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

mod = 10**9+7

def choose(n,r):
    p,q = 1,1
    for i in range(r):
        p = p*(n-i)%mod
        q = q*(i+1)%mod
    return p * pow(q,mod-2,mod) % mod # modの世界では逆元はpow(x,mod-2)をかけることと同じ

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

if n > 0 and m > 0 and int(n)*10 == n*10 and int(m)*10 == m*10:
    ans = choose(int(m+n), int(m))
else:
    ans = 0
print(ans)

Submission status: Wrong Answer

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

mod = 10**9+7

def choose(n,r):
    p,q = 1,1
    for i in range(r):
        p = p*(n-i)%mod
        q = q*(i+1)%mod
    return p * pow(q,mod-2,mod) % mod # modの世界では逆元はpow(x,mod-2)をかけることと同じ

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

if int(n)*10 == n*10 and int(m)*10 == m*10:
    ans = choose(int(m+n), int(m))
else:
    ans = 0
print(ans)