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:
import math
from operator import mul
from functools import reduce
from scipy.special import comb


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


target_x, target_y = map(int, input().split())
max_times_of_two = math.floor(target_x / 2)
times_of_two = max_times_of_two
if target_x % 2 == 0:
    times_of_one = 0
else:
    times_of_one = 1
while (True):
    if times_of_two * 1 + times_of_one * 2 == target_y:
        # print("OK")
        break
    elif times_of_two * 1 + times_of_one * 2 > target_y:
        print("0")
        exit(0)
    else:
        times_of_two -= 1
        times_of_one += 2

print(comb(times_of_two + times_of_one, times_of_two, exact=True) % 1000000007)
# print(combinations_count(times_of_two + times_of_one, times_of_two) % 1000000007)

Submission status: Runtime Error

Solution code:
from scipy.special import comb

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 = comb(s+t, t, exact=True)
    print(a%(10**9+7))

Submission status: Runtime Error

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

dp = [[-1]*(x+1) for i in range(y+1)]
# dp[1][2]=1
# dp[2][1]=1
# dp[1][1]=0
# dp[1][0]=0
# dp[0][1]=0

def f(x,y):
    if (x,y)==(1,2):
        dp[y][x]=1
        return 1
    elif (x,y)==(2,1):
        dp[y][x]=1
        return 1
    elif (x,y)==(1,1):
        dp[y][x]=0
        return 0
    elif (x,y)==(0,1):
        dp[y][x]=0
        return 0
    elif (x,y)==(1,0):
        dp[y][x]=0
        return 0
    else:
        if dp[y][x]==-1:
            dp[y][x]=f(x-1,y-2)+f(x-2,y-1)
        return dp[y][x]

print(dp[y][x]%(10**9+7))

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
X, Y = map(int, input().split())
mod = 10 ** 9 + 7
ans = 0
if X == Y:
    a = X % 3
    if a == 0:
        b = X / 3
        ans = (2 ** b) % mod
        print(ans) 
    else:
        print(ans)
else:
    if X < Y:
        s = Y - X
        if s > X:
            print(ans)
        else:
            v = (X - s) / 3
            v = v % mod
            ans = (2 ** v) % mod
            for i in range(s):
                ans = ans * (v + 2)
                v += 1 
            print(ans)
    else:
        s = X - Y
        if s > Y:
            print(ans)
        else:
            v = (Y - s) / 3
            v = v % mod
            ans = (2 ** v) % mod
            for i in range(s):
                ans = ans * (v + 2)
                v += 1 
            print(ans)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
from decimal import Decimal
from scipy.special import comb
input = sys.stdin.readline


def main():
    x, y = map(int, input().split())

    if x < y:
        temp = x
        x = y
        y = temp
    t = int(x / 2)

    in2_count = 0
    step = 0
    for i in range(t + 1):
        x_step = i + (x - i * 2)
        if (y - i) % 2 != 0:
            continue

        y_step = i + int((y - i) / 2)
        if x_step == y_step:
            in2_count = i
            step = x_step
            break

    if in2_count == 0 and step == 0:
        print('0')
        return

    result = Decimal(comb(step, in2_count))
    # print(in2_count, step)
    print(result % Decimal(1000000007))


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


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import sys
import math
sys.setrecursionlimit(200000)
MOD = 10 ** 9 + 7


def main():
    X, Y = map(int, input().split())
    while X != Y:
        if X > Y:
            X -= 2
            Y -= 1
        else:
            X -= 1
            Y -= 2
    if X % 2 == 1 and Y % 2 == 1:
        ab = math.factorial((X + Y) // 3)
        a = math.factorial(X // 3)
        b = math.factorial(Y // 3)
        print(ab // (a * b) % MOD)
    else:
        print(0)



if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
X,Y = [int(i) for i in input().split()]
def check(x,y):
    if x/2 == y:
        return 0
    elif x/2 < y:
        return 1
    else:
        return 9
cnt = 0
possible = True

def mod_inv(a,m):
    x = extgcd(a,m)[0]
    return (m+x%m)%m
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 cmb(n,r):
    m = 10**9+7
    res = 1
    for i in range(1,n+1):
        res = res*i%m
    for i in range(1,r+1):
        res = res*mod_inv(i,m)%m
    for i in range(1,n-r+1):
        res = res*mod_inv(i,m)%m
    return res

while True:
    check_num =  check(X,Y)
    if check_num == 0:
        break
    elif check_num == 1:
        X += 1
        Y -= 1
        cnt += 1
    else:
        possible = False
        break
if possible == True:
    n = X / 2 
    r = cnt
    print(cmb(n,r))
else:
    print(0)

Submission status: Runtime Error

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

if (X + Y) % 3 != 0:
    print(0)
else:
    m = (X + Y) // 3 #動かした回数
    d = X - m # 2がでた回数
    num = 1
    if m - d >= d:
        for i in range(d):
            num *= m - i
        num = num // math.factorial(d)
    else:
        for i in range(m-d):
            num += m - i
        num = num // math.factorial(m - d)
    print(num % (10**9 + 7))

Submission status: Runtime Error

Solution code:
import math

x, y = (int(l) for l in input().split())
if (x+y) % 3 != 0:
    print(0)
else:
    a = (x+y)//3
    n = math.factorial(a)
    if (x+y) % 2 == 0:
        k = a // 2 + abs(x-y)
        ka = math.factorial(k)
        nk = math.factorial(a-k)
        print(int(n/(ka*nk)))
    else:
        k =  a//2 + (abs(x-y)-1)
        ka = math.factorial(k)
        nk = math.factorial(a-k)
        print(nk)
        print(int(n/(ka*nk)))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
x,y=(int(x) for x in input().split())
d=1
if((x+y)%3 !=0):
    print(0)
else:
    for i in range(int((x+y)/3/2)):
        d*=2
    print(d/(10**9+7))

Submission status: Runtime Error

Solution code:
inf = 10**9+7
import sys
a = 0
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
    print(x/y)
    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 == 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 itertools
from scipy.special import comb

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

def main():
    x, y = map(int, input().split())

    if x < y:
        x_ = y
        y_ = x

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

    else:
        n = (x+y)//3
        r = x//2

        #a = len(list(itertools.combinations(range(n), r)))
        #a = comb(n, r, exact=True)
        #a = comb_1(n, r)
        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**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 )

        a = cmb(n,r,mod)

        print(a)

        #print(int(a) % ((1e9) + 7))

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
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 *= numerator[k]
    return result

x,y= (int(_) for _ in input().split()) 
if (x+y)%3!=0:
    print(0)
    sys.exit()
else:
    n=(x+y)/3
    n=int(n)
    if x<n or y<n:
         print(0)
         sys.exit()
    else:
        x=x-n
        y=y-n
        ans=(ncr(x+y,x))
        print(ans%1000000007)

Submission status: Runtime Error

Solution code:
import math

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

a = x+y
b = abs(x-y)
c = (x+y)/3
e=1

if a%3 != 0:
    ans = 0
elif b==c:
    ans = 1
else:
    d=c / 2 + b / 2
    n=int(c-(c/2+b/2))

    for i in range(n):
        e*=d-i

    ans = int(e/math.factorial(n))%(10**9+7)

print(ans)

Submission status: Runtime Error

Solution code:
import math
x, y = map(int, input().split())
f = 0
if (x+y)%3 != 0:
	print(f)
else:
	n = (x+y)/3
	k = (math.floor(n/2))*2- math.floor(abs((x-y)/2))
	a = math.factorial(n) // math.factorial(n - k)
	ans = a%1000000007
    print(ans)

Submission status: Runtime Error

Solution code:
from collections import deque, defaultdict
# import sys
# sys.setrecursionlimit(1000000)
X, Y = map(int, input().split())

MOD = 1000000007

dp = defaultdict(int)
def search(r, c):
    if (r > X) or (c > Y):
        return 0

    # if dp[r][c] is not None:
    #     return dp[r][c]
    if (r, c) in dp:
        return dp[(r, c)]

    if (r == X) and (c == Y):
        return 1

    ret = search(r + 1, c + 2) + search(r + 2, c + 1)

    # dp[r][c] = ret
    dp[(r, c)] = ret
    return ret
  
print(search(0, 0) % MOD)

Submission status: Runtime Error

Solution code:
import sys
input = sys.stdin.readline

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

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

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

X, Y = [int(x) for x in input().strip().split()]
p = (X, 2 * X)
n1 = X
n2 = 0
f = True
while p != (X, Y):
    n1 -= 2
    n2 += 1
    p = (n1 + 2 * n2, 2 * n1 + n2)
    if p[1] <= 0:
      	f = False
        break
if f:
    print(combination(n1 + n2, n1) % (10 ** 9 + 7))
else:
    print(0)

Submission status: Runtime Error

Solution code:
import sys
x,y=map(int,input().split())
if ((2*x)-y)%3!=0 or ((2*y)-x)%3!=0:
  print(0)
  sys.exit()
n=((2*x)-y)//3
m=((2*y)-x)//3
l=min(m,n)
num=m+n
x=1
for i in range(1,l):
  num*=(m+n-l)
  x*=i
x*=l
print((num//x)%((10**9)+7))

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

Z=((X+Y)//3)

if (X+Y)%3==0 and abs(X-Y)<=Z:
  ans=(comb(Z, X-Z,(10**9+7)
  print(ans)
else:
  print(0)

Submission status: Runtime Error

Solution code:
import math
from operator import mul
from functools import reduce
from scipy.special import comb


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


target_x, target_y = map(int, input().split())
max_times_of_two = math.floor(target_x / 2)
times_of_two = max_times_of_two
if target_x % 2 == 0:
    times_of_one = 0
else:
    times_of_one = 1
while (True):
    if times_of_two * 1 + times_of_one * 2 == target_y:
        # print("OK")
        break
    elif times_of_two * 1 + times_of_one * 2 > target_y:
        print("0")
        exit(0)
    else:
        times_of_two -= 1
        times_of_one += 2

print("times_of_one:", times_of_one)
print("times_of_two:", times_of_two)
print(comb(times_of_two + times_of_one, times_of_two, exact=True) % 1000000007)
# print(combinations_count(times_of_two + times_of_one, times_of_two) % 1000000007)

Submission status: Runtime Error

Solution code:
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 = Y - sub

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

dp[1][0] = 1
for i in range(1, Y):
  for j in range(1, X):
    if dp[j][i]:
      dp[i][j] = dp[j][i]
      continue
    dp[i][j] = (dp[i][j-1] + dp[i-1][j]) % MOD

print(dp[Y-1][X-1])

Submission status: Runtime Error

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

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

ans = 0
for i in range(int(X)):
    for h in range(int(X)):
        if X == 1 * i + 2 * h:
            a = i
            b = h
if Y == 1 * b + 2 * a:
    ans = (a + b) 

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

Submission status: Runtime Error

Solution code:
import math
[x,y]=list(map(int,input().split()))
if ((x%3)+(y%3))%3!=0:
	print(0)
else:
	dansu=int((x+y)/3)
	r=y-dansu
	# d=1
	# rr=1
	# nr=1
	# for i in range(1,dansu+1):
		# d=d*(i%(10**9+7))
	# for i in range(1,r+1):
		# rr=rr*(i%(10**9+7))
	# for i in range(1,dansu-r+1):
		# nr=nr*(i%(10**9+7))
	
	# kotae=int(d/(rr*nr))
	kotae=math.factorial(dansu)//(math.factorial(dansu-r)*math.factorial(r))
	kotae=kotae%(10**9+7)
	
	print(kotae)

Submission status: Runtime Error

Solution code:
from math import factorial
import sys

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

for i in range(min(X + 1, Y + 1)):
    if (min(X, Y) - i) == (max(X, Y) - i * 2) * 2:
        answer = factorial(max(X, Y) - i) / factorial(i) / factorial(max(X, Y) - i * 2)
        print(round(answer % (10 ** 9 + 7)))
        sys.exit()
print('0')

Submission status: Runtime Error

Solution code:
import sys

sys.setrecursionlimit(10**6)
input=sys.stdin.readline

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


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

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

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

val_min_sho = int(val_min/3)

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

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
import math
def permutations_count(a, b):
    return math.factorial(a) // math.factorial(a - b)

def main():
    intStr = input().split()
    try:
        intX = int(intStr[0])
        intY = int(intStr[1])
    except Exception as e:
        return 0

    n = (2 * intX - intY) / 3
    m = intY - 2 * n

    if (2 * intX - intY) % 3 != 0:
        print('0')

    print(permutations_count(n+m,n) % (1000000000+7))


main()

Submission status: Runtime Error

Solution code:
import sys
input = sys.stdin.readline

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

#output
import math

if (X + Y) % 3 == 0:
    k = (-X + 2*Y) //3
    l = (2*X -Y) //3
    answer = math.factorial(k+l)//(math.factorial(k)*math.factorial(l)) % (10**9 + 7)
else:
    answer = 0

print(answer)

Submission status: Runtime Error

Solution code:
n = list(map(int, input().split()))
def kaijo(p, q):
    s = 1
    for i in range(p+1,q+1):
        s = s * i
    return(s)
a = (n[0]+n[1]) // 3
b = (a + abs(n[0]-n[1])) // 2
if (n[0]+n[1])%3 == 0 and a >= b:
    print((kaijo(a-b, a)/(kaijo(0, a-b)))%1000000007)
else: print(0)

Submission status: Runtime Error

Solution code:
def pas(n):
    if n<1 :
        return [1]
    p = pas(n-1)
    return list(map(lambda a,b:a+b, [0]+p, p+[0]))

x,y = map(int,input().split())
if (x+y) % 3 != 0:
    print("0")
else:
    t = (x+y) // 3
    if x >= t and y >= t:
        ans = pas(t)
        print(ans[x-t]%(10**9+7))
    else:
        print("0")

Submission status: Runtime Error

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

#
# dp = [[0]*4 for _ in range(4)]
# for

if (X+Y)%3 != 0:
    print(0)
    exit()
dp = [0]*(min(X, Y)+1)
dp[1] = 1
dp[2] = 2
for i in range(3, len(dp)):
    dp[i] += (dp[i-1] + dp[i-2])%1000000007

print(sum(dp[math.ceil(max(X, Y)/2):-1])%1000000007)
# print(dp)

Submission status: Runtime Error

Solution code:
import math

N = input().split()
X = int(N[0])
Y = int(N[1])

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

if (2 * Y - X) % 3 != 0 or (2 * X - Y) % 3 != 0:
    print(0)
else:
    a = 1
    if x < y:
        for i in range(x):
            a *= x + y - i
        a = a / math.factorial(x)
    else:
        for i in range(y):
            a *= x + y - i    
        a = a / math.factorial(y)
    print(int(a))

Submission status: Runtime Error

Solution code:
import sys
import numpy as np

INPUT = lambda: sys.stdin.readline().rstrip()
MAP = lambda: map(int, INPUT().split())

sys.setrecursionlimit(10 ** 9)
mod = 10 ** 9 + 7


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

    s = (2*X - Y)//3
    t = (2*Y - X)//3
    MAX_NUM = max(X, Y)
    dp = np.zeros((X+1, Y+1), np.int)
    for i in range(MAX_NUM):
        if i == 0:
            for j in range(len(dp[0])):
                if j == 0: dp[i][j] = 0
                else: dp[i][j] = 1
        else:
            for j in range(len(dp[0]-1)):
                if j == 0: dp[i][j] = 1
                else: dp[i][j] = dp[i-1][j] + dp[i][j-1]

    print(dp[s][t] % mod)


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
from math import ceil
md= 1000000000+7
x,y=map(int,input().strip().split())
c =(x-1+y-2)*(x-2+y-1)
m = (x-1+y-2)+(x-2+y-1)
print(ceil(c/m)%md)

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:
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
    print(x/y)
    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 not a:
    print(0)
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 numpy as np
x, y = map(int, input().split())
table = np.ones((x+1, y+1)) * -1

for i in range(x):
  table[i,0] = 0
for j in range(y):
  table[0,j] = 0
table[0,0] = 1


for i in range(1,x+1):
  for j in range(1,y+1):
     a1 = 0
     a2 = 0
     if i-1 >= 0 and  j-2 >= 0:
        a1 = table[i-1, j-2]
     if i-2 >= 0 and  j-1 >= 0:
      	a2 = table[i-2,j-1]
     table[i,j] = a1 + a2

print(int(table[x,y] % (1e9+7)))

Submission status: Runtime Error

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

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

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

Submission status: Runtime Error

Solution code:
MOD = 10 ** 9 + 7

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

dp = [[0 for _ in range(x + 1)] for _ in range(y + 1)]

dp[x][y] = 1

for i in range(x, -1, -1):
    for j in range(y, -1, -1):
        if i == x and j == y:
            continue
        pt = 0
        if i + 1 <= x and j + 2 <= y:
            pt += dp[i + 1][j + 2]
        if i + 2 <= x and j + 1 <= y:
            pt += dp[i + 2][j + 1]
        dp[i][j] = pt

print(int(dp[0][0]) % MOD)

Submission status: Runtime Error

Solution code:
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools
sys.setrecursionlimit(10**8)
mod = 10**9+7
mod2 = 998244353
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

n,w = inpl()
wv = [inpl() for i in range(n)]
dp = [[0 for i in range(w+1)] for j in range(n+1)]
wv.sort()
wv.sort(key=lambda x:x[1])
ww = [0] * n
vv = [0] * n
for i in range(n):
    ww[i],vv[i] = wv[i][0], wv[i][1]
for i in range(n-1):
    for j in range(w+1):
        if j >= ww[i]:
            dp[i+1][j] = max(dp[i][j], dp[i][j-ww[i]]+vv[i])
        else:
            dp[i+1][j] = dp[i][j]
res = dp[n-1][w-1]+wv[n-1][1]
tmp = wv[n-1][1]
dp = [[0 for i in range(w+1)] for j in range(n+1)]
wv.sort()
ww = [0] * n
vv = [0] * n
for i in range(n):
    ww[i],vv[i] = wv[i][0], wv[i][1]

if sum(ww[:n-1]) < w:
    print(sum(vv))
    quit()
for i in range(n-1):
    for j in range(w+1):
        if j >= ww[i]:
            dp[i+1][j] = max(dp[i][j], dp[i][j-ww[i]]+vv[i])
        else:
            dp[i+1][j] = dp[i][j]
print(max(res,dp[n-1][w-1]+tmp))

Submission status: Runtime Error

Solution code:
import logging

logging.basicConfig(level=logging.INFO, format="%(message)s")
#logging.disable(logging.CRITICAL)



def main():
    X, Y = map(int, input().split())
        
    dp = [[0 for i in range(X + Y)] for j in range(X + Y)]
    logging.info("reset 0")
    dp[0][0] = 0
    dp[1][2] = 1
    dp[2][1] = 1
    
    for i in range(2, X + 1):
        for j in range(2, Y + 1):
            if (i + j) % 3 == 0:
                dp[i][j] = dp[i - 2][j - 1] + dp[i - 1][j - 2] 
                

    print(dp[X][Y] % (10 ** 9 + 7))
    
    
if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
import numpy as np
X, Y = map(int, input().split())
dp = np.zeros((X+1,Y+1))
dp[0][0] = 1
for n in range(2,X+1):
    for m in range(2,Y+1):
        dp[n][m] = (dp[n-1][m-2]+dp[n-2][m-1])%(10**9+7)
print(int(dp[X][Y]))

Submission status: Runtime Error

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

if not (x+y)%3==0:
    print(0)
else:
    a = (2*x-y)//3
    b = (2*y-x)//3
    ans = factorial(a+b)//(factorial(a)*factorial(b))
    print(int(ans%m))

Submission status: Runtime Error

Solution code:
import math

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):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

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:
X, Y = map(int, input().split())
a = 0
for i in range(X + 1):
    N = i
    if (X - N) % 2 != 0:
        continue
    M = (X - N) / 2
    
    x = N + 2 * M
    y = 2 * N + M
    if X == x and Y == y:
        a = N
#print(a)

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**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 )
if a != 0:
    ans = cmb(X-1,a,mod)
    print(ans)
else:
    print("0")

Submission status: Runtime Error

Solution code:
def powermod(a, p, mod):
    if p == 0:
        return 1
    elif p % 2 == 0:
        return (powermod(a, p//2, mod) ** 2) % mod
    else:
        return ((powermod(a, (p-1)//2, mod) ** 2) % mod) * a % mod

def combinationmod(n,r):
    mod = 10 ** 9 + 7
    factorial = 1
    for i in range(n):
        factorial = (factorial * (i+1)) % mod
        if i+1 == r:
            fact_1 = factorial
        if i+1 == n-r:
            fact_2 = factorial
        if i+1 == n:
            fact_0 = factorial
    return fact_0 * powermod(fact_1,mod-2,mod) % mod * powermod(fact_2,mod-2,mod) % mod
    
X,Y = map(int,input().split())
if (X + Y) % 3 == 0 and X <= 2 * Y and 2 * X >= Y:
    turns = (X + Y) // 3
    print(combinationmod(turns, min(X,Y) - turns))
else:
    print(0)

Submission status: Runtime Error

Solution code:
from scipy import special
x,y = map(int,input().split())
if x<y:
    temp = x
    x = y
    y = x
count = 0

if x == y and x % 3 ==0 and y % 3 == 0:
    print(int(special.comb((x/3)*2,x/3)))
else:
    while True:
        print(count)
        if x == y*2:
            print(int(special.comb(y+(count*2), count)))
            break
        elif x > y*2:
            print(0)
            break
        else:
            x =x - 3
            y =y - 3
            count +=1

Submission status: Runtime Error

Solution code:
import copy
x,y = [int(s) for s in input().split()]
print(x,y)
def replace_zahyo(list, sum):
    print(list,sum)
    list1 = copy.deepcopy(list)
    if list == []: #リスtがからで終わり
        return sum
    for first in list1:
        if first == (0,0): #0,0にたどり着いたら加算
            sum+=1
            list.remove(first)
            return replace_zahyo(list,sum)
        elif first[0] <= 0 or first[1] <= 0: #外に出たら終わり
            list.remove(first)
            return replace_zahyo(list,sum)
        else:#普通
            list.append((first[0]-1, first[1]-2))
            list.append((first[0]-2, first[1]-1))
            list.remove(first)
            return replace_zahyo(list,sum)
print(replace_zahyo([(x,y)],0))

Submission status: Runtime Error

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())
 
def f(x, y):
  s=max(x, y)
  t=min(x, y)
  st=s+t
  ans=1
  for i in range(1, t+1):
    ans=ans*(st+1-i)//i
    ans=ans%(10**9+6)
    
  return ans
  
      
b=(2*X-Y)//3
btemp=(2*X-Y)%3
a=(Y-a)//2
atemp=(Y-a)%2
if btemp>0 or atemp>0:
  ans=0
else:
  a=(Y-b)//2
  
  #ans=mt.factorial(a+b)//(mt.factorial(a)*mt.factorial(b))
  #ans=tool.permutations(a+b)//(tool.permutations(a)*tool.permutations(b))
  #s=max(a, b)
  #t=min(a, b)
  #ans=comb(s+t, t, 10**9+7)
  m=10**9+7
  ans=1
  for i in range(1, a+b+1):
    ans=ans*i%m
  for i in range(1, a+1):
    ans=ans*mod_inv(i, m)%m
  for i in range(1, b+1):
    ans=ans*mod_inv(i, m)%m
print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np
X, Y = map(int, input().split())
dp = np.zeros((X+1,Y+1))
dp[0][0] = 1
dp[1][2] = 1
dp[2][1] = 1
for n in range(2,X+1):
    for m in range(2,Y+1):
        dp[n][m] = (dp[n-1][m-2]+dp[n-2][m-1])%(10**9+7)
print(int(dp[X][Y]))