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):
X,Y = map(int,input().split())
 
c1 = (2*Y-X)
if (c1%3!=0)or(X-c1<0)or(Y-2*c1):
  print(0)

else:
 
  c1 = c1//3
  c2 = Y-2*c1
  c3 = c1+c2+1
  mod = 10**9+7
  c4 = min(c1,c2)
  x = 1
  y = 1
  for i in range(1,c4+1):
    x = x * (c3-i) % mod
    y = y * i % mod
    
  result = x * pow(y,mod-2,mod) % mod
 
  print(result)

import numpy as np
import math
X,Y = map(int,input().split())
 
 
c1 = (2*Y-X)
if c1%3!=0:
  print(0)
 
else:
  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
  
  c1 = c1//3
  c2 = Y-2*c1
  c3 = c1+c2+1
  mod = 10**9+7
  c4 = min(c1,c2)
  x = 1
  y = 1
  for i in range(1,c4+1):
    x = (x * (c3-i)) % mod
    y = (y * i) % mod
    
  result = 1
  for _ in range(mod-2):
    result = (result * y) % mod
    
  result = (result * x) % mod
 
  print(result)

print(0)

X,Y = map(int,input().split())
 
c1 = (2*Y-X)
if c1%3!=0:
  print(0)



X,Y = map(int,input().split())
 
c1 = (2*Y-X)
if (c1%3!=0)or(X-c1<0)or(Y-2*c1<0):
  print(0)

else:

  c1 = c1//3
  c2 = Y-2*c1
  c3 = c1+c2+1
  mod = 10**9+7
  c4 = min(c1,c2)
  x = 1
  y = 1
  for i in range(1,c4+1):
    x = x * (c3-i) % mod
    y = y * i % mod
    
  result = x * pow(y,mod-2,mod) % mod
 
  print(result)


X,Y = map(int,input().split())
 
c1 = (2*Y-X)
if (c1%3!=0)or((X-c1)<0)or((Y-2*c1)<0):
  print(0)

else:

  c1 = c1//3
  c2 = Y-2*c1
  c3 = c1+c2+1
  mod = 10**9+7
  c4 = min(c1,c2)
  x = 1
  y = 1
  for i in range(1,c4+1):
    x = x * (c3-i) % mod
    y = y * i % mod
    
  result = x * pow(y,mod-2,mod) % mod
 
  print(result)


X,Y = map(int,input().split())
 
c1 = (2*Y-X)
rest = c1%3
c1 = c1//3
if (rest!=0)or((X-c1)<0)or((Y-2*c1)<0)or(c1<0):
  print(0)

else:
  c2 = Y-2*c1
  c3 = c1+c2+1
  mod = 10**9+7
  c4 = min(c1,c2)
  x = 1
  y = 1
  for i in range(1,c4+1):
    x = x * (c3-i) % mod
    y = y * i % mod
    
  result = x * pow(y,mod-2,mod) % mod
 
  print(result)

Verdicts: Wrong Answer

Time Limit Exceeded

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

if Y > X:
    X, Y = Y, X

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

n = 0
m = 0

for n in range(X + 1):
    if (X - n) % 2 != 0:
        continue
    else:
        m = (X - n) // 2
        if 2 * n + m == Y:
            break

if m > n:
    n, m = m, n

print(n, m)

p = 1
q = 1
mod = 10 ** 9 + 7

for i in range(m):
    p *= (n + m - i)
    p %= mod
    q *= (m - i)
    q %= mod

ans = p * pow(q, mod - 2, mod)

print(ans % mod)


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

if Y > X:
    X, Y = Y, X

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

n = 0
m = 0

for n in range(X + 1):
    if (X - n) % 2 != 0:
        continue
    else:
        m = (X - n) // 2
        if 2 * n + m == Y:
            break

if m > n:
    n, m = m, n

# print(n, m)

p = 1
q = 1
mod = 10 ** 9 + 7

for i in range(m):
    p *= (n + m - i)
    p %= mod
    q *= (m - i)
    q %= mod

ans = p * pow(q, mod - 2, mod)

print(ans % 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):
mod = 10 ** 9 + 7
x, y = map(int, input().split())
a = (2 * y - x) // 3
b = (2 * x - y) // 3
if (x + y) % 3 != 0 or a < 0 or b < 0:
    print(0)
    exit()
n = a + b
r = min(a, b)
lim = 10 ** 6
g1 = [1, 1]
g2 = [1, 1]
inv = [0, 1]
for i in range(2, lim + 1):
    g1.append((g1[-1] * i) % mod)  
    inv.append((inv[mod % i] * (mod // i)) % mod)  
    g2.append((g2[-1] * inv[-1]) % mod)  計算用テーブル


def comb(n, r, mod):
    if r < 0 or r > n:
        return 0
    else:
        return g1[n] * g2[r] * g2[n - r] % mod


ans = comb(n, r, mod)
print(ans)

def factorial(n, r, p):
    ret = 1
    for i in range(n, n - r, -1):
        ret = (ret * i) % p
    return ret


def comb(n, r, p):
    r = min(r, n - r)
    return (factorial(n, r, p) * pow(factorial(r, r, p), p - 2, p)) % p


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


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 = 10**9+7

mx = 10**6
fact = [1]*(mx+1)
for i in range(mx):
  fact[i+1] = fact[i]*(i+1)%mod
def inv(n):
  return pow(n,mod-2,mod)
if (x%3==0 and y%3==0) or (x%3==1 and y%3==2) or (x%3==2 and y%3==1):
  n = int(2*x/3-y/3)
  m = int(-x/3 + 2*y/3)
  s += fact[n+m]*inv(fact[n])*inv(fact[m])%mod
  print(s)
else:
  print(0)
 

x,y = map(int,input().split())
mod = 10**9+7
if 2*x-y%3!=0 and 2*y-x!=0:
  print(0)
  exit()
n = (2*x-y)//3
m = (2*y-x)//3
#n+mCm
if n==0 or m==0:
  print(1)
  exit()
def ka(x):
  a = 1
  while x!=1:
    a *= x
    x -= 1
    a%= mod
  return a

ans = (ka(n+m)*pow(ka(m),mod-2,mod)*pow(ka(n),mod-2,mod))%mod
print(ans)

x,y = map(int,input().split())
mod = 10**9+7
if (x+y)%3!=0:
  print(0)
  exit()
if 2*min(x,y)<max(x,y):
  print(0)
  exit()
n = (2*x-y)//3
m = (2*y-x)//3
#n+mCm
if n==0 or m==0:
  print(1)
  exit()
def ka(x):
  a = 1
  while x!=1:
    a *= x
    x -= 1
    a%= mod
  return a

ans = (ka(n+m)*pow(ka(m),mod-2,mod)%mod)*(pow(ka(n),mod-2,mod))%mod
print(ans)

Verdicts: 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):
import math
N,Y= [int(i) for i in input().split()]
a=N+Y
if a%3 != 0:print(0)
else:
    b=a/3
    print(int((math.factorial(b)/math.factorial(abs(N-Y)))%(10**9+7)))

def egcd(a, b):
    (x, lastx) = (0, 1)
    (y, lasty) = (1, 0)
    while b != 0:
        q = a // b
        (a, b) = (b, a % b)
        (x, lastx) = (lastx - q * x, x)
        (y, lasty) = (lasty - q * y, y)
    return (lastx, lasty, a)



def modinv(a, m):
    (inv, q, gcd_val) = egcd(a, m)
    
    return inv % m

def m(n,r):
    d=1
    e=1
    f=1
    for i in range(r):
        d=(n-i)
        e=(i+1)
        d%=(10**9+7)
        f = f*d*modinv(e,(10**9+7))%(10**9+7)
        
    return(f)

n=[int(i) for i in input().split()]
a=sum(n)
if a%3 != 0:print(0)

else:
    b=int(a/3)
    if b==1:
        print(1)
    else:
        c=n[0]-b
        d=n[1]-b
        if c<0 or d<0: print(0)

        else:
            if c==d:
                c=int(b/2)
            #d=m(b,min(c,d))
            print(m(b,min(c,d)))

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

import math
X, Y = map(int, input().split())
p = (((X+Y)/3)+Y-X)/2
m = p+X-Y


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

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

def comb(n, k, mod):
    a=framod(n, mod)
    b=framod(k, mod)
    c=framod(n-k, mod)
    return (a * power(b, mod-2, mod) * power(c, mod-2, mod)) % mod


if p % 1 != 0 or p<0 or m<0:
    ans = 0

else:
    q = p+m
    q = int(q)
    p = int(p)
    ans = comb(q,p,10**9+7)
  

print(ans)

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):
from sympy import Symbol, solve
x = Symbol('x')
y = Symbol('y')

tmp1 = 2*x + 3*y - 6
tmp2 = 3*x + 2*y - 12

ans = solve((tmp1, tmp2))
print(ans[x])
print(x)

MOD = 10 ** 9 + 7
MAX = 10 ** 6 + 1
fac = [0] * MAX
finv = [0] * MAX
inv = [0] * MAX

def CoMinit():
    fac[0] = fac[1] = 1
    finv[0] = 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 < k:
       return 0
   if n < 0 or k < 0:
       return 0

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

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

if (X + Y) % 3:
    print(0)
    exit()
n = (X + Y) // 3
X -= n
Y -= n
if X < 0 or Y < 0:
    print(0)
    exit()
CoMinit()
ans = COM(X + Y, X)
print(ans)

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

X , Y =map(int,input().split())
X1=X
Y1=Y
x=0
y=0
if(X>Y):
    x=X-Y
    X1-=2*x
    Y1-=x
else:
    y=Y-X
    X1-=y
    Y1-=2*y
if(X1<0 or Y1<0 or X1%3!=0 or Y1%3!=0):
    print(0)
x+=X1//3
y+=X1//3


print((math.factorial(x+y)//(math.factorial(x)*math.factorial(y)))//((10**9)+7))

import math

X , Y =map(int,input().split())
X1=X
Y1=Y
x=0
y=0
if(X>Y):
    x=X-Y
    X1-=2*x
    Y1-=x
else:
    y=Y-X
    X1-=y
    Y1-=2*y
if(X1<0 or Y1<0 or X1%3!=0 or Y1%3!=0):
    print(0)
x+=X1//3
y+=X1//3


print((math.factorial(x+y)//(math.factorial(x)+math.factorial(y)))//((10**9)+7))

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

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

mod = 10**9+7 
g1 = [1]*(x+y) 
g2 = [1]*(x+y) 
inverse = [1]*(x+y)
inverse[0] = 1

if (x+y)%3 != 0 :
  print(0)
else:
  n = (x + y) // 3
  if x >= n and y >= n:
    a = x - n
    b = y - n
    
    for i in range(2, n + 1):
      g1[i]=( g1[i-1] * i ) % mod 
      inverse[i]=( -inverse[mod % i] * (mod//i) ) % mod 
      g2[i]=(g2[i-1] * inverse[i]) % mod
    
    answer = cmb(a+b,a,mod)
    print(answer)
  else:
    print(0)


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):
from scipy.misc import comb

x, y = map(int, input().split())
s, l = min(x,y), max(x,y)
if 2*s-l<0 or (2*s-l)%3!=0:
  print(0)
else:
  r = (2*s-l)//3
  n = 2*r+l-s
  print(comb(n,r,exact=True)%1000000007)

import sys

x, y = map(int, input().split())
s, l = min(x,y), max(x,y)

if 2*s-l<0 or (2*s-l)%3!=0:
    print(0)
    sys.exit()

r = (2*s-l)//3
n = (s+l)//3
mod = 10**9+7
g1 = [1, 1]
g2 = [1, 1]
inv = [0, 1]
for i in range(2, n+1):
    g1.append((g1[-1] * i) % mod)
    inv.append((-inv[mod%i] * (mod//i)) % mod)
    g2.append((g2[-1] * inv[-1]) % mod)

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

print(comb(n, 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):
X, Y = map(int, input().split())
MOD = 10 ** 9 + 7


S = -X + 2 * Y
T = 2 * X - Y

if S < 0 or T < 0:
    print(0)
    exit()
if S % 3 != 0 or T % 3 != 0:
    print(0)
    exit()

S //= 3
T //= 3


def cmb(n, r, p):
    r = min(n - r, r)
    if r == 0:
        return 1
    over = 1
    for i in range(n, n - r, -1):
        over = over * i % p
    under = 1
    for i in range(1, r + 1):
        under = under * i % p
    inv = pow(under, p - 2, p)
    return over * inv % p


print(S, T)
ans = cmb(S + T, S, MOD) % MOD
print(ans % MOD)


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


S = -X + 2 * Y
T = 2 * X - Y

if S < 0 or T < 0:
    print(0)
    exit()
if S % 3 != 0 or T % 3 != 0:
    print(0)
    exit()

S //= 3
T //= 3


def cmb(n, r, p):
    r = min(n - r, r)
    if r == 0:
        return 1
    over = 1
    for i in range(n, n - r, -1):
        over = over * i % p
    under = 1
    for i in range(1, r + 1):
        under = under * i % p
    inv = pow(under, p - 2, p)
    return over * inv % p


# print(S, T)
ans = cmb(S + T, S, MOD) % MOD
print(ans % 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):

import numpy as np
i8 = np.int64
MOD = 1000000007

def mod_inv(mod, a):

    old_s, s = 1, 0
    old_t, t = 0, 1
    old_r, r = mod, a

    while r != 0:
        quotient = old_r // r

        old_r, r = r, old_r - quotient * r
        old_s, s = s, old_s - quotient * s
        old_t, t = t, old_t - quotient * t

    return old_t % mod


def get_fac(fac):
    fac[1] = 1
    for i in range(2, fac.shape[0]):
        fac[i] = fac[i - 1] * i % MOD


def combine(m, n, fac):
    return fac[m] * mod_inv(MOD, (fac[m - n] * fac[n]) % MOD) % MOD


def main(in_file):
    stdin = open(in_file)
    X, Y = [int(x) for x in stdin.readline().split()]
    m1 = X + Y
    fac = np.empty(670000, i8)
    get_fac(fac)
    if m1 % 3 == 0:
        m = m1 // 3
        if X < m or Y < m:
            print(0)
        else:
            print(combine(m, X - m, fac))
    else:
        print(0)


def main2():
    main('/dev/stdin')

MOD = 1000000007


def mod_inv(mod, a):
    old_t, t = 0, 1
    old_r, r = mod, a

    while r != 0:
        quotient = old_r // r

        old_r, r = r, old_r - quotient * r
        old_t, t = t, old_t - quotient * t

    return old_t % mod


def combine(n, k, mod):
    if k > n // 2:
        k = n - k
    u = 1
    for i in range(n - k + 1, n + 1):
        u = u * i % mod

    v = 1
    for i in range(1, k + 1):
        v = v * i % mod

    return u * mod_inv(mod, v) % MOD


def main():
    X, Y = map(int, input().split())
    m1 = X + Y
    if m1 % 3 == 0:
        m = m1 // 3
        if X < m or Y < m:
            print(0)
        else:
            print(combine(m, X - m, MOD))
    else:
        print(0)


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):
from operator import mul
from functools import reduce

mod = 10**9+7

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 % mod


d = list(map(int, input().split()))
if (2*d[1] - d[0]) % 3 != 0:
	print(0)
	exit()

a = (2*d[1] - d[0]) // 3
b = d[1] - 2 * d[0]
print(combinations_count(a+b, a) % mod)

from operator import mul
from functools import reduce

mod = 10**9+7

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


x, y = map(int, input().split())
if (2*y - x) % 3 != 0:
	print(0)
	exit()

if (x+y) % 3 != 0 or not (x <= 2*y and y <= 2*x):
    print(0)
    exit()

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

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 numpy as np

def combination(n, a):
    mod = pow(10, 9)+7
    x = 1
    y = 1
    for i in range(a):
        x = x * (n-i)%mod
        y = y * (a-i)%mod
    return x * pow(y, mod-2, mod)%mod

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

if (x + y)%3 != 0:
    print(0)
else:
    A = np.matrix([
        [2, 1],
        [1, 2]
        ])
    B = np.matrix([
        [x],
        [y]
        ])
    
    ans1 = np.linalg.solve(A,B)
    n, m = int(ans1[0])//3, int(ans1[1])//3
    ans2 = combination(n+m, n)
    print(ans2)


def combination(n, a):
    mod = pow(10, 9)+7
    x, y = 1, 1
    for i in range(a):
        x = x * (n-i)%mod
        y = y * (a-i)%mod
    return x * pow(y, mod-2, mod)%mod

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


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())
a = ((x+y)//3 + (x-y))//2
b = ((x+y)//3 - (x-y))//2

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

print(a)
print(b)
if a!=0 and b!=0:
    print(cmb(a+b,min(a,b))%(10**9+7))
else:
    print(0)

x, y = map(int, input().split())
a = ((x+y)/3 + (x-y))/2
b = ((x+y)/3 - (x-y))/2

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

if a.is_integer() and a>=0 and b>=0:
    print(cmb(int(a+b),int(a))%((10**9)+7))
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):
from math import factorial
X, Y = map(int,input().split())
if (X+Y)%3!=0:
    print(0)
else:
    itr=(X+Y)//3
    x_mx=itr*2
    flag=0
    ir=-1
    for i in range(itr,x_mx+1,1):
        ir+=1
        if X==i and Y==x_mx-ir:
            flag=1
            break
    print(flag)
    if flag==1:
        g=factorial(itr)/factorial(ir) / factorial(itr-ir)
        print(int(g%(10**9+7)))
    elif flag==0:
        print(0)

X, Y = map(int,input().split())
# https://qiita.com/derodero24/items/
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

if (X+Y)%3!=0:
    print(0)
else:
    itr=(X+Y)//3
    x_mx=itr*2
    if itr<=X and X<=x_mx and itr<=Y and Y<=x_mx and X+Y==itr+x_mx:
        c=X-itr
        f=cmb(itr, c)
        f=f%(10**9+7)
        print(f)
    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):

def acinput():
    return list(map(int, input().split(" ")))


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])
            #print(result)
            result%=(10**9+7)

    return result


X,Y=acinput()

import numpy as np
from numpy.linalg import solve
 

x=solve([[1,2],[2,1]],[X,Y])

#print(x)

if np.all(x%1.0==0) and np.all(x>=0):
    print(cmb(int(np.sum(x)),int(np.min(x)),10**9+7))

else:
    print(0)




def acinput():
    return list(map(int, input().split(" ")))


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])
            #print(result)
            result%=(10**9+7)

    return result


X,Y=acinput()

import numpy as np
from numpy.linalg import solve
 

x=solve([[1,2],[2,1]],[X,Y])

#print(x)

if np.all(x%1.0==0) and np.all(x>=0):
    print(cmb(int(np.sum(x)),int(np.min(x))))
    #print(cmb(int(np.sum(x)),int(np.min(x)),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):
def combination(n, r, mod=10**9+7):
    n1, r = n+1, min(r, n-r)
    numer = denom = 1
    for i in range(1, r+1):
        numer = numer * (n1-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 or not(X <= 2*Y and Y <= 2*X):
    print(0)
    exit()
else:
    s = (x+y)//3
 
t = min((x-s),(y-s))

print(combination(s,t))

def combination(n, r, mod=10**9+7):
    n1, r = n+1, min(r, n-r)
    numer = denom = 1
    for i in range(1, r+1):
        numer = numer * (n1-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 or not(x <= 2*y and y <= 2*x):
    print(0)
    exit()
else:
    s = (x+y)//3
 
t = min((x-s),(y-s))

print(combination(s,t))

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):
def C(n, r, m):
    num, den = 1, 1
    for i in range(1, r + 1):
        num = num * (n - i + 1) % m
        den = den * i % m
    return (num * pow(den, m - 2, m)) % m

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

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

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

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())
import math
def f2(r):

    return inv_t
def co(n,r):
    P = 10**9 + 7
    N = r+1
    inv_t = [0]+[1]
    for i in range(2,N+1):
        inv_t += [inv_t[P % i] * (P - int(P / i)) % P]
    ans =1
    for i in range(1,r+1):
        ans = (ans * (n+i-1)) % P
    for i in range(1,r+1):
        ans = (ans * inv_t[i]) % P
    return ans
if (X+Y)%3==0:
    Z=X+Y
    if min(X,Y)-Z//3 >-1:
        #print(1)
        comb = Combination(Z)
        print(comb(Z//3,min(X,Y)-Z//3))
        
    else:
        print(0)
else:
    print(0)

X,Y=map(int,input().split())
import math
def f2(r):

    return inv_t
def co(n,r):
    P = 10**9 + 7
    N = r+1
    inv_t = [0]+[1]
    for i in range(2,N+1):
        inv_t += [inv_t[P % i] * (P - int(P / i)) % P]
    ans =1
    for i in range(1,r+1):
        ans = (ans * (n+i-1)) % P
    for i in range(1,r+1):
        ans = (ans * inv_t[i]) % P
    return ans
if (X+Y)%3==0:
    Z=X+Y
    if min(X,Y)-Z//3 >-1:
        #print(1)
        comb = Combination(Z//3)
        print(comb(Z//3,min(X,Y)-Z//3))
        
    else:
        print(0)
else:
    print(0)

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

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

def f2(r):

    return inv_t
def co(n,r):
    P = 10**9 + 7
    N = r+1
    inv_t = [0]+[1]
    for i in range(2,N+1):
        inv_t += [inv_t[P % i] * (P - int(P / i)) % P]
    ans =1
    for i in range(1,r+1):
        ans = (ans * (n+i-1)) % P
    for i in range(1,r+1):
        ans = (ans * inv_t[i]) % P
    return ans
if (X+Y)%3==0:
    Z=X+Y
    if min(X,Y)-Z//3 >-1:
        #print(1)
        print(combination(Z//3,min(X,Y)-Z//3))
        
    else:
        print(0)
else:
    print(0)

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):
mod=10**9+7

x,y=map(int,input().split())
if (x+y)%3!=0:
  print(0)
  exit()
  
if x*2>y or y*2>x:
  print(0)
  exit()
  
z=(x+y)//3

x-=z
y-=z

n=x+y
r=x


lst=[0]+[1]
for i in range(2,n+10):
  lst.append((lst[-1]*i)%mod)


xxx=lst[n]
xxx*=pow(lst[n-r],10**9+5,mod)
xxx%=mod
xxx*=pow(lst[r],10**9+5,mod)
xxx%=mod

print(xxx)

mod=10**9+7

x,y=map(int,input().split())
if (x+y)%3!=0:
  print(0)
  exit()
  
if x*2<y or y*2<x:
  print(0)
  exit()
  
z=(x+y)//3

x-=z
y-=z

n=x+y
r=x

if x==0 or y==0:
  print(1)
  exit()
  

lst=[0]+[1]
for i in range(2,n+10):
  lst.append((lst[-1]*i)%mod)


xxx=lst[n]
xxx*=pow(lst[n-r],10**9+5,mod)
xxx%=mod
xxx*=pow(lst[r],10**9+5,mod)
xxx%=mod

print(xxx)

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

I=list(map(int,input().split()))
X=(2*I[1]-I[0])//3
Y=(2*I[0]-I[1])//3
n=X+Y
r=X

if ((X<0 or Y<0) or (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, r, p))

import math

I=list(map(int,input().split()))
X=(2*I[1]-I[0])//3
Y=(2*I[0]-I[1])//3
n=X+Y
r=X

if (X<0 or Y<0 or (I[0]+I[1])%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, r, p))

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())
def factorial(a,b):
    fact = 1
    for i in range(b):
        fact *= (a-i)
    return fact
    
if (x + y) %3 == 0:
    if (0< (2*y - x)//3) and (2*y - x)%3 == 0 and (0 < (2*x-y)//3) and (2*x-y)%3==0:
        n = int((2*y - x)//3)
        m = int((2*x-y)//3)
        print(n,m)
        ans = int(factorial((n+m),n) / factorial(n,n))
        print(ans%(10**9+7))
    else: 
        print("0")
    
else:
    print("0")

x,y = map(int, input().split())
mod = 10**9+7
a = (x + y) //3
n = (2*x-y)//3
m = a-n
print(n,m)
def nCr(n,r,mod):
    r = min(r, n-r)
    fact = rial=1
    for i in range(1,r+1):
        fact *= (n+1-i) % mod
        rial *= i %mod
    return fact * pow(rial,mod-2,mod) %mod
    
if (x + y) %3 == 0:
    if 0 < n and 0 < m and (x+y)%3==0:
       
        print(nCr(a,n,mod))
        
    else: 
        print(0)
    
else:
    print(0)

a = (x + y) //3
n = (2*x-y)//3
m = a-n
print(n,m)
def nCr(n,r,mod):
    r = min(r, n-r)
    fact = rial=1
    for i in range(1,r+1):
        fact *= (n+1-i) % mod
        rial *= i %mod
    return fact * pow(rial,mod-2,mod) %mod
    
if (x + y) %3 == 0:
    if 0 < n and 0 < m and (x+y)%3==0:
       
        print(nCr(a,n,mod))
        
    else: 
        print(0)
    
else:
    print(0)

def nCr(n,r,mod = 10**9+7):
    r = min(n-r,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 or not (x <= 2*y and y <= 2*x ):
    print(0)
    exit()
    
a = (x + y) //3
n = y - a

print(nCr(a,n))

Verdicts: Wrong Answer

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):
import numpy as np
from numpy import linalg as LA

N = int(input())
li = [[1,N]]

for i in range(2,int(np.sqrt(N))+1):
    if N%i == 0:
        li.append([i,N//i])

ans = 10**12
for i in li:
    x,y = i
    tmp = LA.norm([x-1,y-1],1)
    if ans > tmp:
        ans = tmp

print(ans)


X,Y = [int(zz) for zz in input().split()]

mod = 10**9+7
g1 = [1, 1]
g2 = [1, 1]
inverse = [0, 1]

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

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

if a != int(a):
    print(0)
    exit()

a = int(a)
b = int(b)
N = a+b

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

ans = cmb(N,a,mod)%(10**9+7)
print(int(ans))


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):
from math import factorial
pos = map(int, input().split())

x, y = sorted(pos)

num_twos = x // 2
rem = x % 2

solution = 0

max_n = 5*10**5

result = max_n*[None]
result[0] = 1
for i in range(1, max_n):
    result[i] = i*result[i-1]
m = 10**9 + 7 - 2


def ncr(n, r):
    return result[n] * result[r]**(m) * result[n-r]**(m)


while not (y == num_twos + (rem*2)):
    num_twos -= 1
    rem += 2

    if y < (num_twos + rem*2):
        print(0)
        exit()

solution = ncr(num_twos + rem, rem)

print(int(solution))


from math import factorial
pos = map(int, input().split())
p = 10**9 + 7
x, y = sorted(pos)

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

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

# Python3 function to
# calculate nCr % p


def ncr(n, r, p):
    # initialize numerator
    # and denominator
    num = den = 1
    for i in range(r):
        num = (num * (n - i)) % p
        den = (den * (i + 1)) % p
    return (num * pow(den,
                      p - 2, p)) % p


ans = ncr(n+m, n, p)
print(ans)


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):
x,y=map(int,input().split())
mod=10**9+7

def modinv(a, mod=10**9+7):
    return pow(a, mod-2, mod)
def mod_combinations_cont(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

if (x+y)%3!=0:
    print(0)
else:
    n=(x+y)//3
    m=(-x+2*y)/3
    if n<0 or m<0:
        print(0)
        exit()
    else:
        print(mod_combinations_cont(n,m,mod)%mod)


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

def modinv(a, mod=10**9+7):
    return pow(a, mod-2, mod)
def mod_combinations_count(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

if (x+y)%3!=0:
    print(0)
else:
    n=(x+y)//3
    m=(-x+2*y)//3
    if n<0 or m<0 or n<m:
        print(0)
        exit()
    else:
        print(mod_combinations_count(n,m,mod)%mod)


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())
a=-1
p=10**9+7
for i in range(x//2+1):
  if i+2*(x-2*i)==y:
    a=i
    break
if a==-1:
  print(0)
  exit()
elif a==0:
  print(1)
else:
  gyaku=[0,1]
  for i in range(2,a+1):
    gyaku.append(((p//i)*-gyaku[p%i])%p)
  com=[1]
  for i in range(1,a+1):
    com.append(com[-1]*gyaku[i]*(x-a+1-i)%p)
　　print(com[a])


x,y=map(int,input().split())
a=-1
p=10**9+7
for i in range(x//2+1):
  if i+2*(x-2*i)==y:
    a=i
    break
if a==-1:
  print(0)
  exit()
elif a==0:
  print(1)
else:
  gyaku=[0,1]
  for i in range(2,a+1):
    gyaku.append(((p//i)*-gyaku[p%i])%p)
  com=[1]
  for i in range(1,a+1):
    com.append(com[-1]*gyaku[i]*(x-a+1-i)%p)
  print(com[-1])  


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())
s=2*x-y
t=2*y-x
if s%3!=0 or s<0 or t%3!=0 or t<0:
  print(0)
else:
  import sys
  mod = 1000000007
  p = 1
  q = 1
  for i in range(s//3):
    p = (p*(n-i)) % mod
    q = (q*(i+1)) % mod
  print((p*pow(q, -1, mod)) % mod)

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

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())
def combination(n,r,mod=10**9+7):
    n1 = n+1
    r = min(r,n-r)
    numer = denom = 1
    for i in range(1,r+1):
        numer = numer * (n1-i) % mod
        denom = denom * i % mod
    return numer * pow(denom,mod-2,mod) % mod


if (X+Y) % 3 != 0 or not (X<=2*y and Y <=2*X):
    ans = 0
else:
    N = (X+Y)//3
    r = Y - N
    ans = combination(N,r)
print(ans)

X, Y = map(int,input().split())
DIV = 10**9 + 7
def combination(n,r,mod=DIV):
    n1 = n
    r = min(r,n-r)
    numer = denom = 1
    for i in range(1,r+1):
        numer = numer * (n1-i) % mod
        denom = denom * i % mod
    return numer * pow(denom,mod-2,mod) % mod


N = (X+Y)//3
ans = 0
if (X+Y) % 3 != 0:
    ans = 0
else:
    r = Y - N
    ans = combination(N,r)
print(ans)

X, Y = map(int,input().split())
def combination(n,r,mod=10**9+7):
    n1 = n+1
    r = min(r,n-r)
    numer = denom = 1
    for i in range(1,r+1):
        numer = numer * (n1-i) % mod
        denom = denom * i % mod
    return numer * pow(denom,mod-2,mod) % mod


if (X+Y) % 3 != 0 or not (X<=2*Y and Y <=2*X):
    ans = 0
else:
    N = (X+Y)//3
    r = Y - N
    ans = combination(N,r)
print(ans)

Verdicts: 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=list(map(int,input().split()))

import sys
if (2*Y-X)%3!=0 or (2*X-Y)%3!=0:
  print(0)
  sys.exit()
if (2*Y-X)%3<0 or (2*X-Y)<0:
  print(0)
  sys.exit()

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

fac=[0 for i in range(x+y+1)]
inv=[0 for i in range(x+y+1)]
finv=[0 for i in range(x+y+1)]

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

for i in range(2,x+y+1):
  fac[i]=fac[i-1]*i%p
  #p=(p//a)*a+(p%a) a^(-1)=-(p//a)*(p%a)^(-1)
  inv[i]=(-(p//i)*inv[p%i])%p
  finv[i]=finv[i-1]*inv[i]%p

print(x+y)
print(x)
print(y)

print((fac[x+y]*finv[x]%p)*finv[y]%p)




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

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

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

fac=[0 for i in range(x+y+1)]
inv=[0 for i in range(x+y+1)]
finv=[0 for i in range(x+y+1)]

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

for i in range(2,x+y+1):
  fac[i]=fac[i-1]*i%p
  #p=(p//a)*a+(p%a) a^(-1)=-(p//a)*(p%a)^(-1)
  inv[i]=(-(p//i)*inv[p%i])%p
  finv[i]=finv[i-1]*inv[i]%p

print(x+y)
print(x)
print(y)

print((fac[x+y]*finv[x]%p)*finv[y]%p)




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

import sys
if (2*Y-X)%3!=0 or (2*X-Y)%3!=0:
  print(0)
  sys.exit()
if 2*Y-X<0 or 2*X-Y<0:
  print(0)
  sys.exit()

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

fac=[0 for i in range(x+y+1)]
inv=[0 for i in range(x+y+1)]
finv=[0 for i in range(x+y+1)]

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

for i in range(2,x+y+1):
  fac[i]=fac[i-1]*i%p
  #p=(p//a)*a+(p%a) a^(-1)=-(p//a)*(p%a)^(-1)
  inv[i]=(-(p//i)*inv[p%i])%p
  finv[i]=finv[i-1]*inv[i]%p

print(x+y)
print(x)
print(y)

print((fac[x+y]*finv[x]%p)*finv[y]%p)








X,Y=list(map(int,input().split()))
import sys
if (2*Y-X)%3!=0 or (2*X-Y)%3!=0:
  print(0)
  sys.exit()
if (2*Y-X)<0 or (2*X-Y)<0:
  print(0)
  sys.exit()

  

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


fac=[0 for i in range(x+y+1)]
inv=[0 for i in range(x+y+1)]
finv=[0 for i in range(x+y+1)]

fac[0]=fac[1]=1
inv[1]=1
finv[0]=finv[1]=1
p=1000000007
for i in range(2,x+y+1):
  fac[i]=(fac[i-1]*i)%p
  
  inv[i]=(-(p//i)*inv[p%i])%p
  finv[i]=(finv[i-1]*inv[i])%p

print((fac[x+y]*finv[x]%p)*finv[y]%p)



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):
import numpy as np
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, invfact = make_fact(U,MOD)

MOD = 10**9 + 7
X, Y = [int(x) for x in input().split()]
if (X+Y) % 3 != 0:
    print(0)
    exit()
r = (X+Y) // 3
k = X - r
if (k < 0 or Y - r < 0):
    print(0)
else:
    print(fact[r] * invfact[r-k] % MOD * invfact[k] % MOD)


import numpy as np
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
MOD = 10**9 + 7
fact, invfact = make_fact(U,MOD)

X, Y = [int(x) for x in input().split()]
if (X+Y) % 3 != 0:
    print(0)
    exit()
r = (X+Y) // 3
k = X - r
if (k < 0 or Y - r < 0):
    print(0)
else:
    print(fact[r] * invfact[r-k] % MOD * invfact[k] % MOD)


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
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+y) % 3 != 0:
    print(0)
    exit()
A = np.matrix([[1,2],[2,1]])
Y = np.matrix([[x],[y]])
n,m = np.linalg.inv(A)*Y
n = int(n.tolist()[0][0])
m = int(m.tolist()[0][0])
if n < 0 or m < 0:
    print(0)
    exit()
print(cmb(n+m,n,mod))

from functools import reduce

def mycmb(n,r,p):
    r = min(r,n-r)
    if r == 0:
        return 1
    over = reduce(lambda x,y:x*y%p,range(n,n-r,-1))
    under = reduce(lambda x,y:x*y%p,range(1,r+1))
    return (over * pow(under,p-2,p))%p


mod = 10**9+7

x,y = map(int, input().split())
n = (2*x-y) // 3
m = (2*y-x) //3

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

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

print(mycmb(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):
import math
import numpy as np

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

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

b = np.array([x, y])
 
sol_auto = np.linalg.solve(A, b)


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

    print(int(k%1000000007))
else:
    print(0)

import math
import numpy as np

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+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

Accepted