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

def cmb(n, r):
    if n < r: return 0 #date added
    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 = result%MOD

    return result

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

print(a, b)

if a.is_integer() and b.is_integer() and a>=0 and b>=0:
    print(cmb(int(a+b), int(a)))
else:
    print(0)


MOD=10**9+7

def cmb(n, r):
    if n < r: return 0 #date added
    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 = result%MOD

    return result

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

#print(a, b)

if a.is_integer() and b.is_integer() and a>=0 and b>=0:
    print(cmb(int(a+b), int(a)))
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):
# ABC145 D







X,Y = imn()


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

M = (2*Y-X)//3
N = (-2*M)+Y


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


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

print(cmb(M+N, M))




import math
import fractions
import bisect
import collections
import itertools
import heapq
import string
import sys
import copy
from decimal import *
from collections import deque
sys.setrecursionlimit(10**7)
MOD = 10**9+7
INF = float('inf') 
def gcd(a,b):return fractions.gcd(a,b) 
def lcm(a,b):return (a*b) // fractions.gcd(a,b) 
def iin(): return int(sys.stdin.readline()) 
def ifn(): return float(sys.stdin.readline()) 
def isn(): return sys.stdin.readline().split() 
def imn(): return map(int, sys.stdin.readline().split()) 
def imnn(): return map(lambda x:int(x)-1, sys.stdin.readline().split()) 
def fmn(): return map(float, sys.stdin.readline().split()) 
def iln(): return list(map(int, sys.stdin.readline().split())) 
def iln_s(): return sorted(iln()) 
def iln_r(): return sorted(iln(), reverse=True) 
def fln(): return list(map(float, sys.stdin.readline().split())) 
def join(l, s=''): return s.join(l) 
def perm(l, n): return itertools.permutations(l, n) 
def perm_count(n, r): return math.factorial(n) // math.factorial(n-r) 
def comb(l, n): return itertools.combinations(l, n) 
def comb_count(n, r): return math.factorial(n) // (math.factorial(n-r) * math.factorial(r)) 
def two_distance(a, b, c, d): return ((c-a)**2 + (d-b)**2)**.5 
def m_add(a,b): return (a+b) % MOD
def lprint(l): print(*l, sep='\n')


X,Y = imn()


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

M = (2*Y-X)//3
N = (-2*M)+Y


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


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

print(cmb(M+N, M))



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
import itertools
import sys

x, y = [int(x) for x in input().split()]

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

total_move = (x+y) // 3
move_a = 2 * total_move - x

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 = total_move
g1 = [1, 1] 
g2 = [1, 1] 
inverse = [0, 1] 計算用テーブル

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

    a = cmb(total_move,move_a,mod)

print(a)

import sys
import math
from itertools import permutations
from itertools import combinations
#input = sys.stdin.readline
sys.setrecursionlimit(10**9)

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

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

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

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 = (n + m)
g1 = [1, 1]
g2 = [1, 1]
inverse = [0, 1]

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

a = cmb(n+m, m, mod)

print(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):
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())
s=(2*y-x)/3
t=(2*x-y)/3
if (2*y-x)%3!=0 or (2*x-y)%3!=0:
    print(0)
else:
    a = cmb(s+t, t)
    print(a%(10**9+7))

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())
s=int((2*y-x)/3)
t=int((2*x-y)/3)
if (2*y-x)%3!=0 or (2*x-y)%3!=0:
    print(0)
elif s<0 or t<0:
    print(0)
else:
    a = cmb(s+t, t)
    print(a%(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())
n = (x + y) / 3
l = 0
a = 1

if n % 1 != 0:
    a *= 0
else:
    for i in range(int(n)):
        if x != n - i:
            l += 1
            x -= 2
        else:
            x -= 1

for i in range(l):
    a *= (n - i)
    
ans = a % 1000000007
    
print(ans)

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

x, y = map(int, input().split())
n = (x + y) // 3
p = 10 ** 9 + 7
if (x + y) % 3 == 0 and max(x, y) <= 2 * min(x, y):
    r = 0
    if x > y:
        x, y = y, x
    a = (2 * x - y) // 3
    r = min(a, n - a)
    print(comb(n, r, p))
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):
import math

xy = list(map(int, input().split()))

if (2*xy[1]-xy[0]) % 3 == 0 and (2*xy[0]-xy[1]) % 3 == 0:
    a = (2*xy[1]-xy[0]) // 3
    b = (2*xy[0]-xy[1]) // 3
    ans = int(math.factorial(a+b)/(math.factorial(a)*math.factorial(b)))
    print(int(ans/(10**9 + 7)))
else:
    print(0)

import math
from operator import mul
from functools import reduce

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

if (2*xy[1]-xy[0]) % 3 == 0 and (2*xy[0]-xy[1]) % 3 == 0 and 2*xy[1]-xy[0] > -1 and 2*xy[0]-xy[1] > -1:
    a = (2*xy[1]-xy[0]) // 3
    b = (2*xy[0]-xy[1]) // 3
    print(cmb(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):
from operator import mul
from functools import reduce

def cmb(n,r):
  r = min(r, n-r)
  ans = 1
  for i in range(1,r+1):
    ans *= n
    n -= 1
    ans //= i
    ans %= (10**9+7)
  return ans

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

max_diff = min(X,Y)
if (X+Y) % 3 == 0:
  n = (X + Y) // 3
  k = max_diff - n
  print(n,k)
  ans = cmb(n, k)
else:
  ans = 0

print(ans)

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

max_diff = min(X,Y)
if (X+Y) % 3 == 0:
  n = (X + Y) // 3
  k = max_diff - n
  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 )
  ans = cmb(n,k,mod)
else:
  ans = 0

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):
import sys
input = lambda: sys.stdin.readline().rstrip() 

def resolve():
    X, Y = map(int, input().split())
    p = 10**9+7

    def combMod(n, r, p):
        numer = 1
        denom = 1
        for i in range(1, r+1):
            numer = numer * (n-r+i) % p
            denom = denom * i % p
        return numer * pow(denom, p-2, p) % p

    if (X+Y)%3==0 and Y<=X*2 and X<=Y*2:
        n = (X+Y)//3
        r = X-(X+Y)//3
        print(combMod(n, r, p))
    else:
        print('0')

import sys
input = lambda: sys.stdin.readline().rstrip() 

def resolve():
    X, Y = map(int, input().split())
    p = 10**9+7

    def combMod(n, r, p):
        numer = 1
        denom = 1
        for i in range(1, r+1):
            numer = numer * (n-r+i) % p
            denom = denom * i % p
        return numer * pow(denom, p-2, p) % p

    if (X+Y)%3==0 and Y<=X*2 and X<=Y*2:
        n = (X+Y)//3
        r = X-(X+Y)//3
        print(combMod(n, r, p))
    else:
        print('0')

if __name__ == '__main__':
    resolve()

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

fac = [0] * 700000
finv = [0] * 700000
inv = [0] * 700000
mod = 1000000007

def cominit():
    fac[0] = fac[1] = 0
    finv[0] = finv[1] = 0
    inv[1] = 0
    for i in range(2, 700000):
        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, r):
    if n < r:
        return
    if n < 0 or k < 0:
        return
    return fac[n] * (finv[r] * finv[n - r] % mod) % mod

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

if (2 * x - y) % 3 != 0 or (2 * y - x) % 3 != 0:
    print(0)
    sys.exit()

k = (2 * x - y) // 3
l = (2 * y - x) // 3

print(com(k + l, k))


import sys

fac = [0] * 700000
finv = [0] * 700000
inv = [0] * 700000
mod = 1000000007

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

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

if (2 * x - y) % 3 != 0 or (2 * y - x) % 3 != 0:
    print(0)
    sys.exit()

k = (2 * x - y) // 3
l = (2 * y - x) // 3

print(fac[k + l] * (finv[k] * finv[l] % mod) % mod)


mod = 10 ** 9 + 7
ans = 0

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

if (x + y) % 3 == 0:
    k = (2 * x - y) // 3
    l = (2 * y - x) // 3
    if k >= 0 and l >= 0:
        fac = [1] * (k + l + 1)
        for i in range(2, k + l + 1):
            fac[i] = fac[i - 1] * i % mod
        ans = fac[k + l] * (pow(fac[k], mod - 2, mod) * pow(fac[l], mod - 2, mod) % mod) % mod

print(ans)


Verdicts: 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):
import math
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
X, Y = map(int, input().split())
N = X + Y
C21 = 0
C12 = 0

ans = 0
if (N) % 3 != 0 or X >= 2*Y or Y >= 2*X:
  print(ans)
else:
  while N != 0:
    if X >= 666666 and Y >= 666666:
      C21 += 222222
      C12 += 222222
      X -= 333333
      Y -= 333333
      N -= 666666
    elif X >= Y:
      C21 += 1
      X -= 2
      Y -= 1
      N -= 3
    else:
      C12 += 1
      X -= 1
      Y -= 2
      N -= 3

  print('C12=', C12, 'C21=', C21) 
  print(combinations_count(C21 + C12, C21))

from numpy.linalg import solve
import numpy

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())
N = X + Y

left = [[1, 2], [2, 1]]
right = [X, Y]
s = solve(left, right)

if s[0] < 0 or s[1] < 0 or N % 3 != 0:
  print(0)
else:
  a = cmb(int(s[0]) + int(s[1]) , min(int(s[0]), int(s[1])))
  print(a % (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):
import math
X,Y=list(map(int,input().split()))
mod=10**9+7
def mul(a, b):
    return ((a % mod) * (b % mod)) % mod

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

def div(a, b):
    return mul(a, power(b, mod-2))
if X>Y:
    big=X
    small=Y
else:
    big=Y
    small=X


if (small+big)%3!=0:
    print(0)
    exit()
if small*2==big:
    print(small%mod)
    exit()
    
    
diff=big-small
big-=diff*2
small-=diff
if big<0 or big!=small:
    print(0)
    exit()

num=big//3
tmp=1
for i in range(num*2+diff):
    tmp*=(i+1)
    tmp%=mod
bunsi=tmp

bunbo=1
tmp=1
for i in range(num):
    tmp*=(i+1)
    #tmp%=mod
bunbo*=tmp
tmp=1
for i in range(num+diff):
    tmp*=(i+1)
    #tmp%=mod
bunbo*=tmp
#ans=div(bunsi,bunbo)
ans=bunsi/bunbo
print(ans%mod)

import math
X,Y=list(map(int,input().split()))
mod=10**9+7




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


tmp=1
for i in range(n,n+m):
    tmp=(tmp*(i+1))%mod
bunsi=tmp
bunbo=1
tmp=1
for i in range(m):
    tmp=(tmp*(i+1))%mod
bunbo=pow(tmp,mod-2,mod)
#ans=div(bunsi,bunbo)
ans=bunsi*bunbo
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):
def power_func(a,b,p):
  
  if b==0: return 1
  if b%2==0:
    d=power_func(a,b//2,p)
    return d*d %p
  if b%2==1:
    return (a*power_func(a,b-1,p ))%p

def comb(n,k,p):
  
  from math import factorial
  if n<0 or k<0 or n<k: return 0
  if n==0 or k==0: return 1
  a=factorial(n) %p
  b=factorial(k) %p
  c=factorial(n-k) %p
  return (a*power_func(b,p-2,p)*power_func(c,p-2,p))%p
x,y = map(int,input().split())
if (x+y)%3 != 0:
     print(0)
else:
     a = (2*y-x) / 3
     b = (2*x - y) / 3
     print(comb(a+b, b,1000000007))


x,y = map(int,input().split())
s = (2 * y -x) / 3
t = (2 * x -y) / 3
if s.is_integer() and t.is_integer() and s >= 0 and t >= 0:
    def comb(n, r, mod=10 ** 9 + 7):
        a = 1
        b = 1
        r = min(r, n - r)
        for i in range(r):
            a = a * (n - i) % mod
            b = b * (i + 1) % mod
        return a * pow(b, mod - 2, mod) % mod
    s = int(s)
    t = int(t)
    print(comb(s + t, t, mod=10 ** 9 + 7))
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):
a,b = map(int, input().split())
tried = (a + b)//3
p = 10**9 +7

if a < tried or b < tried or (a+b)%3 != 0:
    print(0)
    quit()
one = int((2 * a -  b)/3)
print(one)
n = tried
r = min(one, tried-one)
n_fac = 1
r_fac = 1
n_r_fac = 1

for i in range(2,n+1):
    n_fac *= i
    n_fac %= p
for i in range(2,r+1):
    r_fac *= i
    r_fac %= p
for i in range(2,n-r+1):
    n_r_fac *= i
    n_r_fac %= p
r_fac_inverse = pow(r_fac, p-2, p)
n_r_fac_inverse = pow(n_r_fac, p-2, p)

print((n_fac * r_fac_inverse * n_r_fac_inverse)%p)


a,b = map(int, input().split())
tried = (a + b)//3
p = 10**9 +7

if a < tried or b < tried or (a+b)%3 != 0:
    print(0)
    quit()
if abs(a-b) == 0:
    one = tried//2
else:
    one = abs(a-b)
n = tried
r = min(one, tried-one)
print(n,r)
n_fac = 1
r_fac = 1
n_r_fac = 1

for i in range(2,n+1):
    n_fac *= i
    n_fac %= p
for i in range(2,r+1):
    r_fac *= i
    r_fac %= p
for i in range(2,n-r+1):
    n_r_fac *= i
    n_r_fac %= p
r_fac_inverse = pow(r_fac, p-2, p)
n_r_fac_inverse = pow(n_r_fac, p-2, p)

print((n_fac * r_fac_inverse * n_r_fac_inverse)%p)


a,b = map(int, input().split())
tried = (a + b)//3
p = 10**9 +7

if a < tried or b < tried or (a+b)%3 != 0:
    print(0)
    quit()
one = (2/3)* a - (1/3)* b
n = tried
r = min(one, tried-one)
n_fac = 1
r_fac = 1
n_r_fac = 1

for i in range(2,n+1):
    n_fac *= i
    n_fac %= p
for i in range(2,r+1):
    r_fac *= i
    r_fac %= p
for i in range(2,n-r+1):
    n_r_fac *= i
    n_r_fac %= p
r_fac_inverse = pow(r_fac, p-2, p)
n_r_fac_inverse = pow(n_r_fac, p-2, p)

print((n_fac * r_fac_inverse * n_r_fac_inverse)%p)


a,b = map(int, input().split())
tried = (a + b)//3
p = 10**9 +7

if a < tried or b < tried or (a+b)%3 != 0:
    print(0)
    quit()
one = int((2 * a -  b)/3)
n = tried
r = min(one, tried-one)
n_fac = 1
r_fac = 1
n_r_fac = 1

for i in range(2,n+1):
    n_fac *= i
    n_fac %= p
for i in range(2,r+1):
    r_fac *= i
    r_fac %= p
for i in range(2,n-r+1):
    n_r_fac *= i
    n_r_fac %= p
r_fac_inverse = pow(r_fac, p-2, p)
n_r_fac_inverse = pow(n_r_fac, p-2, p)

print((n_fac * r_fac_inverse * n_r_fac_inverse)%p)


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 math
from functools import lru_cache

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


# 08        01
# 07          04
# 06      01    06
# 05        03    04
# 04    01    03    01
# 03      02    01
# 02  01    01
# 01    01
# 00ST
#   000102030405060708






if x <= 2 * y and y <= x * 2 and (x + y) % 3 == 0:
    
    total = (x + y) // 3
    
    
    n=x-total
    # print(total, k)

    
    
    

    fac = [1, 1]
    ifac = [1, 1]
    inv = [0, 1]

    for i in range(2, total + 1):
        fac.append(fac[-1] * i % MOD)
        inv.append((-inv[MOD % i] * (MOD // i)) % MOD)
        ifac.append((ifac[-1] * inv[-1]) % MOD)

    def c(n, k):
        k = min(k, n-k)
        # if total < k: return 0
        # if total < 0 or k < 0: return 0
        return fac[n] * ifac[k] * ifac[n-k] % MOD

    

    print(c(total, n))
else:
    print(0)
    exit()


import math
from functools import lru_cache

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

MOD = 10 ** 9 + 7


# 08        01
# 07          04
# 06      01    06
# 05        03    04
# 04    01    03    01
# 03      02    01
# 02  01    01
# 01    01
# 00ST
#   000102030405060708






if x <= 2 * y and y <= x * 2 and (x + y) % 3 == 0:
    
    total = (x + y) // 3
    
    
    n=x-total
    # print(total, k)

    
    
    

    fac = [1, 1]
    ifac = [1, 1]
    inv = [0, 1]

    for i in range(2, total + 1):
        fac.append(fac[-1] * i % MOD)
        inv.append((-inv[MOD % i] * (MOD // i)) % MOD)
        ifac.append((ifac[-1] * inv[-1]) % MOD)

    def c(n, k):
        k = min(k, n-k)
        # if total < k: return 0
        # if total < 0 or k < 0: return 0
        return fac[n] * ifac[k] * ifac[n-k] % MOD

    

    print(c(total, n))
else:
    print(0)
    exit()


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())
cnt = 0

for i in range(0,x//2+1):
    if (x-2*i)*2+i == y:
        cnt += factorial(x-i)/(factorial(x-2*i)*factorial(i))

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

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

x,y = map(int,input().split())
ans = 0
mod = 10**9+7
if (x+y)%3 == 0:
    a = (-x+2*y)//3
    b = (2*x-y)//3
    if a >= 0 and b >= 0: 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().spilt())
mult1=1
mult2=1
if (2*Y-X)%3 ==0:
    x=(2*Y-X)//3
    y=(2*X-Y)//3
    for i in range(min(x,y)):
        mult1*=(x+y-i)
        mult2*=min(x,y)-i
    print((mult2//mult1)%(10**9+7))
else:
    print(0)

X,Y=map(int,input().split())
mult1=1
mult2=1
if (2*Y-X)%3 ==0:
    x=(2*Y-X)//3
    y=(2*X-Y)//3
    for i in range(min(x,y)):
        mult1*=(x+y-i)
        mult2*=min(x,y)-i
    print((mult2//mult1)%(10**9+7))
else:
    print(0)

X,Y=map(int,input().split())
A,B=1,1
mod=10**9+7
if (X+Y)%3 ==0:
    x=(2*Y-X)//3
    y=(2*X-Y)//3
    if min(x,y) >= 0:
      for i in range(min(x,y)):
        A*=(x+y-i)
        A%=mod
        B*=(i+1)
        B%=mod
      print(A*pow(B,mod-2,mod)%mod)
    else:
      print(0)
else:
  print(0)


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

n = (-X+2*Y)//3
m = (2*X-Y)//3
MOD = 10**9+7
    
def comb(n,r,MOD):
    x = n+1
    y = min(r,n-r)
    
    numer = 1
    denom = 1
    
    for i in range(1,r+1):
        numer = numer*(x-i)%MOD
        denom = denom*(i)%MOD
    
    return numer * pow(denom,MOD-2,MOD) % MOD
  
import sys

if n < 0 or m < 0:
    print(0)
    sys.exit()
if X+Y%3 != 0:
    print(0)
    sys.exit()
    
print(comb(n+m,n,MOD))

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

n = (-X+2*Y)//3
m = (2*X-Y)//3
MOD = 10**9+7
    
def comb(n,r,MOD):
    x = n+1
    y = min(r,n-r)
    
    numer = 1
    denom = 1
    
    for i in range(1,r+1):
        numer = numer*(x-i)%MOD
        denom = denom*(i)%MOD
    
    return numer * pow(denom,MOD-2,MOD) % MOD
  
import sys

if n < 0 or m < 0:
    print(0)
    sys.exit()
if (X+Y)%3 != 0:
    print(0)
    sys.exit()
    
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):
from numpy.linalg import solve
import math

x, y = map(int, input().split())
m  = 10**9+7
if (x+y)%3 == 0:
    left, right = [[2,1],[1,2]], [x,y]
    nl = solve(left, right)
    nl.sort()
    print((math.factorial(sum(nl))//(math.factorial(sum(nl)-nl[0]) * math.factorial(nl[0])))%m)
else:
    print(0)

nCr = {}
def cmb(n, r):
    if r == 0 or r == n: return 1
    if r == 1: return n
    if (n,r) in nCr: return nCr[(n,r)]
    nCr[(n,r)] = cmb(n-1,r) + cmb(n-1,r-1)
    return nCr[(n,r)]

x, y = map(int, input().split())
m  = 10**9+7
if (x+y)%3 == 0:
    left, right = [[2,1],[1,2]], [x,y]
    nl = solve(left, right)
    a, b = nl[0], nl[1]
    print(int(cmb(a+b, a))%m)
else:
    print(0)

def nCr(n, r, mod):
    x, y = 1, 1
    for r_ in range(1, r+1):
        x = x*(n+1-r_)%mod
        y = y*r_%mod
    return x*pow(y, mod-2, mod)%mod

x, y = map(int, input().split())
if (x+y)%3 or 2*x<y or 2*y<x:
    print(0)
else:
    print(nCr((x+y)//3,(2*x-y)//3, mod))

def nCr(n, r, mod):
    x, y = 1, 1
    for r_ in range(1, r+1):
        x = x*(n+1-r_)%mod
        y = y*r_%mod
    return x*pow(y, mod-2, mod)%mod

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

Verdicts: 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 sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines


def c(n, k):
    from math import factorial

    ans = factorial(n) / factorial(k) / factorial(n - k)

    return ans % mod


mod = 10**9 + 7

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

if y > x:
    temp = y
    y = x
    x = temp

if ((x + y) % 3 != 0) or x > y * 2:
    print("0")
else:
    n = ((x + y) // 3)
    k = ((n - abs(x - y)) // 2)
    ans = c(n, k)
    print(ans)


import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

MOD = 10**9 + 7


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


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

if ((x + y) % 3 != 0):
    print("0")
else:
    a = (2*y - x) // 3
    b = (x - a) // 2

    if a < 0 or b < 0:
        print(0)
    else:
        print(combination(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):
x,y=map(int,input().split())

if (x+y)%3!=0 or x*2>y or y*2>x :
    print(0)

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

# ans = math.factorial(a+b)/math.factorial(a)
# ans=1

#     ans*=i%(10**9+7)

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)

ans = cmb(a+b,a,p)

print(ans)


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

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

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

# ans = math.factorial(a+b)/math.factorial(a)
# ans=1

#     ans*=i%(10**9+7)

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)

ans = cmb(a+b,a,p)

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

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

if m.is_integer() == n.is_integer() == True:
    ans = math.factorial(m+n)//(math.factorial(m) * math.factorial(n))
else:
    ans = 0

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

import math

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

if m.is_integer() == n.is_integer() == True:
    ans = math.factorial(m+n)/(math.factorial(m)*math.factorial(n))
else:
    ans = 0

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

import math

x, y = map(int, input().split())
m = (2*x-y)/3
n = (-x+2*y)/3
print(m,n)
if m.is_integer() == n.is_integer() == True:
    ans = math.factorial(m+n)/(math.factorial(m)*math.factorial(n))
else:
    ans = 0

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

MOD = 10**9+7
MAX = 1000010
finv = [0] * MAX
inv = [0] * MAX
def COMinit():
    finv[0] = finv[1] = 1
    inv[1] = 1
    for i in range(2, MAX):
        inv[i] = MOD - inv[MOD%i] * (MOD//i) % MOD
        finv[i] = finv[i-1] * inv[i] % MOD
def COM(n, k):
    res = 1
    for i in range(k):
        res = res * (n-i) % MOD
    return res * finv[k] % MOD

x, y = map(int, input().split())
if (x+y)%3 != 0:
    ans = 0
else:
    s, t = (-x+2*y)//3, (2*x-y)//3
    if s < 0 or t < 0:
        ans = 0
    else:
        COMinit()
        ans = COM((s+t), s)

print(ans)

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

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

if (2*X < Y):
    print (0)
    exit()

W = X - ((X+Y)//3)
H = Y - ((X+Y)//3)

mx = 10**6
fact = [1] * (mx+1) 
def inv(n): 
    return pow(n, MOD-2, MOD)
for i in range(mx):
    fact[i+1] = fact[i] * (i+1) % MOD 
ans = (fact[W+H] * inv(fact[W]) * inv(fact[H])) % MOD # comb(W+H,W) = (W+H)!/(W!H!)
print (ans)

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

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

if (2*X < Y):
    print (0)
    exit()

W = X - ((X+Y)//3)
H = Y - ((X+Y)//3)

mx = 10**6
fact = [1] * (mx+1) 
def inv(n): 
    return pow(n, MOD-2, MOD)
for i in range(mx):
    fact[i+1] = fact[i] * (i+1) % MOD 
ans = (fact[W+H] * inv(fact[W]) * inv(fact[H])) % MOD # comb(W+H,W) = (W+H)!/(W!H!)
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):
x, y =map(int, input().split())

x_n = 0
y_n = 0

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

from itertools import permutations, combinations,combinations_with_replacement,product

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

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

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

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

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

print(int(combination(m + n, 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):
X,Y = input().split()
X,Y = int(X),int(Y)

def d(r,n,p):#r^n mod p
    if(n==0):
        return 1
    
    elif(n%2==0):
        d_ = d(r,n//2,p)
        return (d_**2)%p
    
    else:
        d_ = d(r,(n-1),p)
        return (d_*r)%p
    
def fac(n,p):#n! mod p
    mul = 1
    for i in range(1,n+1):
        mul = (mul*i)%p
        
def r_fact_p(r,p):#(r!)^(p-2)
    mul = 1
    for i in range(1,r+1): #i^(p-2)
        mul = (mul*d(i,p-2,p))%p
        
    return mul

def C(n,r):
    return (d(r,n,p)*r_fact_p(r,p))%p



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

p = 10 ** 9 + 7
 
def mod_inverse(a, p):
    mod = 1
    p_bin = bin(p-2)
    for i in range(len(p_bin) - 1, 1, -1):
        if i == len(p_bin) - 1:
            mul = a
            mul %= p
            mod *= (mul ** int(p_bin[i]))
            mod %= p
        else:
            mul = mul ** 2
            mul %= p
            mod *= (mul ** int(p_bin[i]))
            mod %= p
    return mod
 
def combination(n, k, p):
    a = 1
    for i in range(n, n - k, -1):
        a *= i
        a %= p
    b = 1
    for i in range(k):
        b *= (i + 1)
        b %= p
    return (a * mod_inverse(b, p)) % p

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

if((X-2*Y)%3 !=0 or (2*X-Y)%3 != 0):
    print(0)
    
else:
    a = (-X+2*Y)//3
    b = (2*X-Y)//3
    if(a<0 or b<0):
        print(0)
    else:
        
        print(combination(a+b,b,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):
#coding:utf-8
x, y = map(int, input().split())

mod = 10**9 + 7
f = [1]
for i in range(10**6):
    f.append(f[-1] * (i+1) % mod)
    
def nCr(n, r):
    return f[n] * pow(f[r], mod-2, mod) * pow(f[n-r], mod-2, mod) % mod

def main():
    if (x + y) % 3 != 0 or (x + y) // 3 < abs(x - y):
        print(0)
        return

    n = (x + y) // 3
    r = n - abs(x - y)
    print(nCr(n, r))
    return
    
main()

#coding:utf-8
x, y = map(int, input().split())

mod = 10**9 + 7
f = [1]
for i in range(10**6):
    f.append(f[-1] * (i+1) % mod)
    
def nCr(n, r):
    return f[n] * pow(f[r], mod-2, mod) * pow(f[n-r], mod-2, mod) % mod

def main():
    if (x + y) % 3 != 0 or (x + y) // 3 < abs(x - y):
        print(0)
        return
    
    n = (x + y) // 3
    r = n // 2 - abs(x-y) // 2
    print(n, r)
    print(nCr(n, r))
    return
    
main()

#coding:utf-8
x, y = map(int, input().split())

mod = 10**9 + 7
f = [1]
for i in range(10**6):
    f.append(f[-1] * (i+1) % mod)
    
def nCr(n, r):
    return f[n] * pow(f[r], f[r] ** (mod-2), mod) * pow(f[n-r] ** (mod-2), mod) % mod

def main():
    if (x + y) % 3 != 0 or (x + y) // 3 < abs(x - y):
        print(0)
        return

    n = (x + y) // 3
    r = n - abs(x - y)
    print(nCr(n, r))
    return
    
main()

#coding:utf-8
x, y = map(int, input().split())

mod = 10**9 + 7
f = [1]
for i in range(10**6):
    f.append(f[-1] * (i+1) % mod)
    
def nCr(n, r):
    return f[n] * pow(f[r], mod-2, mod) * pow(f[n-r], mod-2, mod) % mod

def main():
    if (x + y) % 3 != 0 or (x + y) // 3 < abs(x - y):
        print(0)
        return
    
    n = (x + y) // 3
    r = n // 2 - abs(x-y) // 2
    print(nCr(n, r))
    return
    
main()

Verdicts: Wrong Answer

Wrong Answer

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())
if X>Y:
    X,Y = Y,X
if(X+Y)%3:
    print(0)
    exit()
n = (X+Y)//3
if X < n:
    print(0)
    exit()

MOD = 10**9+7
r = X-n

print(n,r)

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

def ncr(n,r):
    if n < r: return 0
    if n < 0 or r < 0: return 0
    return fac[n] * (finv[r] * finv[n-r] % MOD) % MOD

print(ncr(n,r))

X,Y = map(int,input().split())
if(X+Y)%3:
    print(0)
    exit()
n = (X+Y)//3
if X < n:
    print(0)
    exit()

MOD = 10**9+7
r = X-n

print(n,r)

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

def ncr(n,r):
    if n < r: return 0
    if n < 0 or r < 0: return 0
    return fac[n] * (finv[r] * finv[n-r] % MOD) % MOD

print(ncr(n,r))

X,Y = map(int,input().split())
if X>Y:
    X,Y = Y,X
if(X+Y)%3:
    print(0)
    exit()
n = (X+Y)//3
if X < n:
    print(0)
    exit()

MOD = 10**9+7
r = X-n

print(n,r)

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

def ncr(n,r):
    if n < r: return 0
    if n < 0 or r < 0: return 0
    return fac[n] * (finv[r] * finv[n-r] % MOD) % MOD

print(ncr(n,r))

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

if (X+Y)%3:
    print(0)
    exit()
n = (X+Y)//3
r = X-n
if not 0 <= r <= n:
    print(0)
    exit()

MAXN = r
inv = [0,1] + [0]*MAXN
for i in range(2,MAXN+2):
    inv[i] = -inv[MOD%i] * (MOD // i) % MOD
def comb(n,r):
    ret = 1
    for i in range(r):
        ret *= n-i
        ret *= inv[i+1]
        ret %= MOD
    return ret

print(comb(n,r))

Verdicts: 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())
mod = 10**9+7
b = (2*Y-X)//3
a = Y - 2*b
print(a, b)
max_num = a + b + 5
facts = [1 for i in range(max_num)]
invs = [1 for i in range(max_num)]
 
def inv(x):
    return pow(x,mod-2,mod)
 
for i in range(1,max_num):
    facts[i] = facts[i-1]*i%mod
    invs[i] = inv(facts[i])
 
def nCk(n,k):
    try:
        return facts[n]*invs[k] * invs[n-k] % mod
    except IndexError:
        print(n, k, len(facts), len(invs))
if (X+Y)%3 == 0 and a>=0 and b >=0:
    print(nCk(a+b, a))
else:
    print(0)

def sq(a, b, mod):  
    if b == 0:
        return 1
    elif b % 2 == 0:
        return sq(a, b // 2, mod)**2 % mod
    else:
        return sq(a, b - 1, mod) * a % mod


def nCk(n, k, mod=10 ** 9 + 7):
    x = max(k, n - k)
    y = min(k, n - k)
    kkai = 1
    for i in range(2, y + 1):
        kkai = (kkai * i) % mod
    nkkai = 1
    for i in range(x + 1, n + 1):
        nkkai = (nkkai * i) % mod
    answer = sq(kkai, mod - 2, mod) * nkkai % mod
    return answer


X, Y = map(int, input().split())
if (X + Y) % 3 != 0:
    print(0)
else:
    n = (2 * Y - X) // 3
    m = (2 * X - Y) // 3
    if n < 0 or m < 0:
        print(0)
    else:
        print(nCk(n + m, n))


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
def binomial(n,k):
    x=1
    y=1
    for i in range(k):
        x=x*(n-i)%mod
        y=y*(i+1)%mod
    return x*power(y,mod-2)%mod

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

print(binomial(a+b,a)%mod)



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

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

if (2*X-Y)%3==0 and  (2*Y-X)%3==0:
    a=(2*X-Y)//3
    b=(2*Y-X)//3
    if a<0 or b<0:
        print(0)        
    else:
        print(binomial(a+b,a)%mod)
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):
import cmath
import numpy as np
import sys

INF=1**18
MOD=10**9+7


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

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

N=(x+y)//3
if x<N or y<N:
    print(0)
    exit()

def moP(x,n):
    res=1
    while n>0:
        if n and 1:
            res=res*x%MOD
        x=x*x%MOD
        n//=2

fa=[1]*(N+1)
re=[1]*(N+1)


for i in range(1, N+1):
    fa[i]=fa[i-1]*i%MOD
    re[i]=moP(fa[i], MOD-2)

def comb(n,k):
    if n==0 or n==k:
        return 1
    return fa[n]*re[k]%MOD*re[n-k]%MOD

K=min(x,y)-N
print(comb(N,K))









import cmath
import numpy as np
import sys

INF=1**18
MOD=10**9+7
MAX=10**5

def moP(x,n):
    res=1
    while n>0:
        if n & 1:
            res=res*x%MOD
        x=x*x%MOD
        n>>=1
    return res

def moF(n):
    res=1
    for i in range(1,n+1):
        res=res*i%MOD
    return res


def C(n,k):
    if n==0 or n==k:
        return 1
    return moF(n)*moP(moF(k), MOD-2)%MOD*moP(moF(n-k), MOD-2)%MOD

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

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

    N=(x+y)//3
    if x<N or y<N:
        print(0)
        exit()

    K=min(x,y)-N
    print(C(N,K))

if __name__=='__main__':
    main()







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())
import numpy as np
a = [[1, 2], [2, 1]]

mod = pow(10,9)+7

b = np.linalg.inv(a)


Z = np.array([[X],[Y]])

n,m=np.dot(b,Z)
p,q = *n,*m

def comb(n,k,p):
    if k==0:
        return 1
    A = reduce(lambda x,y:x*y%p ,[n-k+1+i for i in range(k)])
    B = reduce(lambda x,y:x*y%p ,[i+1 for i in range(k)])
    return A*pow(B,p-2,p)%p

if p<0 or q<0:
    print(0)
elif not p == int(p) or not q==int(q):
    print(0)
elif p==0 and q==0:
    print(0)
elif p==0:
    print(1)
elif q==0:
    print(1)
else:
    n = int(p)
    m = int(q)
    ans = comb(n,m,mod)

    print(ans%mod)



X,Y = map(int,input().split())
import numpy as np
from functools import reduce
import math 
a = [[1, 2], [2, 1]]

mod = pow(10,9)+7

b = np.linalg.inv(a)


Z = np.array([[X],[Y]])

n,m=np.dot(b,Z)
p,q = *n,*m


def comb(n,k,p):
    if k==0:
        return 1
    A = reduce(lambda x,y:x*y%p ,[n-k+1+i for i in range(k)])
    B = reduce(lambda x,y:x*y%p ,[i+1 for i in range(k)])
    return A*pow(B,p-2,p)%p


if p<0 or q<0:
    print(0)
elif not abs(p-round(p))<pow(10,-3) or not abs(q-round(q))<pow(10,-3):
    print(0)
elif p==0 and q==0:
    print(0)
elif p==0:
    print(1)
elif q==0:
    print(1)
else:
    n = int(round(p))
    m = int(round(q))
    ans = comb(n+m,m,mod)

    print(ans%mod)


Verdicts: Runtime Error

Accepted