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: Runtime Error

Solution code:
MOD = 10**9+7
x, y = map(int, input().split())
if (x+y)%3 != 0 or 3*x < x+y or 3*y < x+y:
    print(0)
    exit()
n = (x+y)//3
x -= n
y -= n
fact = [0, 1]
for i in range(2,n+1):
    fact.append(fact[i-1] * i)
factX = fact[x]
factY = fact[y]
factN = fact[n]

inv_t = [0, 1]
for i in range(2,n+1):
    inv_t.append(inv_t[MOD % i] * (MOD - int(MOD / i)) % MOD)

c = factN * inv_t[factX] * inv_t[factY]
c %= MOD
print(c)

Submission status: Runtime Error

Solution code:
import math
MOD = 10**9+7
x, y = map(int, input().split())
if (x+y)%3 != 0 or 3*x < x+y or 3*y < x+y:
    print(0)
    exit()
n = (x+y)//3
x -= n
y -= n
factN = 1
for i in range(1,n+1):
    factN *= i
    if i == x: factX = factN
    if i == y: factY = factN
c = factN // factX // factY
print(c%MOD)

Submission status: Runtime Error

Solution code:
def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

def cinit(N):
    g1,g2,inverse = [0]*N,[0]*N,[0]*N
    mod = 10**9+7 #出力の制限
    g1[0],g1[1],g2[0],g2[1],inverse[0],inverse[1] = 1,1,1,1,0,1 # 元テーブル
    for i in range( 2, N + 1 ):
        g1[i] = ( ( g1[-1] * i ) % mod )
        inverse[i]=( ( -inverse[mod % i] * (mod//i) ) % mod )
        g2[i]=( (g2[-1] * inverse[-1]) % mod )

X,Y = map(int, input().split())
if (X+Y)%3==0and(X<Y*2 or Y<X*2):
    cinit((X+Y)//3)
    p = (min(X,Y)*2 - max(X,Y))//3
    print(cmb((X+Y)//3,p,mod))
else:
    print(0)

Submission status: Runtime Error

Solution code:
def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

def cinit(N):
    g1,g2,g3 = [0]*N,[0]*N,[0]*N
    mod = 10**9+7 #出力の制限
    g1[0],g1[1],g2[0],g2[1],inverse[0],inverse[1] = 1,1,1,1,0,1 # 元テーブル
    for i in range( 2, N + 1 ):
        g1[i] = ( ( g1[-1] * i ) % mod )
        inverse[i]=( ( -inverse[mod % i] * (mod//i) ) % mod )
        g2[i]=( (g2[-1] * inverse[-1]) % mod )

X,Y = map(int, input().split())
if (X+Y)%3==0and(X<Y*2 or Y<X*2):
    cinit((X+Y)//3)
    p = (min(X,Y)*2 - max(X,Y))//3
    print(cmb((X+Y)//3,p,mod))
else:
    print(0)

Submission status: Runtime Error

Solution code:
X, Y = int(input().split(" "))
count = 0
for i in range(X):
    for j in range(Y):
        if i * 1 + j * 2 == X and i * 2 + j * 1 == Y:
            count = count + i + j - 1
print(count)

Submission status: Runtime Error

Solution code:
X, Y = int(input())
count = 0
for i in range(X):
    for j in range(Y):
        if i * 1 + j * 2 == X and i * 2 + j * 1 == Y:
            count = count + i + j - 1
print(count)

Submission status: Runtime Error

Solution code:
import math

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

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

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

if (2*x-y)%3 != 0:
  print("0")
  exit()
  
m = (2*x-y)//3

if (x-2*m) < 0:
  print("0")
  exit()

n = x-2*m

print(combinations_count(m+n, n)%(10**9+7) )

Submission status: Runtime Error

Solution code:
import math

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

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

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

if (2*x-y)%3 != 0:
  print("0")
  exit()
  
m = (2*x-y)//3

if (x-2*m) < 0:
  print("0")
  exit()

n = x-2*m

print(combinations_count(m+n, n))

Submission status: Runtime Error

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

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

n=((x+y)//3) + 1
k=y-(n-2)

m=max(n,k)
fac=[0 for _ in range(m)]   #n!
finv=[0 for _ in range(m)]  #1/n!
inv=[0 for _ in range(m)]   #

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

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

print( fac[n-1] * (finv[k-1] * finv[n - k] % MOD) % MOD )

Submission status: Runtime Error

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

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

n=((x+y)//3) + 1
k=y-(n-2)

fac=[0 for _ in range(n)]   #n!
finv=[0 for _ in range(n)]  #1/n!
inv=[0 for _ in range(n)]   #

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

m=max(n,k)

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

print( fac[n-1] * (finv[k-1] * finv[n - k] % MOD) % MOD )

Submission status: Runtime Error

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

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

n=((x+y)//3) + 1
k=y-(n-2)

fac=[0 for _ in range(n)]   #n!
finv=[0 for _ in range(n)]  #1/n!
inv=[0 for _ in range(n)]   #

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

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

print( fac[n-1] * (finv[k-1] * finv[n - k] % MOD) % MOD )

Submission status: Runtime Error

Solution code:
import numpy as np


MOD = 10**9 + 7

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

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

    if (Y < X/2) or (Y > 2*X):
        print(0)
	else:
      
        h = (2 * X - Y) // 3
        v = (2 * Y - X) // 3

        def extgcd(a, b):
            if b == 0:
                x = 1
                y = 0
            else:
                y, x = extgcd(b, a%b)
                y -= a//b * x
            return x, y

        def low_inverse(a):
            ret, _ = extgcd(a, MOD)
            return ret

        def low_combination(m, n):
            # calculate (m+n)!/n!m!
            ret = 1
            numerator = m + n
            for i in range(min(m, n)):
                inv_i = low_inverse(i + 1)
                ret = ret * (numerator - i) * inv_i % MOD
            return ret

        print(low_combination(h, v))

Submission status: Runtime Error

Solution code:
import math
MOD = 10**9+7
x, y = map(int, input().split())
if (x+y)%3 != 0 or 3*x < x+y or 3*y < x+y:
    print(0)
    exit()
n = (x+y)//3
x -= n
y -= n
c = math.factorial(x) // (math.factorial(x - y) * math.factorial(y))
print(c%MOD)

Submission status: Runtime Error

Solution code:
import math
MOD = 10**9+7
x, y = map(int, input().split())
if (x+y)%3 != 0 or 3*x < x+y or 3*y < x+y:
    print(0)
    exit()
n = (x+y)//3
x -= n
y -= n
c = math.factorial(x) // (math.factorial(x - y) * math.factorial(y))
print(c//MOD)

Submission status: Runtime Error

Solution code:
import math
MOD = 10**9+7
x, y = map(int, input().split())
if (x+y)%3 != 0 or 3*x < x+y or 3*y < x+y:
    print(0)
    exit()
n = (x+y)//3
x -= n
y -= n
c = math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
print(c//MOD)

Submission status: Runtime Error

Solution code:
def main(X,Y):
    if (X+Y)%3 != 0:
        print(0)
    else:
        n = (2*X-Y)/3
        m = (2*Y-X)/3
        if n < 0 or m < 0:
            print(0)
        elif n == 0 or m == 0:
            print(1)
        else:
            top = 1
            bot = 1
            n = int(n)
            m = int(m)
            for i in range(n):
                top *= (n + m) - i
                bot *= n - i
            w = (10**9)+7)
            result = (top/bot) % w
            result = int(result)
            print(result)

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

Submission status: Runtime Error

Solution code:
X,Y  = map(int,input().split())
if (X+Y)%3 != 0:
    print(0)
else:
    n = (2*X-Y)/3
    m = (2*Y-X)/3
    if n < 0 or m < 0:
        print(0)
    elif n = 0 or m = 0:
        print(1)
    else:
        top = 1
        bot = 1
        n = int(n)
        m = int(m)
        for i in range(n):
            top *= (n + m) - i
            bot *= n - i

        result = (top/bot) % ((10**9)+7)
        result = int(result)
        print(result)

Submission status: Runtime Error

Solution code:
X,Y  = map(int,input().split())
if (X+Y)%3 != 0:
    print(0)
else:
    n = (2*X-Y)/3
    m = (2*Y-X)/3
    if n < 0 or m < 0:
        print(0)
    if n = 0 or m = 0:
        print(1)
    top = 1
    bot = 1
    n = int(n)
    m = int(m)
    for i in range(n):
        top *= (n + m) - i
        bot *= n - i

    result = (top/bot) % ((10**9)+7)
    result = int(result)
    print(result)

Submission status: Runtime Error

Solution code:
import math
X,Y = map(int, input().split())
maxY = X * 2
if (maxY - Y)%3==0:
    num2 = (maxY - Y)//3
    num1 = X - num2 * 2
    print((math.factorial(num2+num1) // math.factorial(num1) * math.factorial(num2))%(10**9+7))
else:
    print(0)

Submission status: Runtime Error

Solution code:
X,Y  = map(int,input().split())
if (X+Y)%3 != 0:
    print(0)
else:
    n = (2*X-Y)/3
    m = (2*Y-X)/3
    top = 1
    bot = 1
    n = int(n)
    m = int(m)
    for i in range(n):
        result *= ((n + m) - i)/(n-i)

    result = result % ((10**9)+7)
    result = int(result)
    print(result)

Submission status: Runtime Error

Solution code:
X,Y  = map(int,input().split())
if (X+Y)%3 != 0:
    print(0)
else:
    n = (2*X-Y)/3
    m = (2*Y-X)/3
    top = 1
    bot = 1
    n = int(n)
    m = int(m)
    for i in range(n):
        top *= (n + m) - i
        bot *= n - i

result = (top/bot) % ((10**9)+7)
result = int(result)
print(result)

Submission status: Runtime Error

Solution code:
X,Y  = input().split()
X = int(X)
Y = int(Y)
if (X+Y)%3 != 0:
    print(0)
else:
    n = (2*X-Y)/3
    m = (2*Y-X)/3
    top = 1
    bot = 1
    n = int(n)
    m = int(m)
    for i in range(n):
        top *= (n + m) - i
        bot *= n - i

result = (top/bot) % ((10**9)+7)
result = int(result)
print(result)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
import math
from scipy.special import comb
from operator import mul
from functools import reduce

def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under

X,Y = (int(x) for x in input().split())
count = 0
if (X+Y)%3!=0 or 2*X<Y or 2*Y<X:
    print("0")
    exit()
else:
    N=(X+Y)/3 # 合計移動回数
    mov_x=(2*X-Y)/3 #(2,1)の移動回数 ]

    #print(combinations_count(N, mov_x)%(pow(10,9)+7))
    #print(comb(N, mov_x, exact=True)%(pow(10,9)+7))
    print(cmb(int(N), int(mov_x))%(pow(10,9)+7))

Submission status: Runtime Error

Solution code:
X = int(input())
Y = int(input())

if (X+Y)%3 != 0:
    print(0)
else:
    n = (2X-Y)/3
    m = (2Y-X)/3
    top = 1
    bot = 1
    for i in range(n):
        top *= (n + m) - i
        bot *= n - i

result = (top/bot) % ((10**9)+7)

print(result)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
import math
from scipy.special import comb
#from operator import mul
#from functools import reduce

def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under

X,Y = (int(x) for x in input().split())
count = 0
if (X+Y)%3!=0 or 2*X<Y or 2*Y<X:
    print("0")
    exit()
else:
    N=(X+Y)/3 # 合計移動回数
    mov_x=(2*X-Y)/3 #(2,1)の移動回数 ]

    #print(combinations_count(N, mov_x)%(pow(10,9)+7))
    #print(comb(N, mov_x, exact=True)%(pow(10,9)+7))
    print(cmb(int(N), int(mov_x))%(pow(10,9)+7))

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
import math
#from scipy.special import comb
#from operator import mul
#from functools import reduce

def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under

X,Y = (int(x) for x in input().split())
count = 0
if (X+Y)%3!=0 or 2*X<Y or 2*Y<X:
    print("0")
    exit()
else:
    N=(X+Y)/3 # 合計移動回数
    mov_x=(2*X-Y)/3 #(2,1)の移動回数 ]

    #print(combinations_count(N, mov_x)%(pow(10,9)+7))
    #print(comb(N, mov_x, exact=True)%(pow(10,9)+7))
    print(cmb(int(N), int(mov_x))%(pow(10,9)+7))

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
import math
from scipy.special import comb
from operator import mul
from functools import reduce

def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under

X,Y = (int(x) for x in input().split())
count = 0
if (X+Y)%3!=0 or 2*X<Y or 2*Y<X:
    print("0")
    exit()
else:
    N=(X+Y)/3 # 合計移動回数
    mov_x=(2*X-Y)/3 #(2,1)の移動回数 ]

    if (left<right):
        left=mov_y+1
        right=mov_x
    #print(combinations_count(N, mov_x)%(pow(10,9)+7))
    #print(comb(N, mov_x, exact=True)%(pow(10,9)+7))
    print(cmb(int(N), int(mov_x))%(pow(10,9)+7))

Submission status: Runtime Error

Solution code:
# from scipy.special import comb

from math import factorial

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

if (x + y) % 3 != 0:
    print(0)
else:
    # (+1, +2) n
    # (+2, +1) m
    # n + 2m = x
    # 2n + m = y
    m = (2 * x - y) // 3
    n = (2 * y - x) // 3
    score = factorial(n + m) // factorial(n) // factorial(m)
    # score = comb(n + m, n, exact=True)
    print(score % MOD)

Submission status: Runtime Error

Solution code:
board = [[999 for j in range(8)]for i in range(8)]
board2 = [[0 for j in range(8)]for i in range(8)]

def move(x, y, hops):
    if 0<=x<8 and 0<=y<8 and hops < board[x][y]:
        board[x][y] = hops
        board[x][y] = 1
        move(x - 1, y + 2, hops + 1)
        move(x - 1, y - 2, hops + 1)
        move(x + 1, y + 2, hops + 1)
        move(x + 1, y - 2, hops + 1)
        move(x - 2, y + 1, hops + 1)
        move(x - 2, y - 1, hops + 1)
        move(x + 2, y + 1, hops + 1)
        move(x + 2, y - 1, hops + 1)
    elif board[x][y] == board:
      	board2[x][y] += 1


startx, starty = 0, 0
endx, endy = input().split(' ')
endx, endy = int(endx), int(endy)
move(startx-1, starty-1, 0)
print(board2[endx-1][endy-1])

Submission status: Runtime Error

Solution code:
x,y = map(int,input().split())
diff = abs(x-y)
mod = 10**9 + 7
if (x+y) % 3 != 0:
    print("0")
    exit()
else:
    cir = (min(x,y) - diff) // 3
    if cir < 0:
        print("0")
        exit()
    all_step = (x+y) // 3
    print(combination(all_step, cir, mod))

Submission status: Runtime Error

Solution code:
def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod
#出力の制限
#フェルマーの小定理なので、素数のみ使用
mod = 10**9+7 #出力の制限
N = 10**6
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

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

x , y = map(int,input().split())
MOD = 10 ** 9 + 7
for s in range(max(x,y)):
    if 2 * x - 3 * s == y:
        flag = True
        break
t = x - 2 * s
if flag:
    print(cmb((t+s),s,mod))
else:
    print(0)

Submission status: Runtime Error

Solution code:
import math
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 = (-x+2*y)//3
print(math.factorial(a+b)//(math.factorial(a)*math.factorial(b))%(10**9+7))

Submission status: Runtime Error

Solution code:
from operator import mul
from functools import reduce

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

def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under



if (x+y) % 3 == 0 and (2*x-y) % 3 == 0 and (2*y-x) % 3 == 0:
    n=(x+y)//3
    r=(2*y-x)//3
    #b = math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
    
    b=cmb(n,r)
    print(b % W)
else:
    print("0")

Submission status: Runtime Error

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

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


def comb(n, r):
    return (math.factorial(n) // (math.factorial(n - r) * math.factorial(r))) % (10**9+7)



if (X+Y)%3 != 0:
    print(0)
else:
    if n<0 or m<0:
        print(0)
    else:
        print(comb(n+m,n))

Submission status: Runtime Error

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

if (x+y) % 3 == 0 and (2*x-y) % 3 == 0 and (2*y-x) % 3 == 0:
    n=(x+y)//3
    r=(2*y-x)//3
    b = math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
    print(b % W)
else:
    print("0")

Submission status: Runtime Error

Solution code:
import math


def main():
    X,Y=input().split()
    x=int(X)
    y=int(Y)
    print(dp_knight(x,y)%(10**9+7))

def dp_knight(x,y):
    dp=[[0]*(x+3) for i in range(y+3)]
    dp[2][2]=1
    for i in range(x+1):
        for j in range(y+1):
            dp[i+2][j+2]+=dp[i+1][j]+dp[i][j+1]

    return dp[x+2][y+2]


if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
def ext_gcd(p, a):
  #require a, m be relative prime
  #m > a  
  if a == 0:
    return 1, 0
  else:
    x1, y1 = ext_gcd(a, p%a)
    y = x1 - y1 * int(p/a)
    x = y1
    return x, y

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

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

if n != int(n) or m != int(m) or n<0 or m<0:
  ans = 0
else:
   n = int(n)
   m = int(m)
   if n < m :
      m = c
      m = n
      n = c
   # (n+m!)/(n!)(m!) mod (1e9+7)
   ans = 1
   prime = 1000000007 
   for i in range(n+1,m+n+1):
        ans = int(ans * i) 
        ans = (ans % prime)
   for i in range(1, m+1):
      ori_inv = int(ext_gcd(prime, i)[1])
      while ori_inv < 0 :
        ori_inv += prime
      ans = int(ans * ori_inv)  
      ans = (ans % prime)
print(ans)

Submission status: Runtime Error

Solution code:
def ext_gcd(m, a):
  #require a, m be relative prime
  #m > a  
  if m < a:
    assert ('error')
  elif a == 0:
    return 1, 0
  else:
    x1, y1 = ext_gcd(a, m%a)
    y = x1 - y1 * int(m/a)
    x = y1
    return x, y

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

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

if n != int(n) or m != int(m) or n<0 or m<0:
  ans = 0
else:
   n = int(n)
   m = int(m)
   if n < m :
      m = c
      m = n
      n = c
   # (n+m!)/(n!)(m!) mod (1e9+7)
   ans = 1
   prime = 1000000007 
   for i in range(n+1,m+n+1):
        ans = int(ans * i) 
        ans = (ans % prime)
   for i in range(1, m+1):
      ori_inv = int(ext_gcd(prime, i)[1])
      while ori_inv < 0 :
        ori_inv += prime
      ans = int(ans * ori_inv)  
      ans = (ans % prime)
print(ans)

Submission status: Runtime Error

Solution code:
def ext_gcd(m, a):
  #require a, m be relative prime
  #m > a  
  if m < a:
    assert ('error')
  elif a == 0:
    return 1, 0
  else:
    x1, y1 = ext_gcd(a, m%a)
    y = x1 - y1 * int(m/a)
    x = y1
    return x, y

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

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

if n != int(n) or m != int(m) or n<0 or m<0:
  ans = 0
else:
   n = int(n)
   m = int(m)
   if n < m :
      m = c
      m = n
      n = c
   # (n+m!)/(n!)(m!) mod (1e9+7)
   ans = 1
   prime = 1000000007 
   for i in range(n+1,m+n+1):
        ans = int(ans * i) 
        ans = (ans % prime)
   for i in range(1, m+1):
      ori_inv = int(ext_gcd(prime, i)[1])
      while ori_inv < 0 :
        ori_inv += prime
      assert int(ori_inv * i) % prime == 1
      ans = int(ans * ori_inv)  
      ans = (ans % prime)
print(ans)

Submission status: Runtime Error

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

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

if (X+Y)%3 != 0:
      print(0)
      exit()
 
x,y=X,Y
for i in range(0,x+1):
    if x==y*2 or (x==0 and y==0):
        n=i
        break
    else:
      x-=1
      y-=2

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

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

ans = nCr(n+m,n,mod)
print(ans)

Submission status: Runtime Error

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

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

if (X+Y)%3 != 0:
      print(0)
      exit()
 
x,y=X,Y
for i in range(x):
    if x==y*2:
        n=i
        break
    else:
      x-=1
      y-=2

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

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

ans = nCr(n+m,n,mod)
print(ans)

Submission status: Runtime Error

Solution code:
X, Y = map(int, input().split())
go = [1, 2]

def dfs(x, y):
  if x > X or y > Y:
    return 0
  ret = 1 if x == X and y == Y else 0
  for i in range(0, 2):
    ret += dfs(x + go[i], y + go[i-1])
  return ret

ans = dfs(0, 0) % (10**9 + 7)

print(ans)

Submission status: Runtime Error

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

def cmb(nn, rr, mod):
    if ( rr<0 or rr>nn ):
        return 0
    rr = min(rr, nn-rr)
    return g1[nn] * g2[rr] * g2[nn-rr] % mod

if (X+Y)%3 != 0:
      print(0)
      exit()
 
if min(X,Y)*2<max(X,Y):
    print(0)
    exit()

n,x,y=0,X,Y
while x != y*2:
      x-=1
      y-=2
      n+=1
m=((X+Y)//3)-n

mod = 10**9+7 #出力の制限
N = 10**4
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 )

ans = cmb(n+m,n,mod)
print(ans)

Submission status: Runtime Error

Solution code:
from math import factorial

X, Y = map(int, input().split())
mod = 10 ** 9 + 7
if (X + Y) % 3 != 0:
    print(0)
else:
    n = (2 * Y - X) // 3
    m = (2 * X - Y) // 3
    print((factorial(n+m)%mod * pow(factorial(n)*factorial(m), mod-2, mod))%mod)

Submission status: Runtime Error

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

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

n = (-X + 2 * Y) / 3
m = (2 * X - Y) / 3
if n < 0 or m < 0:
    print("0")
else:
    import math
    n, m = int(n), int(m)
    s = 0
    for i in range(2, m + n + 1):
        s += math.log(i)
    for i in range(2, m + 1):
        s -= math.log(i)
    for i in range(2, n + 1):
        s -= math.log(i)
    
    print(int(math.exp(s)) % (10**9 + 7))

Submission status: Runtime Error

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

if (x + y) % 3 == 0:
    n = (x + y) // 3
    o = 2 * n - x + 1
    a = 1
    aa = list()
    for i in range(o):
        a += i
        aa.append(int(a))
    if len(aa) % 2 == 0:
        aa += aa[0:len(aa) - 1:-1]
    else:
        aa += aa[0:len(aa) -2:-1]
    print(aa[o] % (10 ** 9 + 7))
else:
    print(0)

Submission status: Runtime Error

Solution code:
def cmb(n,r,mod=10**9+7):
    fac = [0] * (n+1)
    finv = [0] * (n+1)
    inv = [0]*(n+1)

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

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

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

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

i = (x+y)//3
j = x-i

print(cmd(i,j))

Submission status: Runtime Error

Solution code:
import math

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

if (x + y) % 3 != 0:
    print(0)
else:
    n = (x + y) / 3
    a = y - n
    b = x - n
    res = math.factorial(n) // (math.factorial(a) * math.factorial(b))
    print(res % (10 ** 9 + 7))

Submission status: Runtime Error

Solution code:
x,y = map(int, input().split())
 
if (x + y) % 3  != 0:
  print(0)
  exit()
  
k = x - (x+y)//3
m = y - (x+y)//3
 
if k < 0 or m < 0:
  print(0)
  exit()
  
def nCr(k,m):
  mod = 10**9 + 7
  k,m = max(k,m),min(k,m)
  l = s = 0
  for i in range(m,k - m + 1):
    l = l * (m + i) % mod
    s = s * (i + 1) % mod
    
print(l/s)

Submission status: Runtime Error

Solution code:
x,y = map(int, input().split())
 
if (x + y) % 3  == 0:
  print(0)
  exit()
  
k = x - (x+y)//3
m = y - (x+y)//3
 
if k < 0 or m < 0:
  print(0)
  exit()
  
def nCr(k,m):
  mod = 10**9 + 7
  k,m = max(k,m),min(k,m)
  l = s = 0
  for i in range(m,k - m + 1):
    l = l * (m + i) % mod
    s = s * (i + 1) % mod
    
print(l/s)

Submission status: Runtime Error

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

if (x + y) % 3  == 0:
  print(0)
  exit()
  
k = x - (x+y)//3
m = y - (x+y)//3

if k < 0 or m < 0:
  print(0)
  exit()
  
def nCr(k,m):
  mod = 10**9 + 7
  k,m = max(k,m),min(k,m)
  l = s = 0
  for i in range(m,k + 1):
    l = l * (m + i) % mod
    s = s * (i + 1) % mod
    
print(l/s)

Submission status: Runtime Error

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

mod = 10**9+7

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

if X>0 and Y>0 and (2*X - Y)%3 == 0 and (2*Y - X)% 3==0 and 2*Y >= X and Y <= 2*X: 
    m = int((2*X - Y)/ 3)
    n = int((2*Y - X)/ 3)
    
    g1 = [1, 1] # 元テーブル
    g2 = [1, 1] #逆元テーブル
    inverse = [0, 1] #逆元テーブル計算用テーブル
    for i in range( 2, m+n + 1 ):
        g1.append( ( g1[-1] * i ) % mod )
        inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
        g2.append( (g2[-1] * inverse[-1]) % mod )
    ret = cmb(m+n, m, mod)
else:
    print('0')
print(ret)

Submission status: Runtime Error

Solution code:
import numpy as np
import math

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

mod = 10**9+7
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル
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

if X>0 and Y>0 and (2*X - Y)%3 == 0 and (2*Y - X)% 3==0 and 2*Y >= X and Y <= 2*X: 
    m = int((2*X - Y)/ 3)
    n = int((2*Y - X)/ 3)
    
    for i in range( 2, m+n + 1 ):
        g1.append( ( g1[-1] * i ) % mod )
        inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
        g2.append( (g2[-1] * inverse[-1]) % mod )
    
    
    ret = cmb(m+n, m, mod)
print(ret)

Submission status: Runtime Error

Solution code:
import numpy as np
import math

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

mod = 10**9+7
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル
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

if X>0 and Y>0 and (2*X - Y)%3 == 0 and (2*Y - X)% 3==0: 
    m = int((2*X - Y)/ 3)
    n = int((2*Y - X)/ 3)
    
    for i in range( 2, m+n + 1 ):
        g1.append( ( g1[-1] * i ) % mod )
        inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
        g2.append( (g2[-1] * inverse[-1]) % mod )
    
    
    ret = cmb(m+n, m, mod)
print(ret)

Submission status: Runtime Error

Solution code:
import numpy as np

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

ret = 0
def back(X, Y):
    if X == 0 and Y == 0:
        global ret
        ret += 1
        return 0
    elif X>0 and Y > 0:
        back(X-1, Y-2)
        back(X-2, Y-1)
    else:
        return 0

back(X,Y)
print(ret%(10**9+7))

Submission status: Runtime Error

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

class ModComb:
    def __init__(self, MAX, mod=10 ** 9 + 7):
        fac = [1, 1]
        finv = [1, 1]
        inv = [0, 1]
        for i in range(2, MAX):
            fac.append(fac[i - 1] * i % mod)
            inv.append(mod - inv[mod % i] * (mod // i) % mod)
            finv.append(finv[i - 1] * inv[i] % mod)
        self.fac, self.finv, self.mod = fac, finv, mod
    
    def nCk(self, n, k):
        if n < k or n < 0 or k < 0:
            return 0
        fac, finv, mod = self.fac, self.finv, self.mod
        return fac[n] * (finv[k] * finv[n - k] % mod) % mod

if (X+Y)%3 != 0:
    print(O)
else:
    n = (2*X-Y)//3
    m = (2*Y-X)//3
    
    mod = 10 ** 9 + 7
    mc = ModComb(1000000, mod=mod) 

    print(mc.nCk(n+m, n) % mod)

Submission status: Runtime Error

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

class ModComb:
    def __init__(self, MAX, mod=10 ** 9 + 7):
        fac = [1, 1]
        finv = [1, 1]
        inv = [0, 1]
        for i in range(2, MAX):
            fac.append(fac[i - 1] * i % mod)
            inv.append(mod - inv[mod % i] * (mod // i) % mod)
            finv.append(finv[i - 1] * inv[i] % mod)
        self.fac, self.finv, self.mod = fac, finv, mod
    
    def nCk(self, n, k):
        if n < k or n < 0 or k < 0:
            return 0
        fac, finv, mod = self.fac, self.finv, self.mod
        return fac[n] * (finv[k] * finv[n - k] % mod) % mod
      
if (X+Y)%3 != 0:
    print(O)
else:
    n = (2*X-Y)//3
    m = (2*Y-X)//3
    
    mod = 10 ** 9 + 7
    mc = ModComb(1000000, mod=mod) 

    print(mc.nCk(n+m, n) % mod)

Submission status: Runtime Error

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

class ModComb:
    def __init__(self, MAX, mod=10 ** 9 + 7):
        fac = [1, 1]
        finv = [1, 1]
        inv = [0, 1]
        for i in range(2, MAX):
            fac.append(fac[i - 1] * i % mod)
            inv.append(mod - inv[mod % i] * (mod // i) % mod)
            finv.append(finv[i - 1] * inv[i] % mod)
        self.fac, self.finv, self.mod = fac, finv, mod
    
    def nCk(self, n, k):
        if n < k or n < 0 or k < 0:
            return 0
        fac, finv, mod = self.fac, self.finv, self.mod
        return fac[n] * (finv[k] * finv[n - k] % mod) % mod
      
if (X+Y)%3 != 0:
    print(O)
else:
    n = (-X+2*Y)//3
    m = (2*X-Y)//3
    
    mod = 10 ** 9 + 7
    mc = ModComb(1000000, mod=mod) 

    print(mc.nCk(n+m, n) % mod)

Submission status: Runtime Error

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

class ModComb:
    def __init__(self, MAX, mod=10 ** 9 + 7):
        fac = [1, 1]
        finv = [1, 1]
        inv = [0, 1]
        for i in range(2, MAX):
            fac.append(fac[i - 1] * i % mod)
            inv.append(mod - inv[mod % i] * (mod // i) % mod)
            finv.append(finv[i - 1] * inv[i] % mod)
        self.fac, self.finv, self.mod = fac, finv, mod
    
    def nCk(self, n, k):
        if n < k or n < 0 or k < 0:
            return 0
        fac, finv, mod = self.fac, self.finv, self.mod
        return fac[n] * (finv[k] * finv[n - k] % mod) % mod
      
if (X+Y)%3 != 0:
    print(O)
else:
    n = Y - (X+Y)//3
    m = X - (X+Y)//3
    
    mod = 10 ** 9 + 7
    mc = ModComb(1000000, mod=mod) 

    print(mc.nCk(n+m, n) % mod)

Submission status: Runtime Error

Solution code:
from operator import mul
from functools import reduce

def nCr(n,r):
    r=min(n-r,r)
    if r==0:
        return 1
    over=reduce(mul,range(n,n-r,-1))
    under=reduce(mul,range(1,r+1))
    return over//under
    
def main():
    X,Y=map(int,input().split())
    a=X+Y
    if a%3!=0:
        print("0")
        return

    else:
        cmb=nCr(a//3,X-a//3)
        print(cmb%(10**9+7))
        return
    
if __name__=='__main__':
    main()