TnT/Multi_CodeNet4Repair huggingface dataset:
Problem: 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.

Submission attempts (in order):
import sys

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

i = x
j = y
if (2*max(x,y) - min(x,y)) % 3 != 0:
	print(0)
	sys.exit()

c1 = (2*max(x,y) - min(x,y)) // 3
c2 = max(x,y) - 2*c1

c1 %= MOD
c2 %= MOD

ans = cmb(c1 + c2 , c1,MOD)
print(ans%MOD)


import math
import sys

def cmb(n, r):
	if n - r < r: r = n - r
	if r == 0: return 1
	if r == 1: return n

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

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

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

	return result

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

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

MOD = 10**9+7

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

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

print(0)



Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
    MOD = 10 ** 9 + 7
     
    X, Y = map(int, input().split())
     
    a = (2 * X - Y) // 3
    b = (2 * Y - X) // 3
     
    if not ((2 * X - Y) % 3 == 0 and (2 * Y - X) % 3 == 0 and a >= 0 and b >= 0):
        print(0)
        exit()
     
    maxf = a + b + 1
    f = [1 for _ in range(maxf)]
    invf = [1 for _ in range(maxf)]
     
    for i in range(1, maxf):
        f[i] = (i * f[i - 1]) % MOD
    invf[maxf - 1] = pow(f[maxf - 1], MOD - 2, MOD)
     
    for i in range(maxf - 1, 0, -1):
        invf[i - 1] = (i * invf[i]) % MOD
     
     
    def comb(a, b):
        return (f[a + b] * invf[a] * invf[b]) % MOD
     
     
    print(comb(a, b))

MOD = 10 ** 9 + 7

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

a = (2 * X - Y) // 3
b = (2 * Y - X) // 3

if not ((2 * X - Y) % 3 == 0 and (2 * Y - X) % 3 == 0 and a >= 0 and b >= 0):
    print(0)
    exit()

maxf = a + b + 1
f = [1 for _ in range(maxf)]
invf = [1 for _ in range(maxf)]

for i in range(1, maxf):
    f[i] = (i * f[i - 1]) % MOD
invf[maxf - 1] = pow(f[maxf - 1], MOD - 2, MOD)

for i in range(maxf - 1, 0, -1):
    invf[i - 1] = (i * invf[i]) % MOD


def comb(a, b):
    return (f[a + b] * invf[a] * invf[b]) % MOD


print(comb(a, b))


Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
import math

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

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

if (2*x-y) % 3 == 0:
    b = (2*x-y)/3
    a = x-2*b
    if a<0:
        print(0)
        exit()
else:
    print(0)
    exit()

print(int(comb(a+b, a)%(1e9+7)))


p = 10**9+7
def nCr(n,r):
    if r*2>n:
        return nCr(n,n-r)
    else:
        a = b = 1
        for i in range(r):
            a = a * (n - i) % p
            b = b * (r - i) % p
        return (a * pow(b,p-2,p)) % p

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

if (2*x-y) % 3 == 0 and (2*y-x) % 3 == 0 and (2*x-y)>=0 and (2*y-x)>=0:
    b = (2*x-y)//3
    a = x-2*b
else:
    print(0)
    exit()

print(int(nCr(a+b, a)))


Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
import numpy as np
e = 1000000000 + 7
N = 1000000

def binominal(n, k):
	if k == 0 or k == n:
		return 1
	else:
		ans = 1
		for i in range(0, k):
			ans = (ans * (n - i) / (k - i)) % e 
		return ans



# 	pre[0] = 1
# 	for _ in range(n):


# 	return int(pre[k])


if __name__ == "__main__":
	X, Y = map(int, input().split())
	if (X + Y) % 3 != 0:
		print("0")
	else:
		n = (X + Y) // 3
		k = Y - n
		print(binominal(n, k))

MOD = 10 ** 9 + 7

def modPow(a, x, p):
	res = 1
	while x > 0:
		if x % 2 != 0:
			res = res * a % p
		a = a * a % p
		x = x // 2
	return res
 
def modInverse(a, p):
	return modPow(a, p - 2, p)
 
def modBinomial(n, k, p):
	numerator = 1
	for i in range(k):
		numerator = (numerator * (n - i)) % p
	denominator = 1
	for i in range(1, k + 1):
		denominator = (denominator * i) % p
	return (numerator * modInverse(denominator, p)) % p


if __name__ == "__main__":
	X, Y = map(int, input().split())
	if (X + Y) % 3 != 0 or Y > 2 * X or Y < X / 2.:
		print("0")
	else:
		n = (X + Y) // 3
		k = Y - n
		print(modBinomial(n, k, MOD))

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
from collections import deque
p = 10**9+7
x,y = map(int,input().split())
x += 1 ; y += 1
map_a=[[0]*y for _ in range(x)]
d = [(2,1),(1,2)]
que = deque()
que.append((0,0))

map_a[0][0] = 1

print(map_a)
while que:
    a,b = que.popleft()
    for u,v in d:
        m = a + u ; n = b + v
        if 0<=m<x and 0<=n<y:
            map_a[m][n] += map_a[a][b]%p
            que.append((m,n))

print(map_a[-1][-1])


x,y = map(int,input().split())
m = 10**9+7
if not((x+y)%3== 0 and abs(x-y)<=(x+y)//3):
    print(0);exit()

def comb(n,k):
    
        #k = n - k
    a = 1
    for i in range(1,k+1):
        a *= (n - ( i - 1)) * pow(i,m-2,m)
        a = a%m
    return a

n = (x+y)//3
k = x-n
print(comb(n,k))


Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
X, Y = map(int, input().split())
if (X+Y)%3 != 0:
  print(0)
  exit()
N = (X+Y)//3
# C_N_X-N

MAX = 3000000
MOD = 1000000007
fac = [0]*MAX
finv = [0]*MAX
inv = [0]*MAX
fac[0] = 1
fac[1] = 1
finv[0] = 1
finv[1] = 1
inv[1] = 1
for i in range(2, MAX):
  fac[i] = fac[i-1]*i%MOD
  inv[i] = MOD - inv[MOD%i]*(MOD//i)%MOD
  finv[i] = finv[i-1]*inv[i]%MOD
def COM(n, k):
  if n < 0 or k < 0 or n < k:
    return 0
  return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD
r = COM(N, X-N)
print(r)


X, Y = map(int, input().split())
if (X+Y)%3 != 0:
  print(0)
  exit()
N = (X+Y)//3
# C_N_X-N
MAX = 700000
MOD = 1000000007
fac = [0]*MAX
finv = [0]*MAX
inv = [0]*MAX
fac[0] = 1
fac[1] = 1
finv[0] = 1
finv[1] = 1
inv[1] = 1
for i in range(2, MAX):
  fac[i] = fac[i-1]*i%MOD
  inv[i] = MOD - inv[MOD%i]*(MOD//i)%MOD
  finv[i] = finv[i-1]*inv[i]%MOD
def COM(n, k):
  if n < 0 or k < 0 or n < k:
    return 0
  return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD
r = COM(N, X-N)
print(r)


Verdicts: Time Limit Exceeded

Accepted
Problem: 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.

Submission attempts (in order):
import functools, sys

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

mod = 10 ** 9 + 7

def modpow(x, y):
    z = 1
    while y > 0:
        if y % 2 == 0:
            x = (x * x) % mod
            y //= 2
        else:
            z = (z * x) % mod
            y -= 1
    return z

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

def c(n, r):
    fct = [None] * (n + 1)
    fct[0] = 1
    for i in range(1, n + 1):
        fct[i] = fct[i - 1] * i % mod
    return fct[n] * (modinv(fct[n - r]) * modinv(fct[r]) % mod) % mod

def f():
    a = 0
    while True:
        p = x - a
        q = y - 2 * a
        if p <= 0 or q <= 0:
            return 0
        if p % 2 == 0 and p // 2 == q:
            b = q
            break
        a += 1
    
    print(a, b)
    return c(a + b, a)

print(f())

import functools, sys

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

mod = 10 ** 9 + 7

def modpow(x, y):
    z = 1
    while y > 0:
        if y % 2 == 0:
            x = (x * x) % mod
            y //= 2
        else:
            z = (z * x) % mod
            y -= 1
    return z

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

def c(n, r):
    if n == r or r == 0:
        return 1

    fct = [None] * (n + 1)
    fct[0] = 1
    for i in range(1, n + 1):
        fct[i] = fct[i - 1] * i % mod
    return fct[n] * (modinv(fct[n - r]) * modinv(fct[r]) % mod) % mod

def f():
    if 2 * y - x < 0 or (2 * y - x) % 3 != 0:
        return 0
    a = (2 * y - x) // 3
    b = y - 2 * a
    if b < 0:
        return 0
    
    return c(a + b, a)

print(f())

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
X, Y = map(int,input().split())

if (2*X-Y)/3 % 3 != 0 or (2*Y-X)/3 % 3 != 0:
    print(0)
    exit()

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

mod = 10**9+7


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

print(comb(n+m, n, mod))

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

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

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

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

mod = 10**9+7


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

print(comb(n+m, n, mod))


Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
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 = 2*10**6 + 1
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())

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

A = (2*Y - X) // 3
B = (2*X - Y) // 3

print(cmb(A+B, A, mod))


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())

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

A = (2*Y - X) // 3
B = (2*X - Y) // 3

print(cmb(A+B, A, mod))


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

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

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

A = (2 * Y - X) // 3
B = (2 * X - Y) // 3

print(cmb(A + B, A))


Verdicts: Time Limit Exceeded

Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
X, Y = map(int,input().split())
MOD = 10 ** 9 + 7


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

if (X+Y) % 3 != 0:
    print(0)
else:
    total_move = (X+Y) // 3
    
    right_move =  min(X,Y) - total_move
    if right_move * 2 in (X, Y):
        print(calc_comb(total_move, right_move, MOD))
    else:
        print(0)



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


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

if (X+Y) % 3 != 0:
    print(0)
else:
    total_move = (X+Y) // 3
    
    right_move =  min(X,Y) - total_move
    if right_move >= 0:
        print(calc_comb(total_move, right_move, MOD))
    else:
        print(0)



Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
mod = 10 ** 9 + 7

fact = [1]
fact_inv = [1]
for i in range(10 ** 6):
    new_fact = fact[-1] * (i + 1) % mod
    fact.append(new_fact)
    fact_inv.append(pow(new_fact, mod - 2, mod))

def mod_comb_k(n, k, mod):
    return fact[n] * fact_inv[k] % mod * fact_inv[n-k] % mod

def solve():
    X, Y = map(int, input().split())
    if (2 * X - Y) % 3 == 0:
        s = (2 * Y - X) // 3
        t = (2 * X - Y) // 3
        ans = mod_comb_k(s + t, s, mod)
        print(ans)
    else:
        print(0)

solve()

def mod_comb(n, k, p):
    if k > n - k:
        k = n - k
    
    numerator = 1
    denominator = 1
    for i, j in zip(range(n - k + 1, n + 1), range(1, k + 1)):
        numerator = (numerator * i) % p
        denominator = (denominator * j) % p
    
    return (numerator * pow(denominator, p - 2, p)) % p

def solve():
    mod = 10 ** 9 + 7
    X, Y = map(int, input().split())
    s = 2 * Y - X
    t = 2 * X - Y
    if s >= 0 and s % 3 == 0 and t >= 0 and t % 3 == 0:
        s //= 3
        t //= 3
        print(mod_comb(s + t, s, mod))
    else:
        print(0)

solve()

Verdicts: Time Limit Exceeded

Accepted
Problem: 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.

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


X,Y = map(int,input().split())
s = (2*Y-X)//3
t = (2*X-Y)//3

if (2*Y-X)%3==0 and (2*X-Y)%3==0 :
    ans =  combination(s+t,t,mod)
    print(ans)
else:
    print(0)
    

def combination(n, k, p):
    numerator = 1
    for i in range(k):
        numerator = (numerator * (n-i)) % p
 
    denominator = 1
    for i in range(1, k+1):
        denominator = (denominator * i) % p
 
    return (numerator * pow(denominator, p-2, p)) % p
 
 
X, Y = map(int, input().split())
 
a = (2*Y-X) / 3
b = (2*X-Y) / 3
 
if a >= 0 and b >= 0 and a == int(a) and b == int(b):
    a = int(a)
    b = int(b)
 
    print(combination(a+b, a, 10**9+7))
else:
    print(0)

Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
a,b = map(int,input().split())
if (a+b)%3 == 0:
  a == a - min(a,b)
  b == b - min(a,b)
  c = a+b
  import math
  aa = math.factorial(a)
  bb = math.factorial(b)
  cc = math.factorial(c)
  print((cc/(bb*aa))%(10**9+7))
else:
  print(0)

a,b = map(int,input().split())
if (a+b)%3 == 0:
  n = (a+b)/3
  aa = math.factorial(a-n)
  bb = math.factorial(b-n)
  cc = math.factorial(n)
  print((cc/(bb*aa))%(10**9+7))
else:
  print(0)

a,b = map(int,input().split())
if (a+b)%3 == 0:
  n = (a+b)/3
  import math
  aa = math.factorial(a-n)
  bb = math.factorial(b-n)
  cc = math.factorial(n)
  print((cc/(bb*aa))%(10**9+7))
else:
  print(0)

import math
import numpy as np

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

A = np.array([[1, 2],
           [2, 1]])

b = np.array([x, y])

N = np.linalg.solve(A, b)


if N[0].is_integer() == True and N[1].is_integer() == True and N[0] >=0 and N[1] >=0:
  
  k = math.factorial(N[0]+N[1])/(math.factorial(N[0])*math.factorial(N[1]))

  print(int(k%1000000007))

else:
  print(0)


import math
import numpy as np

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

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

  A = np.array([[1, 2],
                [2, 1]])

  b = np.array([x, y])

  N = np.linalg.solve(A, b)


  if N[0].is_integer() == True and N[1].is_integer() == True and N[0] >=0 and N[1] >=0:
        
      print(cmb(int(N[0]+N[1]),int(N[0]),mod))

  else:
      print(0)

else:
  print(0)

Verdicts: Runtime Error

Runtime Error

Runtime Error

Time Limit Exceeded

Accepted
Problem: 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.

Submission attempts (in order):
def factorial_mod(n, mod):
    a = 1
    for i in range(1, n + 1):
        a *= i
        a %= mod
    return a


def comb_mod(n, k, mod):
    if k > n or k < n:
        return 0
    fact_n = factorial_mod(n, mod)
    fact_k = factorial_mod(k, mod)
    fact_n_k = factorial_mod(n - k, mod)
    return (fact_n * pow(fact_k, mod - 2, mod) * pow(fact_n_k, mod - 2, mod)) % mod


def main():
    x, y = map(int, input().split())
    MOD = 10 ** 9 + 7
    if (2 * x - y) % 3 != 0 or (2 * y - x) % 3 != 0:
        print(0)
        exit()
    i = (2 * x - y) // 3
    j = (2 * y - x) // 3
    print(comb_mod(i + j, i, MOD))


if __name__ == '__main__':
    main()


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


def comb_mod(n, k, mod):
    if k > n or k < 0:
        return 0
    fact_n = factorial_mod(n, mod)
    fact_k = factorial_mod(k, mod)
    fact_n_k = factorial_mod(n - k, mod)
    return (fact_n * pow(fact_k, mod - 2, mod) * pow(fact_n_k, mod - 2, mod)) % mod


def main():
    x, y = map(int, input().split())
    MOD = 10 ** 9 + 7
    if (2 * x - y) % 3 != 0 or (2 * y - x) % 3 != 0:
        print(0)
        exit()
    i = (2 * x - y) // 3
    j = (2 * y - x) // 3
    print(comb_mod(i + j, i, MOD))


if __name__ == '__main__':
    main()


Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
X,Y=map(int,input().split())
mod=pow(10,9)+7
if (X+Y)%3!=0:
    print("0")
else:
    m=int((2*X-Y)/3)
    n=int((2*Y-X)/3)
    bunsi=1
    bunbo=1
    for i in range(0,n):
        bunsi=(bunsi*(m+1+i))%mod
        bunbo=(bunbo*(1+i))%mod
    print(bunsi*pow(bunsi,mod-2,mod))


X,Y=map(int,input().split())
mod=pow(10,9)+7
m=(2*X-Y)//3
n=(2*Y-X)//3
if  m==(2*X-Y)/3 and n!=(2*Y-X)/3 and m>=0 and n>=0:
    bunsi = 1
    bunbo = 1
    for i in range(0, n):
        bunsi = (bunsi * (m + 1 + i)) % mod
        bunbo = (bunbo * (1 + i)) % mod
    print((bunsi * pow(bunbo, mod - 2, mod)) % mod)

else:
    print(0)

X,Y=map(int,input().split())
mod=pow(10,9)+7
m=(2*X-Y)//3
n=(2*Y-X)//3
if (X+Y)%3!=0 or m<=0 or n<=0:
    print("0")
else:
    bunsi=1
    bunbo=1
    for i in range(0,n):
        bunsi=(bunsi*(m+1+i))%mod
        bunbo=(bunbo*(1+i))%mod
    print((bunsi*pow(bunsi,mod-2,mod))%mod)

X,Y=map(int,input().split())
mod=pow(10,9)+7
m=(2*X-Y)//3
n=(2*Y-X)//3
if  m==(2*X-Y)/3 and n!=(2*Y-X)/3 and m<=0 and n<=0:
    bunsi = 1
    bunbo = 1
    for i in range(0, n):
        bunsi = (bunsi * (m + 1 + i)) % mod
        bunbo = (bunbo * (1 + i)) % mod
    print((bunsi * pow(bunbo, mod - 2, mod)) % mod)

else:
    print(0)

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

else:
    print(0)
    bunsi = 1
    bunbo = 1
    for i in range(0, n):
        bunsi = (bunsi * (m + 1 + i)) % mod
        bunbo = (bunbo * (1 + i)) % mod
    print((bunsi * pow(bunbo, mod - 2, mod)) % mod)

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

else:
    bunsi = 1
    bunbo = 1
    for i in range(0, n):
        bunsi = (bunsi * (m + 1 + i)) % mod
        bunbo = (bunbo * (1 + i)) % mod
    print((bunsi * pow(bunbo, mod - 2, mod)) % mod)

Verdicts: Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
X, Y = map(int, input().split())

# dp = [[0 for _ in range(X+1)] for __ in range(Y+1)]
# dp[1][2] = 1
# dp[2][1] = 1

# for xi in range(X + 1):
#     for yi in range(Y + 1):
#         dp[xi][yi] = dp[xi - 1][yi - 2] + dp[xi - 2][yi - 1]

# print(dp[X][Y])
import sys
sys.setrecursionlimit(100000)  

def help(x, y):
    if x < 0 or y < 0:
        return 0
    if (x == 1 and y == 2) or (x == 2 and y == 1):
        return 1
    else:
        return (help(x - 1, y - 2) + help(x - 2, y - 1))%(10e9+7)

print(help(X, Y))

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

sys.setrecursionlimit(10000)  

def help(x, y):
    if x < 0 or y < 0:
        return 0
    if (x == 1 and y == 2) or (x == 2 and y == 1):
        return 1
    else:
        return (help(x - 1, y - 2) + help(x - 2, y - 1))%(10e9+7)

print(help(X, Y))

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

a = (4*Y-2*X)//6
b = (Y-2*X)//-3
if a == 0 and b == 0:
    print(0)
    import sys
    sys.exit()

from math import factorial
print(factorial(a+b)//factorial(a)*factorial(b)%(10e9+7))


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

# dp = [[0 for _ in range(X+1)] for __ in range(Y+1)]
# dp[1][2] = 1
# dp[2][1] = 1

# for xi in range(X + 1):
#     for yi in range(Y + 1):
#         dp[xi][yi] = dp[xi - 1][yi - 2] + dp[xi - 2][yi - 1]

# print(dp[X][Y])

def help(x, y):
    if x < 0 or y < 0:
        return 0
    if (x == 1 and y == 2) or (x == 2 and y == 1):
        return 1
    else:
        return (help(x - 1, y - 2) + help(x - 2, y - 1))%(10e9+7)

print(help(X, Y))

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

MD = pow(10, 9) + 7

def choose(n, a):
    x, y = 1, 1
    for i in range(a):
        x = x * (n - i) % MD
        y = y * (i + 1) % MD
    return x * pow(y, MD - 2, MD) % MD


a = (2*Y-X)//3
b = (Y-2*X)//-3

if a < 0 or b < 0 or (X+Y) % 3 != 0:
    print(0)
    import sys
    sys.exit()

print(choose(a+b, min(a,b)))

Verdicts: Runtime Error

Runtime Error

Runtime Error

Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):

import math
import numpy as np
X, Y = list(map(int, input().split()))

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


a = np.array([[2, 1], [1, 2]])
b = np.array([X, Y])

res = np.linalg.solve(a, b)
n = int(res[0])
m = int(res[1])
print(n, m)

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

MOD = 10 ** 9 + 7
result = math.factorial(n + m) // (math.factorial(n) * math.factorial(m)) % MOD
print(result)



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

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


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

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


def comb(n, k):
    c = 1
    for i in range(k):
        c *= n - i
        c %= MOD
    d = 1
    for i in range(1, k + 1):
        d *= i
        d %= MOD
    return (c * pow(d, MOD - 2, MOD)) % MOD

MOD = 10 ** 9 + 7
result = comb(n+m, n)
print(result)


Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
import math
x,y=map(int,input().split())
if (2*y-x)%3==0 and (2*x-y)%3==0:
    a=(2*y-x)/3
    b=(2*x-y)/3
    ans=math.factorial(a+b)//math.factorial(a)//math.factorial(b)
    print(ans%(10**9+7))
else:
    print('0')

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

x,y=map(int,input().split())
if (2*y-x)%3==0 and (2*x-y)%3==0 and  (2*y-x)/3>=0 and (2*x-y)/3>=0 :
    a=(2*y-x)//3
    b=(2*x-y)//3
    ans=cmb(a+b,a)
    print(ans%(10**9+7))
else:
    print('0')

Verdicts: Runtime Error

Accepted
Problem: 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.

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

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

Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
import itertools
X, Y=map(int, input().split())  
MOD = 10**9 + 7
if (X+Y)%3 != 0:
    print(0)
else:

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

    # print(f"n:{n}, m:{m}")

    if n<0 or m<0:
        print(0)
    else:
        for i in range(m):
            ret = ret * (n - i) % MOD * pow(i + 1, MOD-2, MOD) % MOD
        print(ret)

import itertools
X, Y=map(int, input().split())  
MOD = 10**9 + 7
from math import factorial
# a = factorial(n+m) / factorial(n) / factorial(m)

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

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

    # print(f"n:{n}, m:{m}")

    if n<0 or m<0:
        print(0)
    else:
        
        
        
        a = factorial(n+m) / factorial(n) / factorial(m)
        print(a%MOD)

import itertools
X, Y=map(int, input().split())  
MOD = 10**9 + 7
if (X+Y)%3 != 0:
    print(0)
else:

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

    # print(f"n:{n}, m:{m}")

    if n<0 or m<0:
        print(0)
    else:
        ret = 1
        for i in range(m):
            ret = ret * ((X+Y) - i) % MOD * pow(i + 1, MOD-2, MOD) % MOD
        print(ret)

import itertools
X, Y=map(int, input().split())  
MOD = 10**9 + 7
if (X+Y)%3 != 0:
    print(0)
else:

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

    # print(f"n:{n}, m:{m}")

    if n<0 or m<0:
        print(0)
    else:
        ret = 1
        for i in range(m):
            ret = ret * ((X+Y)//3 - i) % MOD * pow(i + 1, MOD-2, MOD) % MOD
        print(ret)

Verdicts: Runtime Error

Runtime Error

Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
X,Y=map(int,input().split())
MOD=10**9+7

def modinv(a):
    return pow(a,MOD-2,MOD)

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

if x%3!=0 or y%3!=0 or x<0 or y<0:
	print(0)
else:
	r=1
	n=x+y
	k=min(x,y)
	for i in range(k):
		r*=(n-i)
		r*=modinv(i+1)
		r%=MOD
	print(r)


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

def modinv(a):
	return pow(a,MOD-2,MOD)

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

if (2*Y-X)%3!=0 or (2*X-Y)%3!=0 or x<0 or y<0:
	print(0)
else:
	r=1
	n=x+y
	k=min(x,y)
	for i in range(k):
		r*=(n-i)
		r*=modinv(i+1)
		r%=MOD
	print(r)


Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
import sys
import numpy as np
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N, T = map(int, readline().split())
m = map(int, read().split())
AB = sorted(zip(m, m))

dp = np.zeros(T, np.int64)

ans = 0
table = np.zeros(T, int)
for a, b in AB:
    ans = max(ans, max(table) + b)
    np.maximum(table[:-a] + b, table[a:], out=table[a:])
print(ans)


import sys
import numpy as np
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

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

MOD = 10**9 + 7


def cumprod(arr, MOD):
    L = len(arr)
    Lsq = int(L**.5 + 1)
    arr = np.resize(arr, Lsq**2).reshape(Lsq, Lsq)
    for n in range(1, Lsq):
        arr[:, n] *= arr[:, n - 1]
        arr[:, n] %= MOD
    for n in range(1, Lsq):
        arr[n] *= arr[n - 1, -1]
        arr[n] %= MOD
    return arr.ravel()[:L]


def make_fact(U, MOD):
    x = np.arange(U, dtype=np.int64)
    x[0] = 1
    fact = cumprod(x, MOD)
    x = np.arange(U, 0, -1, dtype=np.int64)
    x[0] = pow(int(fact[-1]), MOD - 2, MOD)
    fact_inv = cumprod(x, MOD)[::-1]
    return fact, fact_inv


U = 10**6
fact, fact_inv = make_fact(U, MOD)

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

a = (2 * x - y) // 3
b = (2 * y - x) // 3
if a < 0 or b < 0:
    print(0)
    exit()

answer = fact[a + b] * fact_inv[a] % MOD * fact_inv[b] % MOD
print(answer)


Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
def inv(a,p):
    if a==1:
        return 1
    elif a==0:
        return 0
    return p-(inv(p%a,p)*(p//a))%p
x,y=map(int,input().split())
if (x+y)%3!=0:
    print("0")
    exit()
if y/x>2 or y/x<0.5:
    print("0")
    exit()
n=(x+y)//3
r=(2*x-y)//3
p=10**9+7
def fact(n,p):
    a=[[] for _ in range(n+1)]
    a[0]=1
    for i in range(n):
        a[i+1]=(a[i]*(i+1))%p
    return a
c=f[-1]
d=f[r]
e=f[n-r]
dd=inv(d,p)
ee=inv(e,p)
ans=(c*dd*ee)%p
print(ans)

def inv(a,p):
    if a==1:
        return 1
    elif a==0:
        return 0
    return p-(inv(p%a,p)*(p//a))%p
x,y=map(int,input().split())
if (x+y)%3!=0:
    print("0")
    exit()
n=(x+y)//3
r=(2*x-y)//3
p=10**9+7
def fact(n,p):
    a=[[] for _ in range(n+1)]
    a[0]=1
    for i in range(n):
        a[i+1]=(a[i]*(i+1))%p
    return a
f=fact(n,p)
if len(f)>=r:
    print("0")
    exit()
c=f[-1]
d=f[r]
e=f[n-r]
dd=inv(d,p)
ee=inv(e,p)
ans=(c*dd*ee)%p
print(ans)

def inv(a,p):
    if a==1:
        return 1
    elif a==0:
        return 0
    return p-(inv(p%a,p)*(p//a))%p
x,y=map(int,input().split())
if (x+y)%3!=0:
    print("0")
    exit()
if x==0 and y>0:
    print("0")
    exit()
if y/x>2 or y/x<0.5:
    print("0")
    exit()
n=(x+y)//3
r=(2*x-y)//3
p=10**9+7
def fact(n,p):
    a=[[] for _ in range(n+1)]
    a[0]=1
    for i in range(n):
        a[i+1]=(a[i]*(i+1))%p
    return a
f=fact(n,p)
c=f[-1]
d=f[r]
e=f[n-r]
dd=inv(d,p)
ee=inv(e,p)
ans=(c*dd*ee)%p
print(ans)

Verdicts: Runtime Error

Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
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


X, Y = (int(i) for i in input().split())

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

if(  n < 0 or m < 0  ):
    print(0)
else:
    print(cmb(i+j, i) % 1000000007)


import math


X, Y = (int(i) for i in input().split())

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

if(  ((2*X-Y)%3)!=0 or (2*Y-X)%3!=0  ):
    print(0)
else:
    print(math.factorial(i+j)/math.factorial(i)/math.factorial(j))

import math


X, Y = (int(i) for i in input().split())

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

if(  ((2*X+Y)%3)!=0 or (2*Y-X)%3!=0  ):
    print(0)
else:
    print(math.factorial(i+j)/math.factorial(i)/math.factorial(j))

import math


X, Y = (int(i) for i in input().split())

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

if(  ((2*X-Y)%3)!=0 or (2*Y-X)%3!=0  ):
    print(0)
else:
    print( (math.factorial(i+j)/math.factorial(i)/math.factorial(j) ) % 1000000007 )

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


X, Y = (int(i) for i in input().split())

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

if(  i < 0 or j < 0 or (2*X-Y)%3!=0 or (2*Y-X)%3!=0 ):
    print(0)
else:
    print(cmb(i+j, i) % 1000000007)


Verdicts: Runtime Error

Runtime Error

Wrong Answer

Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
from scipy.misc import comb
x, y = map(int, input().split())
if (x + y) % 3 != 0:
    print(0)
    exit()
a, b = y - (x + y) // 3, x - (x + y) // 3
print(comb(a + b, a))

mod = 10 ** 9 + 7
x, y = map(int, input().split())
if (x + y) % 3 != 0 or x * 2 < y or y * 2 < x:
    print(0)
    exit()
l = [1]
for i in range(1, (x + y) // 3 + 100):
    l.append(l[-1] * i % mod)
def comb(n, r, m):
    return l[n] * pow(l[r], m - 2, m) * pow(l[n - r], m - 2, m) % m
a, b = y - (x + y) // 3, x - (x + y) // 3
print(comb(a + b, a, mod) % mod)

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
from math import factorial

x, y = map(int, input().split())
if y > x:
  x, y = y, x

a = (x+y)/3
b = (2*y-x)/3
if (x+y)%3 == 0 and (2*y-x)%3 == 0 and a*b >= 0:
  answer = factorial(a) // factorial(b) // factorial(a - b)
  print(answer % (10**9+7))
else:
  print(0)

x, y = map(int, input().split())
if y > x:
  x, y = y, x

def cmb(n, r, p):
  if (r < 0) or (n < r):
    return 0
  r = min(r, n - r)
  return fact[n] * factinv[r] * factinv[n-r] % p

p = 10 ** 9 + 7
N = 10 ** 6
fact = [1, 1]
factinv = [1, 1]
inv = [0, 1]
 
for i in range(2, N + 1):
    fact.append((fact[-1] * i) % p)
    inv.append((-inv[p % i] * (p // i)) % p)
    factinv.append((factinv[-1] * inv[-1]) % p)

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


Verdicts: Time Limit Exceeded

Accepted
Problem: 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.

Submission attempts (in order):
from math import factorial as fac
x,y=map(int,input().split())
a=2/3*y-1/3*x
b=1/3*(2*x-y)
mod=10**9+7
if a>=0 and b>=0 and a==int(a) and b==int(b):
  ue=fac(a+b)%mod
  sita1=pow(fac(a),mod-2,mod)
  sita2=pow(fac(b),mod-2,mod)
  print((ue*sita1*sita2)%mod)
else:
  print(0)

from math import factorial as fac
x,y=map(int,input().split())
a=(2*y-x)/3
b=(2*x-y)/3
mod=10**9+7
if a>=0 and b>=0 and a==int(a) and b==int(b):
  a=int(a)
  b=int(b)
  a1=1
  a2=1  
  n3=10**9+7
  for i in range(a):
    a1*=a+b-i
    a2*=i+1
    a1%=n3
    a2%=n3
  a2=pow(a2,n3-2,n3)
  print((a1*a2)%n3)
else:
  print(0)

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
x, y = list(map(int, input().split(' ')))

mmm = 1000000000 + 7
sss = x + y
if sss % 3 != 0:
    print(0)
    exit()
hoge = sss // 3






p =  y - hoge
q = x - hoge

if p < 0 or q < 0:  
    return 0


fac = []
inv = []
inv_fac = []
def init(n):
    fac.append(1)
    fac.append(1)
    inv.append(0)
    inv.append(1)
    inv_fac.append(1)
    inv_fac.append(1)
    for i in range(2, n):
        fac.append(fac[-1] * i % mmm)
        inv.append(mmm - inv[mmm%i] * (mmm // i) % mmm)
        inv_fac.append(inv_fac[-1] * inv[-1] % mmm)

def choice(a, b):
    if a < b:
        return 0
    return fac[a] * (inv_fac[b] * inv_fac[a-b] % mmm) % mmm

init(hoge * 2 + 1)
print(choice(hoge, p) % mmm)



#     if a == b or b == 0:
#         return 0
#     if a < b:
#         return choice(b, a)
#     bunshi = a
#     t = min(b, (a-b))


#         bunshi *= (a-i) % mmm

#     return bunshi // bunbo


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

mmm = 1000000000 + 7
sss = x + y
if sss % 3 != 0:
    print(0)
    exit()
hoge = sss // 3






p =  y - hoge
q = x - hoge

if p < 0 or q < 0:  
    print(0)
    exit()


fac = []
inv = []
inv_fac = []
def init(n):
    fac.append(1)
    fac.append(1)
    inv.append(0)
    inv.append(1)
    inv_fac.append(1)
    inv_fac.append(1)
    for i in range(2, n):
        fac.append(fac[-1] * i % mmm)
        inv.append(mmm - inv[mmm%i] * (mmm // i) % mmm)
        inv_fac.append(inv_fac[-1] * inv[-1] % mmm)

def choice(a, b):
    if a < b:
        return 0
    return fac[a] * (inv_fac[b] * inv_fac[a-b] % mmm) % mmm

init(hoge * 2 + 1)
print(choice(hoge, p) % mmm)



#     if a == b or b == 0:
#         return 0
#     if a < b:
#         return choice(b, a)
#     bunshi = a
#     t = min(b, (a-b))


#         bunshi *= (a-i) % mmm

#     return bunshi // bunbo


Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
#coding: utf-8
import math
import heapq

MOD = 10**9+7

def modinv(a, mod):
    b, u, v = mod, 1, 0
    while(b):
        t = a // b
        a -= t * b
        a, b = b, a
        u -= t * v
        u, v = v, u
    u %= mod
    if u<0:
        u += mod
    
    return u


def combination(n, m):
    ans = 1

    for i in range(n, n-m, -1):
        ans=(ans*i)%MOD
    for i in range(2,m+1):
        ans=(ans*modinv(i,MOD))%MOD

    return ans


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

if (X+Y)%3!=0:
    print(0)
else:
    a = 2*X-Y
    b = 2*Y-X
    if a<0 or b<0:
        print(0)
    else:
        print(combination(a+b, a))


#coding: utf-8
import math
import heapq

MOD = 10**9+7

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


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

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


#coding: utf-8
import math
import heapq

MOD = 10**9+7

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


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

if (X+Y)%3!=0:
    print(0)
else:
    a = 2*X-Y
    b = 2*Y-X
    if a<0 or b<0:
        print(0)
    else:
        print(combination(a+b, a))


#coding: utf-8
import math
import heapq

MOD = 10**9+7

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


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

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


Verdicts: Wrong Answer

Runtime Error

Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
X, Y = map(int, input().split())
import math
a = 2*Y -X
b = 2*X -Y
if a % 3 == 0 and b % 3 == 0 and a > 0 and b > 0:
  k = a // 3
  l = b // 3
  c = max(k, l)
  d = min(k, l)
  sita = math.factorial(d)
  ue = 1
  for i in range(c + 1, c + d + 1):
    ue * = i
  total = ue // sita
  print(total % (7 + 10 ** 9))
else:
  print(0)


X, Y = map(int, input().split())
import math
mod = pow(10,9) + 7
a = 2*Y -X
b = 2*X -Y
if a % 3 == 0 and b % 3 == 0 and a >= 0 and b >= 0:
  k = a // 3
  l = b // 3
  c = max(k, l)
  d = min(k, l)
  bunshi = 1
  bunbo = 1
  for i in range(c+1,c+d+1):
    bunshi = bunshi * i % mod
  for i in range(1,d+1):
    bunbo = bunbo * i % mod
  ans = bunshi * pow(bunbo, mod-2, mod) % mod
  print(ans)
else:
  print(0)


Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
X, Y = map(int,input().split())
n = (2*Y-X)/3
m = (2*X-Y)/3
if isinstance(n, float) or isinstance(m, float):
  print(0)
  exit()
if n < 0 or m < 0:
  print(0)
  exit()
def modinv(a, mod=10**9+7):
    return pow(a, mod-2, mod)
def combination(n, r, mod=10**9+7):
    r = min(r, n-r)
    res = 1
    for i in range(r):
        res = res * (n - i) * modinv(i+1, mod) % mod
    return res
print(combination(int(n)+int(m), int(n)))

X, Y = map(int,input().split())
n = (2*Y-X)/3
m = (2*X-Y)/3
if n < 0 or m < 0:
  print(0)
  exit()
def modinv(a, mod=10**9+7):
    return pow(a, mod-2, mod)
def combination(n, r, mod=10**9+7):
    r = min(r, n-r)
    res = 1
    for i in range(int(r)):
        res = res * (n - i) * modinv(i+1, mod) % mod
    return res
print(combination(n+m, n))

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

X, Y = map(int,input().split())
n = int((2*Y-X)/3)
m = int((2*X-Y)/3)
if (X+Y)%3!=0:
  print(0)
  exit()
def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % p
p = 10 ** 9 + 7
N = 10 ** 6  
fact = [1, 1]
factinv = [1, 1]
inv = [0, 1]
for i in range(2, N + 1):
    fact.append((fact[-1] * i) % p)
    inv.append((-inv[p % i] * (p // i)) % p)
    factinv.append((factinv[-1] * inv[-1]) % p)
print(cmb(n+m, n, p))

Verdicts: Wrong Answer

Wrong Answer

Runtime Error

Accepted