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:
#!/usr/bin/python3
# coding: utf-8

# 整数 > 整数型
def I(): return int(input())

# 整数列 '1 2 3 4' > 整数型リスト
def IsIl(): return list(map(lambda x: int(x), input().split()))

# 改行挟む整数列　'1/n 2/n 3/n' > 整数型りすと
def InIl(n): return [input() for i in range(n)]

# 整数列 '1 2' > 整数型タプル
def IsIt(): return map(lambda x: int(x), input().split())

# 改行挟む整数列　'1\n 2\n 3\n' > 整数型たぷる
def InIl(n): return map(input() for i in range(n))

# 文字列 'abcd' > 文字型リスト
def SsSl(): return list(map(lambda x: x, input()))

# 整数 '1234' > 整数型リスト

# 文字列 'aba' > 辞書（文字型:個数）{'a':2,'b':1}
def SSd():
    from collections import defaultdict
    A = input() # [int(i) for i in input().split()]
    dd=defaultdict(int)
    for a in A:
        dd[a]+=1
    return dd

n = 4
m = 3

memo = {}
def ncr(n,r):
    try:
        return memo[(n,r)]
    except:
        if r == 0 or r == n:
            a = 1
        else:
            a = ncr(n-1,r-1) + ncr(n-1,r)
        memo[(n,r)] = a
        return a

# for i in range(13):
#     print(i)
#     method += ncr(12,i)

# for i in range(16):
#     method += ncr(15,i)

# print( method - 1)
    

    

import math

x,y = IsIt()
xy = x+y
if xy%3 != 0:
    print(0)
else:
    n = xy/3
    if (max(x,y)-min(x,y)>n):
        print(0)
    else:
        print(ncr(n,min(x,y)-n)%(10**9+7))
        #print(int(comb(n,min(x,y)-n))%(10**9+7))
        # print(int(math.factorial(n)/math.factorial(min(x,y)-n)/math.factorial(2*n-min(x,y)))%(10**9+7))

Submission status: Runtime Error

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

def pairs (xs):
    if 2 > len(xs):
        return []
    else:
        return [xs[0:2]] + pairs(xs[1:])

def pascal (n):
    def compute (prev):
        return [1] + [x + y for (x,y) in pairs(prev)] + [1]
    def aux (m, prev):
        if (m > n):
            return []
        else:
            return [prev] + aux(m + 1, compute(prev))
    return aux(1, [1])
  
import math
a = 10**9+7

if (X+Y) % 3 != 0:
    print(0)
else:
    if abs(X-Y) > (X+Y)/3:
        print(0)
    else:
        line = pascal(int((X+Y)/3)+1)
        bangou = int(min(X,Y) - (X+Y)/3)
        print( line[int((X+Y)/3)][bangou]%a )

Submission status: Runtime Error

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

total = 0
n = min(x // 1, y // 2)

for i in range(n//2):
  a = (x - 1 * i) // 2
  b = (y - 2 * i) // 1
  if a == b:
    total += len(list(itertools.combinations(range(i + 1 + a), a)))
total = total * 2
if n % 2 == 1:
  a = (x - 1 * (n//2+1)) // 2
  b = (y - 2 * (n//2+1)) // 1
  if a == b:
    total += len(list(itertools.combinations(range(i + 1 + a), a)))
    
print(total % (10 ** 9 + 7))

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-

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

ans = 0
if X % 2 == 0 and Y % 2 == 0:
    print(0)
else:
    for i in range(X):
        if X == (1 + 2) * i:
            a = i
    print(a)
    print((a * 2) % (10 ** 9 + 7))

Submission status: Runtime Error

Solution code:
from math import factorial

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

for i in range(round(min(X, Y) / 2)):
    if (X - i * 2) * 2 == Y - i:
        answer = factorial(X + Y) / factorial(X) / factorial(Y)
        print(round(answer % (10 ** 9 + 7)))

Submission status: Runtime Error

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

memo = {}
def num(x,y,memo):
  if x==0 and y==0:
    return 1
  elif x<=0 or y<=0:
    return 0
      
  if (x,y) in memo.keys():
    return memo[(x,y)]
  else:
    memo[(x,y)] = num(x-2,y-1,memo) + num(x-1,y-2,memo)
    return memo[(x,y)]
  
ans = num(X,Y,memo)
ans = int(ans % (7 + 1e+9))

print(ans)

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))
    ind = min(o - 1, n - o - 1)
    print(aa[ind] % (10 ** 9 + 7))
else:
    print(0)

Submission status: Runtime Error

Solution code:
import sys
input = sys.stdin.readline
import numpy as np
from math import factorial
def print_ans(X, Y):
    """Test Case
    >>> print_ans(3, 3)
    2
    >>> print_ans(2, 2)
    0
    >>> print_ans(999999, 999999)
    151840682
    """
    A = np.array([[1, 2],[2, 1]])
    B = np.array([X, Y])
    X = np.linalg.solve(A, B)
    if X[0].is_integer() and X[1].is_integer() :
        ans1 = factorial(X[0] + X[1])
        ans2 = factorial(X[0])
        ans3 = factorial(X[1])
        mod =  (10**9+7)
        print((ans1 // ans2 * ans3 ) % mod)
        # print(math.factorial(X[0] + X[1]) // (math.factorial(X[0]) * math.factorial(X[1])))
    else:
        print("0")


if __name__ == '__main__':
    X, Y = map(int, input().rstrip().split())
    print_ans(X, Y)

Submission status: Runtime Error

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

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

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

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

    return result



mod=1000000007
X,Y=map(int,input().split())
flag=0
count=0
for i in range(min(X,Y)//3):
    if min(X,Y)*2==max(X,Y):
        flag=1
        count2=min(X,Y)
        break
    X-=3
    Y-=3
    count+=1
    #print(X,Y)

if min(X,Y)*2==max(X,Y):
    flag=1

if flag==0:
    print('0')
    exit(0)

print(cmb(count*2+count2,count)%mod)

Submission status: Runtime Error

Solution code:
from scipy.special import comb
from operator import mul
from functools import reduce
x,y=map(int,input().split(' '))
MOD = 10**9 + 7

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

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

if a.is_integer() and b.is_integer():
    a=int(a)
    b=int(b)
    print(combinations_count(a+b,a)%MOD)
else:
    print(0)

Submission status: Runtime Error

Solution code:
def factorial(n):
    if n == 1:
        return n
    return n*factorial(n-1)

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

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

ans = factorial((x+y)/3)/factorial((4*x-2*y)/6)*factorial((4*y-2*x)/6)

print(ans)

Submission status: Runtime Error

Solution code:
import math
# from scipy.special import factorial, poch
ppp=10**9+7
x,y =map(int, input().split())
a=[-(x-2*y)//3,-(-2*x+y)//3]
b=[-(x-2*y)%3,-(-2*x+y)%3]
if b[0]==0 and b[1]==0:
    print(math.factorial(a[0]+a[1])//math.factorial(a[0])//math.factorial(a[1])%ppp)
    
else:
    print(0)

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(1000000)
import numpy as np
gx,gy=map(int,input().split())
dp=(-1)*np.ones((gx+1,gy+1))
dp[gx,:]=0
dp[:,gy]=0
dp[gx,gy]=1
dp[gx-1,:]=0
dp[:,gy-1]=0
dp[gx-1,gy-2]=1
dp[gx-2,gy-1]=1
ans=0
for i in range(gx-2,-1,-1):
    for j in range(gy-2,-1,-1):
        dp[i,j]=max(dp[i+1,j+2], dp[i+2,j+1])
for i in range(gx-1):
    for j in range(gy-1):
        if dp[i+1,j+2]!=0:
            dp[i+1,j+2] = dp[i+1,j+2]+dp[i,j]
        if dp[i+2,j+1]!=0:
            dp[i+2,j+1] = dp[i+2,j+1]+dp[i,j]
print(int(dp[gx-1][gy-2]+dp[gx-2][gy-1]))

Submission status: Runtime Error

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

mod = 10**9 + 7

# ある座標に来るパターンの数を記録するDPテーブル
dp = [[0 for _ in range(X+1)] for _ in range(Y+1)]

# 初期位置を設定
dp[0][0] = 1

for y in range(Y+1):
    for x in range(X+1):
        if (x-2) >= 0 and (y-1) >= 0:
            dp[x][y] += int(dp[x-2][y-1] % mod)
        if (x-1) >= 0 and (y-2) >= 0:
            dp[x][y] += int(dp[x-1][y-2] % mod)
        dp[x][y] %= mod

print(dp[X][Y])

Submission status: Runtime Error

Solution code:
import math
from scipy.special import factorial, poch
ppp=10**9+7
x,y =map(int, input().split())
a=[-(x-2*y)//3,-(-2*x+y)//3]
b=[-(x-2*y)%3,-(-2*x+y)%3]
if b[0]==0 and b[1]==0:
    print(math.factorial(a[0]+a[1])//math.factorial(a[0])//math.factorial(a[1])%ppp)
    
else:
    print(0)

Submission status: Runtime Error

Solution code:
if __name__=='__main__':
    x,y = map(int,input().split())
    x0 = (2.0*x-y)/3.0
    y0 = (2.0*y-x)/3.0
    ans = 0
    if x0>=0 and y0>=0 and x0.is_integer() and y0.is_integer():
        ans = 1
        for i in range(max(x0,y0)+1,x0+y0):
            ans = ans*i//(i-max(x0,y0))%(10e9+7)
    if x0==0 and y0==0: ans = 0
    print(int(ans))

Submission status: Runtime Error

Solution code:
from math import factorial
import sys

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

n1 = (2 * X - Y)
n2 = (2 * Y - X)

if n1 % 3 != 0 or n2 % 3 != 0:
    print(0)
    sys.exit()
else:
    n1 = n1 // 3
    n2 = n2 // 3

if n1 == 0 and n2 == 0:
    print(0)
    sys.exit()


P = 10**9 + 7
N = 333334
inv_t = [0]+[1]
for i in range(2,N):
    inv_t += [inv_t[P % i] * (P - int(P / i)) % P]

m = 10**9+7
res = 1
for i in range(n1 + 1, n1 + n2 + 1):
    res = res * i % m
for i in range(1, n1 + 1):
    res = res * inv_t[i] % m
print(res)

Submission status: Runtime Error

Solution code:
from scipy.special import comb
x,y=map(int,input().split(' '))
MOD = 10**9 + 7

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

if a.is_integer() and b.is_integer():
    a=int(a)
    b=int(b)
    print(comb(a+b, a, exact=True)%MOD)
else:
    print(0)

Submission status: Runtime Error

Solution code:
from math import factorial
import sys
mod = 1000000007

def power_func(a,b,p):
  """a^b mod p を求める"""
  if b==0: return 1
  if b%2==0:
    d=power_func(a,b//2,p)
    return d*d %p
  if b%2==1:
    return (a*power_func(a,b-1,p ))%p

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

a = (2*Y-X) / 3
b = Y - 2*a
if a.is_integer() & b.is_integer():
    i = factorial(a+b) % mod
    j = factorial(a) % mod
    k = factorial(b) % mod
    p = mod
    print((i*power_func(j,p-2,p)*power_func(k,p-2,p))%p)
else:
    print(0)

Submission status: Runtime Error

Solution code:
import math
mod = 1000000007

def mul(a, b):
    return ((a % mod) * (b % mod)) % mod

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 mul(a, power(b, mod-2))
X,Y = map(int,input().split())
s = (2*Y-X)//3
t = (2*X-Y)//3
if (2*Y-X)%3!=0 or (2*X-Y)%3!=0:
    print(0)
else:
    a = math.factorial(s+t)%mod
    
    b = math.factorial(s)
    c = math.factorial(t)
    ans = div(div(a,b),c)
    print(ans)

Submission status: Runtime Error

Solution code:
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())

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

ans = 0

if m.is_integer() and n.is_integer():
    m = int(m)
    n = int(n)
    if m<n:m, n = n, m
        
print(comb(m+n, n, 10**9+7))

Submission status: Runtime Error

Solution code:
import numpy as np
v=np.array(list(map(int, input().split())) )
mod = 10**9 +7
import math
def cmb(n, r,mod):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n
    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

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

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

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

k = np.dot(inv_A,v)

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

Submission status: Runtime Error

Solution code:
X, Y = map(int, input().split())  # 目的地
#
dp = [[0]*(X+1) for _ in range(Y+1)]

dp[2][1] = 1
dp[1][2] = 1

for i in range(Y+1):  # iがy座標にあたる
    for j in range(X+1):  # jがx座標にあたる
        if i < 2 or j < 2:
            continue
        dp[i][j] += dp[i-1][j-2] + dp[i-2][j-1]

print(dp[Y][X])

# dp_x = [0]*(X+1)
# dp_x[1] = 1
# dp_x[2] = 2
# for i in range(3, X+1):  # Xの動きだけ専門
#     dp_x[i] += dp_x[i-1] + dp_x[i-2]
#
# dp_y = [0]*(Y+1)
# dp_y[1] = 1
# dp_y[2] = 2
# for i in range(3, Y+1):
#     dp_y[i] += dp_y[i-1] + dp_y[i-2]
# print(dp_x[X-1]*dp_y[Y-1]%1000000007)
# # print(dp_x)
# # print(dp_y)

Submission status: Runtime Error

Solution code:
def solve():
  MOD = 10**9 + 7
  X, Y = map(int, input().split())
  
  if (X+Y)%3!=0:
    print(0)
    quit()
  
  if X < Y:
    X, Y = Y, X

  sub = X - Y
  tan = X - sub

  X = sub + tan + 1
  Y = tan + 1
  dp = [[0]*X for _ in range(Y)]

  dp[2][1] = 1
  for i in range(2, Y):
    for j in range(2, X):
      dp[i][j] = dp[i][j-1] + dp[i-1][j]

  dp[i][j] %= MOD

  #print(*dp, sep='\n')
  print(dp[Y-1][X-1])

if __name__ == '__main__':
  solve()

Submission status: Runtime Error

Solution code:

    def xgcd(a, b):
    x0, y0, x1, y1 = 1, 0, 0, 1
    while b != 0:
        q, a, b = a // b, b, a % b
        x0, x1 = x1, x0 - q * x1
        y0, y1 = y1, y0 - q * y1
    return a, x0, y0

def modinv(a, m):
    g, x, y = xgcd(a, m)
    if g != 1:
        raise Exception('modular inverse does not exist')
    else:
        return x % m

x, y = map(int, input().split())
inf = 10**9+7
if (x+y)%3 > 0:
  print(0)
else:
  n = (x+y)//3
  c = [1 for i in range(n+1)]
  invc = [1 for i in range(n+1)]
  for i in range(1, n+1):
    c[i] = c[i-1]*i % inf
    invc[i] = modinv(c[i], inf)
  cnt=-1
  for i in range(n+1):
    if (i+2*(n-i)==x)&(2*i+(n-i)==y):
      cnt = i
      break
  if cnt < 0:
    ans = 0
  else:
    ans = (c[n] * invc[cnt] * invc[n-cnt]) % inf
  print(ans)

Submission status: Runtime Error

Solution code:
import math
x,y = map(int,input().split())
mod = 10**9+7
if (x+y)%3>0 or (x+y)//3-(x-y)<0:
  print(0)
else:
  n = (x+y)//3
  
  m = [1]
  b = 1
  numx = x-y + (n-(x-y))//2
  
  
  print(math.factorial(n)//math.factorial(numx)//math.factorial(n-numx) %mod  )

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
import numpy as np
import math
from scipy.special import comb

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

if(a % 3 != 0 or b % 3 != 0):
  print(0)
else:
  a = int(a/3)
  b = int(b/3)
  #ans = comb(a+b, a, exact=True)
  ans = float(math.factorial(a+b))/(math.factorial(a)*math.factorial(b))
  ans = int(ans%(1000000000 + 7))
  print(ans)

Submission status: Runtime Error

Solution code:
import sys
from scipy.special import comb
x,y=map(int,input().split())
MOD=10**9 + 7
t=(x+y)//3
if((x+y)%3!=0 or x<t or y<t or 2*t<x or 2*t<y):
    print(0)
    sys.exit()

n=t+1
k=x-t+1
#print(n)
#print(k)
print( comb(n-1,k-1,exact=True) % MOD)

Submission status: Runtime Error

Solution code:
from math import factorial
import math
def nCr(n,r):
    ans = factorial(n)//factorial(r)//factorial(n-r)
    return ans
X,Y = map(int,input().split())
n = (2*Y-X)//3
m = (2*X-Y)//3
if (2*Y-X)%3 == 0 and (2*X-Y)%3 == 0:
    ans = nCr(n+m,m) % (10**9+7)
else:
    ans = 0
print(ans)

Submission status: Runtime Error

Solution code:
import math
X, Y = map(int, input().split())
n = (((X+Y)/3)+Y-X)/2
m = n+X-Y

if n % 1 != 0 or n<0:
    ans = 0

else:
    q = n+m
    p = math.factorial(q) % (10**9+7)
    N = math.factorial(n) % (10**9+7)
    M = math.factorial(m) % (10**9+7)
    ans = p/(N*M)
    ans = ans % (10**9+7)

print(ans//1)

Submission status: Runtime Error

Solution code:
if __name__=='__main__':
    x,y = map(int,input().split())
    x0 = (2.0*x-y)/3.0
    y0 = (2.0*y-x)/3.0
    ans = 0
    if x0>=0 and y0>=0 and x0.is_integer() and y0.is_integer():
        ans = 1
        for i in range(max(x0,y0)+1,x0+y0):
            ans = ans*i//(i-max(x0,y0))%(10e9+7)
    print(int(ans))

Submission status: Runtime Error

Solution code:
def solve():
    mod = 10 ** 9 + 7

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

    sum_ = x + y

    q, r = divmod(sum_, 3)
    if r != 0:
        return 0

    a = (x * 2 - y) // 3

    # b = (y * 2 - x) // 3

    def cmb(n, r):
        return (f[n] * invs[r] * invs[n - r]) % mod

    f = [-1] * (q + 1)
    f[0] = 1
    t = 1
    for i in range(1, q + 1):
        t *= i
        t %= mod
        f[i] = t

    inv = pow(t, mod - 2, mod)
    invs = [-1] * (q + 1)
    invs[q] = inv
    for i in range(q - 1, 0, -1):
        inv *= (i + 1)  # <-直した
        inv %= mod
        invs[i] = inv

    return cmb(q, a)


print(solve())

Submission status: Runtime Error

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

mod = 10**9 + 7

# ある座標に来るパターンの数を記録するDPテーブル
dp = [[0 for _ in range(X+1)] for _ in range(Y+1)]

# 初期位置を設定
dp[0][0] = 1

for y in range(Y+1):
    for x in range(X+1):
        if (x-2) >= 0 and (y-1) >= 0:
            dp[x][y] += int(dp[x-2][y-1] % mod)
        if (x-1) >= 0 and (y-2) >= 0:
            dp[x][y] += int(dp[x-1][y-2] % mod)
        # dp[x][y] /= mod

print(dp[X][Y])

Submission status: Runtime Error

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

def function(x,y):
    ans = 0
    if(x==2*y or y == 2*x):
        ans += 1
    elif x > 2*y or y > 2*x:
        pass
    else:
        ans += function(x-2,y-1)
        ans += function(x-1,y-2)
    return ans % (10**9 + 7)
 
print(function(x,y))

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
import numpy as np
import math
from scipy.special import comb

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

if(a % 3 != 0 or b % 3 != 0):
  print(0)
else:
  a = int(a/3)
  b = int(b/3)
  ans = comb(a+b, a, exact=True)
  #ans = float(math.factorial(a+b))/(math.factorial(a)*math.factorial(b))
  ans = int(ans%(1000000000 + 7))
  print(ans)

Submission status: Runtime Error

Solution code:
import math
x,y = list(map(int,input().split()))
mod = 10**9 + 7
ans = 0
a = (2*y-x)//3
b = (2*x - y)//3
print(a,b)
ans = math.factorial(a+b)//(math.factorial(a)*math.factorial(b))
if (2*y-x)%3 != 0 or (2*x-y)%3 != 0:
    print(0)
else:
    print(ans%mod)

Submission status: Runtime Error

Solution code:
import sys
input = sys.stdin.readline
from math import factorial as fact

MOD = 10 ** 9 + 7


def inv(x):
    return pow(x, MOD - 2, MOD)


def comb(n, r):
    return (fact(n) * inv(fact(n - r)) * inv(fact(r))) % MOD


def main():
    X, Y = [int(x) for x in input().split()]

    y = (X - 2 * Y) // (-3)
    x = (X - y) // 2

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









if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
from numpy.linalg import solve
mod = 10**9+7
x,y=map(int,input().split(' '))
left = [[1,2],
        [2,1]]
right = [x,y]

A=solve(left,right)
ax,ay=float(A[0]),float(A[1])
if (not float.is_integer(ax) or not float.is_integer(ay)):
    print(0)
    exit()
ax,ay=int(ax),int(ay)
fac=[0 for i in range(ax+ay+1)]
inv=[0 for i in range(ax+ay+1)]
finv=[0 for i in range(ax+ay+1)]
fac[0] = 1
fac[1] = 1
finv[0]=1
finv[1]=1
inv[1] = 1
for i in range(2,ax+ay+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
ans = fac[ax+ay]*(finv[ax]*finv[ay])
ans %= mod
print(int(ans))

Submission status: Runtime Error

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

M = int(1e9+7)

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

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


if (x + y) % 3 == 0:
    a, b = (-x + 2 * y) // 3, (2 * x - y) // 3

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

    answer = (f[a + b] * modinv(f[a]) * modinv(f[b])) % M
    print(answer)
else:
    print(0)

Submission status: Runtime Error

Solution code:
import sys
input = sys.stdin.readline
from math import factorial as fact

MOD = 10 ** 9 + 7


def inv(x):
    return pow(x, MOD - 2, MOD)


def comb(n, r):
    return (fact(n) * inv(fact(n - r)) * inv(fact(r))) % MOD




def main():
    X, Y = [int(x) for x in input().split()]

    y = (X - 2 * Y) // (-3)
    x = (X - y) // 2

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









if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import math
i = list(map(int, input().split()))
x = i[0]
y = i[1]

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

if a.is_integer() and b.is_integer():
    a = int(a)
    b = int(b)
    ans = math.factorial(a+b) // (math.factorial(a) * math.factorial(b))
else:
    ans = 0

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

Submission status: Runtime Error

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

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

if n.is_integer() and m.is_integer() and n >= 0 and m >= 0:
  n = int(n)
  m = int(m)
  ans = int(math.factorial(n+m)//(math.factorial(n)*math.factorial(m)))
  ans = int(ans%(10**9+7))
  print(ans)
else:
  print(0)

Submission status: Runtime Error

Solution code:
import os
import math

x,y = (int(x) for x in input().split())
a = []
b = []
ans = 0
if x==y:
    if x%3==0:
        print((math.factorial(2*(x//3))//(math.factorial(x//3)*math.factorial(x//3)))%(10**9+7))
    else:
        print(0)
elif x>y:
    if x>2*y:
        print(0)
    else:
        for i in range(y//3):
            if (x-3*i)==2*(y-3*i):
                a.append(i)
        for p in a:
            ans += math.factorial(4*p+(y-3*i)//(math.factorial(2*p+(y-3*i)*math.factorial(2*p))))
            print(ans%(10**9+7))
else:
    if y>2*x:
        print(0)
    else:
        for i in range(x//3):
            if (y-3*i)==2*(x-3*i):
                b.append(i)
        for q in b:
            ans += math.factorial(4*q+(x-3*i)//(math.factorial(2*q+(x-3*i)*math.factorial(2*q))))
            print(ans%(10**9+7))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
from operator import mul
from functools import reduce

X,Y = map(int,input().split()[:2])

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

x_tmp=X
y_tmp=Y

x_count=0
y_count=0

while x_tmp*2 != y_tmp:
    x_tmp-=2
    y_tmp-=1
    x_count+=1

y_count = y_tmp//2

sum = x_count + y_count

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 #出力の制限
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 )

ret = cmb(sum,y_count,mod)
print(ret)

Submission status: Runtime Error

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

MOD = 10 ** 9 + 7

xx = 2 * Y - X
if (xx % 3 == 0 and Y - 2 * xx // 3 >= 0):
    a = xx // 3
    b = Y - 2 * a

    f = 1
    factorials = [1]
    for m in range(1, a + b + 1):
        f *= m
        f %= MOD
        factorials.append(f)

    inv = pow(f, MOD - 2, MOD)
    invs = [1] * (a + b + 1)
    invs[a + b] = inv
    for m in range(a + b, 1, -1):
        inv *= m
        inv %= MOD
        invs[m - 1] = inv

    # print (a, b, inv)

    print (factorials[-1] * invs[a] * invs[b] % MOD)

    # print (math.factorial(a + b) // math.factorial(a) // math.factorial(b) %  MOD)


else:
    print (0)

Submission status: Runtime Error

Solution code:
import sys
from math import factorial
sys.setrecursionlimit(100000)

input = sys.stdin.readline

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

mod = 10**9 + 7

def mm(a, b):
    return ((a % mod) * (b % mod)) % mod

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

def dd(a, b):
    return mm(a, pp(b, mod-2))

def xgcd(a, b):
	x0, y0, x1, y1 = 1, 0, 0, 1
	while b != 0:
	    q, a, b = a // b, b, a % b
	    x0, x1 = x1, x0 - q * x1
	    y0, y1 = y1, y0 - q * y1
	return a, x0, y0

def modinv(a, m):
    g, x, y = xgcd(a, m)
    if g != 1:
        raise Exception('modular inverse does not exist')
    else:
        return x % m

if (X+Y)%3!=0:
	ans = 0
else:
	nmsum = (X+Y)//3
	nmdif = Y-X
	if (nmsum+nmdif)%2!=0:
		ans = 0
	else:
		n = (nmsum+nmdif)//2
		m = (nmsum-nmdif)//2
		if n<0 or m<0:
			ans = 0
		else:
			t = 1
			for i in range(1,n+m+1):
				t = (t*i)%mod
				if i==n: bb = t
				if i==m: cc = t
				if i==n+m: aa = t
			# aa = factorial(n+m)%mod
			# bb = factorial(n)%mod
			# cc = factorial(m)%mod
			ans = aa * modinv(bb,mod) %mod
			ans = ans * modinv(cc,mod) %mod

print(ans)

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(500*500)

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

moves = [(2, 1), (1, 2)]


def is_not_reachable(goal, current):
    return goal[0] < current[0] or goal[1] < current[1]


def is_at_goal(goal, current):
    return goal[0] == current[0] and goal[1] == current[1]


def dfs(goal, current):
    if is_not_reachable(goal, current):
        return 0
    if is_at_goal(goal, current):
        return 1
    count = 0
    for move in moves:
        count += dfs(goal, (current[0] + move[0], current[1] + move[1]))
    return count


print(dfs((x, y), (0, 0)) % (10 ** 9 + 7))

Submission status: Runtime Error

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



if (2 * Y - X) % 3 != 0:
	print(0)
elif (2 * X - Y) % 3 != 0:
	print(0)
else:
	a = (2 * Y - X) // 3
	b = (2 * X - Y) // 3
	factorial = [1]
	for i in range(1, a + b + 5):
		factorial.append(factorial[i-1] * i % MOD)
	print(int(factorial[a + b] // (factorial[a] * factorial[b])) % MOD)

Submission status: Runtime Error

Solution code:
def solve():
    mod = 10 ** 9 + 7

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

    sum_ = x + y

    q, r = divmod(sum_, 3)
    if r != 0:
        return 0

    a = (x * 2 - y) // 3

    # b = (y * 2 - x) // 3

    def cmb(n, r):
        return (fact[n] * finv_t[r] * finv_t[n - r]) % mod

    fact = [1, 1]
    inv_t = [0, 1]
    finv_t = [1, 1]
    for i in range(2, q + 1):
        fact.append((fact[-1] * i) % mod)
        inv_t.append((-inv_t[mod % i] * (mod // i)) % mod)
        finv_t.append((finv_t[-1] * inv_t[-1]) % mod)

    return cmb(q, a)


print(solve())

Submission status: Runtime Error

Solution code:
X, Y = map(int, input().split())
def framod(n, mod, a=1):
    for i in range(1,n+1):
        a=a * i % mod
    return a

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

def comb(n, k, mod):
    a=framod(n, mod)
    b=framod(k, mod)
    c=framod(n-k, mod)
    return (a * power(b, mod-2, mod) * power(c, mod-2, mod)) % mod
mod = 10 ** 9 + 7
  
if (X + Y) % 3 == 0:
  n = (X + Y) // 3 
  if min(X, Y) >= n:
    s = min(X, Y) - n
    ans = comb(n, s, mod)
else:
  ans = 0

print(ans)

Submission status: Runtime Error

Solution code:
inf = 10**9+7

import sys

def nCr(n, r):
    r = min(r, n - r)
    if r == 0: return 1;
    if r == 1: return n;
    numerator = [n - r + i + 1 for i in range(r)]
    denominator  = [i + 1 for i in range(r)]
    for p in range(2, r + 1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p - 1, r, p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot
    result = 1
    for k in range(r):
        if numerator[k] > 1: 
            result = (result * numerator[k])%inf
    return result

x, y = map(int, input().split())
key = 0
if x == 2*y:
    print(1)
    sys.exit()
if y == 2*x:
    print(1)
    sys.exit()
while x>0 and y>0:
    x, y = x-3, y-3
    key += 1
    if x == 2*y:
        a = 1
        break
    if y == 2*x:
        a = -1
        break

if x < 0 or y < 0:
    print(0)
    sys.exit()

if a == 1:
    print(int(nCr(key*2+y ,key)))
else:
    print(int(nCr(key*2+x ,key)))

Submission status: Runtime Error

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



if (2 * Y - X) % 3 != 0:
	print(0)
elif (2 * X - Y) % 3 != 0:
	print(0)
else:
	a = (2 * Y - X) // 3
	b = (2 * X - Y) // 3
	print(a, b)
	factorial = [1]
	for i in range(1, a + b + 5):
		factorial.append(factorial[i-1] * i % MOD)
	# print(factsorial)
	print(int(factorial[a + b] // (factorial[a] * factorial[b])) % MOD)

Submission status: Runtime Error

Solution code:
import math

N = 10 ** 9 + 7

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

B3 = 2 * X - Y

if B3 % 3:
    print(0)
    exit()

B = B3 // 3

A = X - 2 * B

print(A)
print(B)


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

print(combinations_count(A + B, A) % N)

Submission status: Runtime Error

Solution code:
from scipy.special import comb

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

if not((x + y) % 3 == 0):
    print(0)
elif (x > 2*y) or (y > 2 * x):
    print(0)
else:
    k = (x + y) // 3
    i = x - k
    print(comb(k, i, exact=True) % (10 ** 9 + 7))

Submission status: Runtime Error

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



if (2 * Y - X) % 3 != 0:
	print(0)
elif (2 * X - Y) % 3 != 0:
	print(0)
else:
	a = (2 * Y - X) // 3
	b = (2 * X - Y) // 3
	print(a, b)
	factorial = [1]
	for i in range(1, a + b + 5):
		factorial.append(factorial[i-1] * i % MOD)
	# print(factsorial)
	print(factorial[a + b], factorial[a], factorial[b])
	print(int(factorial[a + b] // (factorial[a] * factorial[b])) % MOD)