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
import sys

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

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

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

x = X - ((X + Y) // 3)
y = Y - ((X + Y) // 3)

mod = 10 ** 9 + 7

numerater = 1
for i in range(1, x+y+1):
    numerater =  (numerater * i) % mod

denominator_x = 1
for i in range(1, x+1):
    denominator_x = (mod_inv(i, mod) * denominator_x) % mod

denominator_y = 1
for i in range(1, y+1):
    denominator_y = (mod_inv(i, mod) * denominator_y) % mod

res = (numerater * denominator_x * denominator_y) % mod

print(res)

Submission status: Wrong Answer

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

knight_move = [(1, 2), (2, 1)]
ans = 0
k = 0
flag = False
for i in range(1, 10**6):
    if y == -x + i*3:
        if y == 2*x:
            ans = 1
            break
        elif x == 2*y:
            ans = 1
            break
        else:
            k = i  # k手でいける
            break
else:
    flag = True

if flag:
    print(0)

move_21 = ((x - y + k) % mod)*pow(2, mod-2, mod)
move_12 = ((y - x + k) % mod)*pow(2, mod-2, mod)


def nck(n, k):
    numer, denom = 1, 1
    for i in range(k):
        numer = numer * (n - i) % mod
        denom = denom * (k - i) % mod
    return numer * pow(denom, mod-2, mod) % mod


ans = nck(k, min(move_12, move_21))
print(ans)

Submission status: Wrong Answer

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

x, y = map(int,input().split())
mod = 10 ** 9 + 7
n = (2 * y - x) // 3 if (2 * y - x) % 3 == 0 else 0
m = (2 * x - y) // 3 if (2 * x - y) % 3 == 0 else 0

if n * m != 0:
    print(com(n + m, n, mod))
else:
    print(0)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(2000000000)
nCr = {}
def cmb(n, r):
    if r == 0 or r == n: return 1
    if r == 1: return n
    if (n,r) in nCr: return nCr[(n,r)]
    nCr[(n,r)] = cmb(n-1,r) + cmb(n-1,r-1)
    return nCr[(n,r)]
X,Y = map(int,input().split())
if (X + Y) % 3 != 0:
    print(0)
else:
    n = int((X+Y)/3)
    p = max(X,Y)
    q = min(X,Y)
    if p > 2 * q:
        print(0)
    else:
        a = 2*n - p
        print(n,a)
        b = cmb(n,a) % (10**9 + 7)
        print(b)

Submission status: Wrong Answer

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

mod = 10**9+7

def com(n, r):
    p, q = 1, 1
    for i in range(r):
        p = p*(n-i)%mod
        q = q*(r-i)%mod
    return (p*pow(q, mod-2, mod))%mod

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

else:
    a = (2*Y-X)//3
    b = (X+Y)//3 - a
    if a > 0 and b > 0:
        print(com(a+b, a))
    else:
        print(0)

Submission status: Wrong Answer

Solution code:
x, y = map(int, input().split())
if (x + y) % 3 != 0:
    print(0)
else:
    n = (x+y) // 3
    nx = x - n
    ny = y - n
    mod = 10 **9 +7
    fac = [1] * 1000000
    for i in range(1,n+1):
        fac[i] = fac[i-1] * i % mod
    print(fac[n] * pow(fac[nx], mod-2, mod) * pow(fac[ny], mod-2, mod) % mod)

Submission status: Wrong Answer

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

mod = 10**9+7

def com(n, r):
    p, q = 1, 1
    for i in range(r):
        p = p*(n-i)%mod
        q = q*(r-i)%mod
    return (p*pow(q, mod-2, mod))%mod

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

else:
    ans = 0
    a = (2*Y-X)//3
    b = (2*X-Y)//3
    if a > 0 and b > 0:
        print(com(a+b, a)%mod)
    else:
        print(0)

Submission status: Wrong Answer

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

mod = 10**9+7

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

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

else:
    ans = 0
    a = (2*Y-X)//3
    b = (2*X-Y)//3
    if a > 0 and b > 0:
        print(com(a+b, a))
    else:
        print(0)

Submission status: Wrong Answer

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

mod = 10**9+7

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

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

else:
    ans = 0
    for i in range(1, 1+(X+Y)//3):
        if (X+Y)//3 - i > 0:
            ans += com((X+Y)//3, i)

    print(ans%mod)

Submission status: Wrong Answer

Solution code:
print(0)

Submission status: Wrong Answer

Solution code:
print(1)

Submission status: Wrong Answer

Solution code:
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
    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 or y>2*x or x>2*x: print(0)
else:
    a, b = (2*x-y)//3, (2*y-x)//3
    m = 10**9+7
    res = 1
    for i in range(1,a+b+1):
        res = res*i%m
    for i in range(1,a+1):
        res = res*mod_inv(i,m)%m
    for i in range(1,b+1):
        res = res*mod_inv(i,m)%m
    print(res%m)

Submission status: Wrong Answer

Solution code:
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
    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: print(0)
else:
    a, b = (2*x-y)//3, (2*y-x)//3
    m = 10**9+7
    res = 1
    for i in range(1,a+b+1):
        res = res*i%m
    for i in range(1,a+1):
        res = res*mod_inv(i,m)%m
    for i in range(1,b+1):
        res = res*mod_inv(i,m)%m
    print(res%m)

Submission status: Wrong Answer

Solution code:
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
    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: print(0)
else:
    a, b = (2*x-y)//3, (2*y-x)//3
    m = 10**9+7
    res = 1
    for i in range(1,a+b+1):
        res = res*i%m
    for i in range(1,a+1):
        res = res*mod_inv(i,m)%m
    for i in range(1,b+1):
        res = res*mod_inv(i,m)%m
    print(res)

Submission status: Wrong Answer

Solution code:
from sys import setrecursionlimit
setrecursionlimit(4100000)

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

mod = 1000000007
f = 0
df = abs(x-y)     #difference
tm = (x+y)//3   #time

if (x+y)%3 != 0:
    f = 1
elif tm < df:
    f = 1
else:
    pass

def mod_a_to_bth_power(a:int, b:int):
    if b%2 == 0:
        return (mod_a_to_bth_power(a, b//2)**2)%mod
    elif b == 1:
        return a%mod
    else:
        return ((mod_a_to_bth_power(a, b//2)**2)*a)%mod

def mod_inverse(a:int):
    return mod_a_to_bth_power(a, mod-2)

def mod_nCr(n:int, r:int):
    num, den = 1, 1 #numerator denominator
    for i in range(r):
        num = (num*(n-i))%mod
        den = (den*(i+1))%mod
    return (num*mod_inverse(den))%mod

if f == 1:
    print(0)
else:
    if df == 0:
        c = tm//2
    else:
        c = df
    ans = mod_nCr(tm, c)
    print(ans)

Submission status: Wrong Answer

Solution code:
import math

mod = 10**9+7

def comb(n, r):
	x = 1
	y = 1
	if n-r<r:
		r = n-r
	for i in range(r):
		x *= n-i
		y *= (i+1)
		x %= mod
		y %= mod
	return x * pow(y, mod-2, mod) % mod

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

o = -1

if X%2 == 0:
	if (Y-X//2)%3 != 0:
		o = 0
else:
	if (Y-(X-3)//2)%3 != 0:
		o = 0

if o == -1:
	n = (2*Y-X)//3
	m = Y-2*n
	if n >= 0 and m >= 0:
		o = comb(n+m, min(n,m))
		
print(o)

Submission status: Wrong Answer

Solution code:
import itertools
import math
import numpy as np
import fractions
from collections import deque
from itertools import combinations
from functools import reduce
from functools import lru_cache
import bisect
import sys
sys.setrecursionlimit(10**9)

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

    i = (2*X-Y)/3
    j = (2*Y-X)/3

    if not(i.is_integer() and j.is_integer()):
        print(0)
        exit()

    i = int(i)
    j = int(j)

    def comb(n, r, mod):
        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

    print(comb(i+j,i,p))


if __name__ == "__main__":
  main()

Submission status: Wrong Answer

Solution code:
X,Y=map(int,input().split())
if (X+Y)%3!=0:
  print(0)
  exit()
s=(2*X-Y)//3
t=(2*Y-X)//3
mod=(10**9)+7
up,d=1,1
for i in range(s+t,max(s,t),-1):#(s+t)!/s!t!がやりたい
  up=(up*i)%mod
for i in range(1,min(s,t)+1):
  d=(d*i)%mod
d=pow(d,mod-2,mod)
print((up*d)%mod)

Submission status: Wrong Answer

Solution code:
X,Y=map(int,input().split())
if (2*X-Y)%3!=0 or (2*Y-X)%3!=0:
  print(0)
  exit()
s=(2*X-Y)//3
t=(2*Y-X)//3
mod=(10**9)+7
up,d=1,1
for i in range(s+t,max(s,t),-1):#(s+t)!/s!t!がやりたい
  up=(up*i)%mod
for i in range(1,min(s,t)+1):
  d=(d*i)%mod
d=pow(d,mod-2,mod)
print((up*d)%mod)

Submission status: Wrong Answer

Solution code:
X,Y=map(int,input().split())
s=(2*X-Y)/3
t=(2*Y-X)/3
mod=(10**9)+7
if s!=int(s) or t!=int(t):
  print(0)
  exit()
s=int(s)
t=int(t)
up=1
d=1
for i in range(s+t,max(s,t),-1):#a!/b!c!(a=b+c)がやりたい
  up=(up*i)%mod
for i in range(1,min(s,t)+1):
  d=(d*i)%mod
d=pow(d,mod-2,mod)
print((up*d)%mod)

Submission status: Wrong Answer

Solution code:
X,Y=map(int,input().split())
s=(2*X-Y)/3
t=(2*Y-X)/3
mod=10**9+7
if s!=int(s) or t!=int(t):
  print(0)
  exit()
s=int(s)
t=int(t)
up=1
d=1
for i in range(s+t,max(s,t),-1):#a!/b!c!(a=b+c)がやりたい
  up=(up*i)%mod
for i in range(1,min(s,t)+1):
  d=(d*i)%mod
print(up//d)

Submission status: Wrong Answer

Solution code:
x, y = map(int, input().split())
mod = 10 ** 9 + 7
dif = abs(x - y)
num = min([x, y]) - dif
if num % 3 != 0:
    print(0)
    exit()
num = num / 3 * 2 + dif
ans = 1
for i in range(int(num)):
    ans = ans * (i + 1) % mod
print(ans % mod)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
mod = 10 ** 9 + 7
def cmb(n, r, mod):
    r = min(r, n-r)
    numer = denom = 1

    for i in range(r):
        numer = numer * (n-i) % mod
        denom = denom * (i+1) % mod
    return numer * pow(denom, mod-2, mod) % mod #逆元

x, y = map(int, input().split())
if (x + y) % 3 == 0 and (2 * y - x) % 3 == 0:
    print(cmb(int((x + y) / 3), int((2 * y - x) / 3), mod))
else:
    print(0)

Submission status: Wrong Answer

Solution code:
m = 10 ** 9 + 7
def cmb(x,y):
    r = 1
    for i in range(1, y + 1):
        r = (r * (x - i + 1) * pow(i, m-2, m)) % m
    return r

x, y = map(int, input().split())
if (x + y) % 3 == 0 and (2 * y - x) % 3 == 0:
    print(cmb(int((x + y) / 3), int((2 * y - x) / 3)))
else:
    print(0)

Submission status: Wrong Answer

Solution code:
m = 10 ** 9 + 7
def cmb(x,y):
    r=1
    for i in range(1,y+1):
        r=(r*(x-i+1)*pow(i,m-2,m))%m
    return r

x, y = map(int, input().split())
if (2 * x - y) % 3 == 0 and (2 * y - x) % 3 == 0:
    print(cmb(int((x + y) / 3), int((2 * y - x) / 3)))
else:
    print(0)

Submission status: Wrong Answer

Solution code:
m = 10 ** 9 + 7
def cmb(x,y):
    r=1
    for i in range(1,y+1):
        r=(r*(x-i+1)*pow(i,m-2,m))%m
    return r

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

Submission status: Wrong Answer

Solution code:
m=10**9+7
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 (2*Y-X) % 3 != 0 or (2*X-Y) % 3  != 0:
    print(0)
else:
    res = 1
    A = int((2*Y-X)/3)
    B = int((2*X-Y)/3)
    for i in range(1,A+B+1):
        res = res*i%m
    for i in range(1,A+1):
        res = res*mod_inv(i,m)%m
    for i in range(1,B+1):
        res = res*mod_inv(i,m)%m
    print(res)

Submission status: Wrong Answer

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

mod=10**9+7
n=10**6
f=[1,1]
g=[1,1]
h=[0,1]

for i in range(2,n+1):
  f.append(f[-1]*i%mod)
  h.append((-h[mod%i]*(mod//i))%mod)
  g.append(g[-1]*h[i]%mod)
  
def cmb(n,r):
  p=f[n]*g[r]*g[n-r]%mod
  return p

if x==y:
  if x%3==0:
    print(cmb((x+y)//3,x//3))
  else:
    print(0)
elif x>y:
  if (2*y-x)%3==0:
    print(cmb((x+y)//3,(2*y-x)//3))
  else:
    print(0)
else:
  if (2*x-y)%3==0:
    print(cmb((x+y)//3,(2*x-y)//3))
  else:
    print(0)

Submission status: Wrong Answer

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

plus = X+Y

if not plus%3==0:
    print(0)
else:
    row = plus//3+1
    col = Y-row+1
    l, r = 1, 1
    for c in range(col):
        l = (l*(row-1-c))%mod
        r = r*(c+1)%mod
    print((l*pow(r, mod-2, mod))%mod)

Submission status: Wrong Answer

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

small = min(X, Y)

plus = X+Y

if not plus%3==0:
    print(0)
else:
    row = plus//3+1
    col = Y-row+1
    l, r = 1, 1
    for c in range(col):
        l = (l*(row-1-c))%mod
        r = r*(c+1)%mod
    print((l*pow(r, mod-2, mod))%mod)

Submission status: Wrong Answer

Solution code:
def C(n, r, m):
    num, den = 1, 1
    for i in range(1, r + 1):
        num = num * (n - i + 1) % m
        den = den * i % m
    return (num * pow(den, m - 2, m)) % m

x, y = map(int, input().split())
m = (2*x - y) // 3
n = (-x + 2*y) // 3
if x + y % 3 != 0 or m < 0 or n < 0:
    print(0)
else:
    print(C(n + m, n, 10**9 + 7))

Submission status: Wrong Answer

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

if (2*x-y)%3!=0 or (2*x-y)<0:
  print(0)
  exit()
if (2*y-x)%3!=0 or (2*y-x)<0:
  print(0)
  exit()
p=int((2*x-y)/3)
q=int((2*y-x)/3)
M=2*(10**6)
Mod=10**9+7

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

def COMinit():
  fac[0]=fac[1]=1
  finv[0]=finv[1]=1
  inv[1]=1
  for i in range(2,M):
    fac[i]=(fac[i-1]*i%Mod)%Mod
    inv[i]=Mod-inv[Mod%i]*(Mod//i) %Mod
    finv[i]=(finv[i-1]*inv[i]%Mod)%Mod
print(inv[0])
def COM(n,k):
  if n<k:
    return 0
  if n<0 or k<0:
    return 0
  return (fac[n]*(finv[k]*finv[n-k]%Mod)%Mod)%Mod

COMinit()
print(COM(p+q,p))

Submission status: Wrong Answer

Solution code:
import math, sys
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque
from copy import deepcopy
from functools import lru_cache
from heapq import heapify, heappop, heappush
from itertools import accumulate, combinations, permutations
input = sys.stdin.readline
mod = 10**9 + 7
ns = lambda: input().strip()
ni = lambda: int(input().strip())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

def main():

    def fur(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

    x, y = nm()

    if (x + y) % 3 != 0:
        print(0)
        exit()
    
    n = (2*y - x) // 3 # (X, Y) -> (X+1, Y+2) 
    m = (2*x - y) // 3 # (X, Y) -> (X+2, Y+1) 

    print(fur(n+m, n))

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import math, sys
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque
from copy import deepcopy
from functools import lru_cache
from heapq import heapify, heappop, heappush
from itertools import accumulate, combinations, permutations
input = sys.stdin.readline
mod = 10**9 + 7
ns = lambda: input().strip()
ni = lambda: int(input().strip())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

def main():

    def fur(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

    x, y = nm()

    if (x + y) % 3 != 0:
        print(0)
    
    n = (2*y - x) // 3 # (X, Y) -> (X+1, Y+2) 
    m = (2*x - y) // 3 # (X, Y) -> (X+2, Y+1) 

    print(fur(n+m, n))

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
x,y=map(int,input().split())
if (2*x-y)%3!=0 or (x-2*y)%3!=0:
  print(0)
  exit()
a=(2*x-y)//3
b=(2*y-x)//3
mod=10**9+7
def comb(x,y):
    s=1
    t=1
    for i in range(1,y+1):
        s=s*(x-i+1)%mod
        t=t*(i)%mod
    return (s*pow(t,mod-2,mod))%mod
print(comb(a+b,min(a,b)))

Submission status: Wrong Answer

Solution code:
import math
import sys

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])
			result %= MOD

	return result

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

min_xy = min(x,y)
max_xy = max(x,y)

MOD = 10**9+7

if max_xy / min_xy == 2.0:
	print(1)
	sys.exit()
if max_xy / min_xy > 2.0:
	print(0)
	sys.exit()
if max_xy == min_xy and max_xy % 3 != 0:
	print(0)
	sys.exit()
if max_xy == min_xy and max_xy % 3 == 0:
	print(cmb(2 * max_xy//3, max_xy//3))
	sys.exit()

for i in range(min_xy//3):
	if (max_xy-3*i) / (min_xy-3*i) == 2.0:
		print(cmb(2*i,i))
		sys.exit()

print(0)

Submission status: Wrong Answer

Solution code:
mod = 10**9 + 7

fact_range = 10**6
facts = [1] * (fact_range + 1)
for i in range(0, fact_range):
	facts[i+1] = facts[i] * (i + 1) % mod

ifacts = [1] * (fact_range + 1)
ifacts[fact_range] = pow(facts[fact_range], mod - 2, mod)
for i in range(fact_range, 0, -1):
	ifacts[i-1] = ifacts[i] * i % mod

def comb(n, k):
	return facts[n] * ifacts[n-k] % mod * ifacts[k] % mod

x, y = map(int, input().split())
if (x + y) % 3:
    print(0)
else:
    n = (x + y) // 3
    k = x - n
    print(comb(n, k))

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
  
if (x+y)/3 != int((x+y)/3):
    print(0)
else:
    print(comb(int((x+y)/3), int(y-((x+y)/3)),10**9+7))

Submission status: Wrong Answer

Solution code:
X,Y=map(int,input().split())
if 2*Y<=X or 2*X<=Y or not((2*Y-X)%3==0) or not((2*X-Y)%3==0):
  print(0)
else:
  A=(2*Y-X)//3
  B=(2*X-Y)//3
  k=1
  for i in range(A+1,A+B+1):
    k=(k*i)%1000000007
  j=1
  for i in range(1,B+1):
    j=(j*i)%1000000007
  l=(pow(j,1000000005,1000000007)*k)%1000000007
  print(l)

Submission status: Wrong Answer

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

mod=10**9+7

def modinv(x):
    return pow(x,mod-2,mod)

def enumfactorial(x):
    ret=1
    for i in range(1,x+1):
        ret*=i
        ret%=mod
    
    return ret

def denomfactorial(x):
    ret=1
    for i in range(1,x+1):
        ret*=modinv(i)
        ret%=mod
    
    return ret

if (2*Y-X)%3>0 or (2*X-Y)%3>0:
    print(0)
else:
    m=(2*Y-X)//3
    n=(2*X-Y)//3

    print((enumfactorial(m+n)*denomfactorial(m)*denomfactorial(n))%mod)

Submission status: Wrong Answer

Solution code:
x,y=map(int,input().split())
def cal(number,mod):
    m=mod-2
    mod2=""
    while m!=0:
        if m%2==0:
            mod2="0"+mod2
        else:
            mod2="1"+mod2
        m=m//2
    two=[]
    for i in range(len(mod2)):
        if mod2[len(mod2)-1-i]=="1":
            two.append(i)
    ret=1
    for i in two:
        v=i
        retsub=number
        while v>0:
            retsub=retsub**2
            retsub=retsub%mod
            v-=1
        ret*=retsub
    ret=ret%mod
    return ret
ans=0
M=10**9+7
if (2*x-y)%3==0:
    n=(x+y)//3
    r=(2*x-y)//3
    if n<r or r<0:
        print(0)
        exit()
    l=[1]
    num=1
    for i in range(1,n+1):
        p=(num*i)%(M)
        l.append(p)
        num=p
    print(n,r)
    a=l[n]
    b=cal(l[n-r],M)
    c=cal(l[r],M)
    ans=(a*b*c)%M
print(ans)

Submission status: Wrong Answer

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

def comb(n, k, mod=10**9+7):
    ret = 1
    for i in range(1, k + 1):
        ret = ret * (n - i + 1) % mod
        ret = ret * pow(i, mod - 2, mod) % mod
    return ret

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

Submission status: Wrong Answer

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

MAX = 2 * 10 ** 6
MOD = 10 ** 9 + 7

fac = [0] * (MAX + 1)
fac[0] = 1
fac[1] = 1
for i in range(2, MAX + 1):
    fac[i] = fac[i - 1] * i % MOD
    
finv = [0] * (MAX + 1)
finv[MAX] = pow(fac[MAX], MOD - 2, MOD)
for i in reversed(range(1, MAX + 1)):
    finv[i - 1] = finv[i] * i % MOD

a = (2 * Y - X) / 3
b = (2 * X - Y) / 3
if a != int(a) or b != int(b):
    print(0)
else:
    a = int(a)
    b = int(b)
    print(fac[a + b] * finv[a] * finv[b] % MOD)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
import re
import math
import itertools
from copy import deepcopy
import random
from heapq import heappop,heappush
import time
import os
import queue
import sys
import datetime
from functools import lru_cache
readline=sys.stdin.readline
sys.setrecursionlimit(2000)
#import numpy as np
alphabet="abcdefghijklmnopqrstuvwxyz"
mod=int(10**9+7)
inf=int(10**20)
week=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"]
def yn(b):
    if b:
        print("yes")
    else:
        print("no")
def Yn(b):
    if b:
        print("Yes")
    else:
        print("No")
def YN(b):
    if b:
        print("YES")
    else:
        print("NO")
class union_find():
    def __init__(self,n):
        self.n=n
        self.P=[a for a in range(N)]
        self.rank=[0]*n
 
    def find(self,x):
        if(x!=self.P[x]):self.P[x]=self.find(self.P[x])
        return self.P[x]
 
    def same(self,x,y):
        return self.find(x)==self.find(y)
 
    def link(self,x,y):
        if self.rank[x]<self.rank[y]:
            self.P[x]=y
        elif self.rank[y]<self.rank[x]:
            self.P[y]=x
        else:
            self.P[x]=y
            self.rank[y]+=1
 
    def unite(self,x,y):
        self.link(self.find(x),self.find(y))
 
    def size(self):
        S=set()
        for a in range(self.n):
            S.add(self.find(a))
        return len(S)
def is_power(a,b):#aはbの累乗数か
    now=b
    while now<a:
        now*=b
    if now==a:return True
    else:return False
def bin_(num,size):
    A=[0]*size
    for a in range(size):
        if (num>>(size-a-1))&1==1:
            A[a]=1
        else:
            A[a]=0
    return A
def facs(n,mod_=0):
    A=[1]*(n+1)
    for a in range(2,len(A)):
        A[a]=A[a-1]*a
        if(mod_>0):A[a]%=mod_
    return A
def comb(n,r,mod_,fac):
    if(n-r<0):return 0
    return (fac[n]*pow(fac[n-r],mod_-2,mod_)*pow(fac[r],mod_-2,mod_))%mod_
def next_comb(num,size):
    x=num&(-num)
    y=num+x
    z=num&(~y)
    z//=x
    z=z>>1
    num=(y|z)
    if(num>=(1<<size)):return False
    else:
        return num
def get_primes(n,type="int"):
    A=[True]*(n+1)
    A[0]=False
    A[1]=False
    for a in range(2,n+1):
        if A[a]:
            for b in range(a*2,n+1,a):
                A[b]=False
    if(type=="bool"):return A
    B=[]
    for a in range(n+1):
        if(A[a]):B.append(a)
    return B
def is_prime(num):
    if(num<=2):return False
    i=2
    while i*i<=num:
       if(num%i==0):return False
       i+=1
    return True
def ifelse(a,b,c):
    if a:return b
    else:return  c
def join(A,c=" "):
    n=len(A)
    A=list(map(str,A))
    s=""
    for a in range(n):
        s+=A[a]
        if(a<n-1):s+=c
    return s
def factorize(n,type_="dict"):
    b = 2
    list_ = []
    while b * b <= n:
        while n % b == 0:
            n //= b
            list_.append(b)
        b+=1
    if n > 1:list_.append(n)
    if type_=="dict":
        dic={}
        for a in list_:
            if a in dic:
                dic[a]+=1
            else:
                dic[a]=1
        return dic
    elif type_=="list":
        return list_
    else:
        return None
def floor_(n,x=1):
    return x*(n//x)
def ceil_(n,x=1):
    return x*((n+x-1)//x)
#################################### ########
# coding: utf-8
import re
import math
import itertools
from copy import deepcopy
import random
from heapq import heappop,heappush
import time
import os
import queue
import sys
import datetime
from functools import lru_cache
readline=sys.stdin.readline
sys.setrecursionlimit(2000)
#import numpy as np
alphabet="abcdefghijklmnopqrstuvwxyz"
mod=int(10**9+7)
inf=int(10**20)
def yn(b):
    if b:
        print("yes")
    else:
        print("no")
def Yn(b):
    if b:
        print("Yes")
    else:
        print("No")
def YN(b):
    if b:
        print("YES")
    else:
        print("NO")
class union_find():
    def __init__(self,n):
        self.n=n
        self.P=[a for a in range(N)]
        self.rank=[0]*n
 
    def find(self,x):
        if(x!=self.P[x]):self.P[x]=self.find(self.P[x])
        return self.P[x]
 
    def same(self,x,y):
        return self.find(x)==self.find(y)
 
    def link(self,x,y):
        if self.rank[x]<self.rank[y]:
            self.P[x]=y
        elif self.rank[y]<self.rank[x]:
            self.P[y]=x
        else:
            self.P[x]=y
            self.rank[y]+=1
 
    def unite(self,x,y):
        self.link(self.find(x),self.find(y))
 
    def size(self):
        S=set()
        for a in range(self.n):
            S.add(self.find(a))
        return len(S)
def is_power(a,b):#aはbの累乗数か
    now=b
    while now<a:
        now*=b
    if now==a:return True
    else:return False
def bin_(num,size):
    A=[0]*size
    for a in range(size):
        if (num>>(size-a-1))&1==1:
            A[a]=1
        else:
            A[a]=0
    return A
def get_facs(n,mod_=0):
    A=[1]*(n+1)
    for a in range(2,len(A)):
        A[a]=A[a-1]*a
        if(mod>0):A[a]%=mod_
    return A
def comb(n,r,mod,fac):
    if(n-r<0):return 0
    return (fac[n]*pow(fac[n-r],mod-2,mod)*pow(fac[r],mod-2,mod))%mod
def next_comb(num,size):
    x=num&(-num)
    y=num+x
    z=num&(~y)
    z//=x
    z=z>>1
    num=(y|z)
    if(num>=(1<<size)):return False
    else:
        return num
def get_primes(n,type="int"):
    A=[True]*(n+1)
    A[0]=False
    A[1]=False
    for a in range(2,n+1):
        if A[a]:
            for b in range(a*2,n+1,a):
                A[b]=False
    if(type=="bool"):return A
    B=[]
    for a in range(n+1):
        if(A[a]):B.append(a)
    return B
def is_prime(num):
    if(num<=2):return False
    i=2
    while i*i<=num:
       if(num%i==0):return False
       i+=1
    return True
def ifelse(a,b,c):
    if a:return b
    else:return  c
def join(A,c=" "):
    n=len(A)
    A=list(map(str,A))
    s=""
    for a in range(n):
        s+=A[a]
        if(a<n-1):s+=c
    return s
def factorize(n,type_="dict"):
    b = 2
    list_ = []
    while b * b <= n:
        while n % b == 0:
            n //= b
            list_.append(b)
        b+=1
    if n > 1:list_.append(n)
    if type_=="dict":
        dic={}
        for a in list_:
            if a in dic:
                dic[a]+=1
            else:
                dic[a]=1
        return dic
    elif type_=="list":
        return list_
    else:
        return None
def floor_(n,x=1):
    return x*(n//x)
def ceil_(n,x=1):
    return x*((n+x-1)//x)
###################################################
def main():
    X,Y=map(int,input().split())
    if (X+Y)%3==0:
        n=(X+Y)//3
        X-=n
        Y-=n
        facs=get_facs(10**6+1,mod)
        if X<0 or Y<0:
            print(0)
            return
        ans=(facs[X+Y])*pow(facs[X]*facs[Y],mod-2,mod)
        print(ans)
    else:
        print(0)


main()