TnT/Multi_CodeNet4Repair huggingface dataset:
Problem: Given is an integer r.  How many times is the area of a circle of radius r larger than the area of a circle of radius 1?  It can be proved that the answer is always an integer under the constraints given.

Submission attempts (in order):
if __name__ == "__main__":
    r = int(input())

    
    
    

    print(r*r*2)

if __name__ == "__main__":
    r = int(input())

    
    
    

    print(r*r)

Verdicts: Wrong Answer

Accepted
Problem: Given is an integer r.  How many times is the area of a circle of radius r larger than the area of a circle of radius 1?  It can be proved that the answer is always an integer under the constraints given.

Submission attempts (in order):
def circle_area(radius):
  return int(radius)**2

r = int(input())
circle_area(r)



return int(radius**2)
              




def circle_area(radius):
  return int(radius)**2

r = input()
circle_area(r)

r = input()
ans = int(r)**2
return ans

return int(r**2)

ans = r**2
return int(ans)

r = int(input())
print(r**2)

Verdicts: Wrong Answer

Runtime Error

Wrong Answer

Runtime Error

Runtime Error

Runtime Error

Accepted
Problem: Given is an integer r.  How many times is the area of a circle of radius r larger than the area of a circle of radius 1?  It can be proved that the answer is always an integer under the constraints given.

Submission attempts (in order):
n = int(input())
print(r**2)

n = int(input())
print(n**2)

Verdicts: Runtime Error

Accepted
Problem: Given is an integer r.  How many times is the area of a circle of radius r larger than the area of a circle of radius 1?  It can be proved that the answer is always an integer under the constraints given.

Submission attempts (in order):
r = map(int(), input())
print(r**2)

r = int(input())
print(r**2)

Verdicts: Runtime Error

Accepted
Problem: Given is an integer r.  How many times is the area of a circle of radius r larger than the area of a circle of radius 1?  It can be proved that the answer is always an integer under the constraints given.

Submission attempts (in order):
print(r * r)

return r * r

r = input()
print(r * r)

r = input()
r2 = r * r
print(r2)

r = input()
rr = input()
rrr = r * rr
print(rrr)

temp1 = r
temp2 = temp1 * 2
print(temp2)

temp = r
print(temp * 2)

r = input()
print(r * 2)

r = int(input())
print(r * r)

Verdicts: Runtime Error

Runtime Error

Runtime Error

Runtime Error

Runtime Error

Runtime Error

Runtime Error

Wrong Answer

Accepted
Problem: Given is an integer r.  How many times is the area of a circle of radius r larger than the area of a circle of radius 1?  It can be proved that the answer is always an integer under the constraints given.

Submission attempts (in order):
N = int(input())
xy = []
for i in range(N):
    a, b = (int(x) for x in input().split())
    xy.append([a, b])
    
def distance(d, xy, i, j):
    return (
              (xy[i][0] - xy[j][0]) ** 2
            + (xy[i][1] - xy[j][1]) ** 2
        ) ** 0.5
 
import itertools
d = []
l1 = [x for x in range(N)]
for v in itertools.permutations(l1, N):
    l2 = list(v)
    d0 = []
    for c in range(N-1):
        i = l2[c]
        j = l2[c+1]
        d0.append(distance(d, xy, i, j))
    d.append(sum(d0))
 
print(sum(d) / len(d))

r = int(input())
print(r * r)

Verdicts: Runtime Error

Accepted
Problem: Given is an integer r.  How many times is the area of a circle of radius r larger than the area of a circle of radius 1?  It can be proved that the answer is always an integer under the constraints given.

Submission attempts (in order):
print((int(input())**2)

n = int(input())
print(n**2)

Verdicts: Runtime Error

Accepted
Problem: Given is an integer r.  How many times is the area of a circle of radius r larger than the area of a circle of radius 1?  It can be proved that the answer is always an integer under the constraints given.

Submission attempts (in order):
a=input()
print(a*a)

a = int(input())
a = a*a
print(a)

Verdicts: Runtime Error

Accepted
Problem: Given is an integer r.  How many times is the area of a circle of radius r larger than the area of a circle of radius 1?  It can be proved that the answer is always an integer under the constraints given.

Submission attempts (in order):
import itertools
import numpy as np

num = int(input())
x = []
y = []
for i in range(num):
  x_N, y_N = map(int, input().split())
  x.append(x_N)
  y.append(y_N)

index = [str(i) for i in range(num)]
index_permut = list(itertools.permutations(index))

distance_all = 0
for l in index_permut:
  distance = 0
  index = list(map(int, l))

  for pos in range(num-1):
    x_diff = (x[index[pos+1]] - x[index[pos]]) ** 2
    y_diff = (y[index[pos+1]] - y[index[pos]]) ** 2
    distance += np.sqrt(x_diff + y_diff)

  distance_all += distance
res = distance_all / len(index_permut)
print(res)

r = int(input())
print(r**2)

Verdicts: Runtime Error

Accepted
Problem: Given is an integer r.  How many times is the area of a circle of radius r larger than the area of a circle of radius 1?  It can be proved that the answer is always an integer under the constraints given.

Submission attempts (in order):


#import math
from operator import mul
from functools import reduce

DEBUG = 0

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

def calc(x,y):
    if (x*2-y)%3 != 0 or (y*2-x)%3 != 0: return 0
    m = (x*2-y)//3
    n = (y*2-x)//3
    if m <= 0 or n <= 0:return 0
    return combinations_count(m+n,m)

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

if DEBUG:print(X,Y)

print(calc(X,Y)%(10**9+7))


r = int(input())
S=r*r
print(int(S))

Verdicts: Runtime Error

Accepted
Problem: Given is an integer r.  How many times is the area of a circle of radius r larger than the area of a circle of radius 1?  It can be proved that the answer is always an integer under the constraints given.

Submission attempts (in order):
print(int(input()**2))

print(input()**2)

print(int(input())**2)

Verdicts: Runtime Error

Runtime Error

Accepted
Problem: Given is an integer r.  How many times is the area of a circle of radius r larger than the area of a circle of radius 1?  It can be proved that the answer is always an integer under the constraints given.

Submission attempts (in order):
r = int(input())
print(r^2)


r = int(input())
print(r*r)


Verdicts: Wrong Answer

Accepted
Problem: Given is an integer r.  How many times is the area of a circle of radius r larger than the area of a circle of radius 1?  It can be proved that the answer is always an integer under the constraints given.

Submission attempts (in order):
a=input()
print(a*a)

N=int(input())
print(N*N)

Verdicts: Runtime Error

Accepted
Problem: Given is an integer r.  How many times is the area of a circle of radius r larger than the area of a circle of radius 1?  It can be proved that the answer is always an integer under the constraints given.

Submission attempts (in order):
print(1)

n=int(input())
print(n*n)

Verdicts: Wrong Answer

Accepted
Problem: Given is an integer r.  How many times is the area of a circle of radius r larger than the area of a circle of radius 1?  It can be proved that the answer is always an integer under the constraints given.

Submission attempts (in order):
r = input()
print(r**2)

print(r**2)

r = int(input())
print(r**2)

Verdicts: Runtime Error

Runtime Error

Accepted
Problem: Given is an integer r.  How many times is the area of a circle of radius r larger than the area of a circle of radius 1?  It can be proved that the answer is always an integer under the constraints given.

Submission attempts (in order):
import math
def hankei(x):
    print(x*x*math.pi/1*1*math.pi)
hankei(int(input(">")))


r=input()
print(r**2)

def hankei(x):
    print(x**2)
hankei(int(input(">")))

def f(r):
  print(r**2)


def hankei(x):
  print(x**2)
print(r)

r=int(input())
print(r**2)


Verdicts: Wrong Answer

Runtime Error

Wrong Answer

Wrong Answer

Runtime Error

Accepted
Problem: Given is an integer r.  How many times is the area of a circle of radius r larger than the area of a circle of radius 1?  It can be proved that the answer is always an integer under the constraints given.

Submission attempts (in order):
N = int(input())
data = []
sum = 0
x = 0
y = 1
ss=[0,0,2,4,18,96,600,4320,35280]
for i in range(N):
    data.append( list(map(int,input().split())))
for i in range(N -1):
    for j in range(N - 1):
        if(j+1+i==N):
            break
        sum+=((data[i][x]-data[j+1+i][x])**2+(data[i][y]-data[j+1+i][y])**2)**0.5

print(sum*ss[N]/N)


r = int(input())
print(r**2)

Verdicts: Runtime Error

Accepted
Problem: Given is an integer r.  How many times is the area of a circle of radius r larger than the area of a circle of radius 1?  It can be proved that the answer is always an integer under the constraints given.

Submission attempts (in order):
r = int(input)
x = r ** 2
print(x)


r = int(input())
x = r ** 2
print(x)

Verdicts: Runtime Error

Accepted
Problem: Given is an integer r.  How many times is the area of a circle of radius r larger than the area of a circle of radius 1?  It can be proved that the answer is always an integer under the constraints given.

Submission attempts (in order):
R = input()R = input()
print(int(R)*int(R))

R = input()
print(int(R)*int(R))

Verdicts: Runtime Error

Accepted
Problem: Given is an integer r.  How many times is the area of a circle of radius r larger than the area of a circle of radius 1?  It can be proved that the answer is always an integer under the constraints given.

Submission attempts (in order):
r = input()
print(r*r)

r = int(input())
print(r*r)


Verdicts: Runtime Error

Accepted
Problem: Given is an integer r.  How many times is the area of a circle of radius r larger than the area of a circle of radius 1?  It can be proved that the answer is always an integer under the constraints given.

Submission attempts (in order):
r=int(input())
print(r^2)

r=int(input())
print(r**2)

Verdicts: Wrong Answer

Accepted
Problem: Given is an integer r.  How many times is the area of a circle of radius r larger than the area of a circle of radius 1?  It can be proved that the answer is always an integer under the constraints given.

Submission attempts (in order):
import math

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

if (X + Y) % 3 != 0:
  print(0)
  
else:
  a = Y - (X + Y) // 3
  b = X - (X + Y) // 3
  total = a + b
  m = min(a,b)
  def permod(n, r):
    return (math.factorial(n) // math.factorial(n - r)) % (10 ** 9 + 7)
  
  ans = permod(total,m)
  print(ans)

r = int(input())

print(r ** 2)

Verdicts: Runtime Error

Accepted
Problem: Given is an integer r.  How many times is the area of a circle of radius r larger than the area of a circle of radius 1?  It can be proved that the answer is always an integer under the constraints given.

Submission attempts (in order):
r = input()
s = r**2
print(s)

r = int(input())
print(r**2)

Verdicts: Runtime Error

Accepted
Problem: Given is an integer r.  How many times is the area of a circle of radius r larger than the area of a circle of radius 1?  It can be proved that the answer is always an integer under the constraints given.

Submission attempts (in order):
if __name__ == "__main__":
  int a = input()
  print(a*a)
  

a = int(input())
print(a*a)

Verdicts: Runtime Error

Accepted
Problem: Given is an integer r.  How many times is the area of a circle of radius r larger than the area of a circle of radius 1?  It can be proved that the answer is always an integer under the constraints given.

Submission attempts (in order):
n=int(input())
print((n**2)/1.0)

n=int(input())
print(int(n**2))

Verdicts: Wrong Answer

Accepted
Problem: Given is an integer r.  How many times is the area of a circle of radius r larger than the area of a circle of radius 1?  It can be proved that the answer is always an integer under the constraints given.

Submission attempts (in order):
R = int(input())
return R*R

R = int(input())
print(R*R)

Verdicts: Runtime Error

Accepted
Problem: Given is an integer r.  How many times is the area of a circle of radius r larger than the area of a circle of radius 1?  It can be proved that the answer is always an integer under the constraints given.

Submission attempts (in order):
import math
r=int(input())
s0=math.pi*1**2
s=math.pi*r**2
print(s//s0)

print(int(input())**2)

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):
# 73

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

a = 2*y - x
b = 2*x - y

fac_l = [0] * (int((a + b) / 3) + 1)
inv_l = [0] * (int((a + b) / 3) + 1)
finv_l = [0] * (int((a + b) / 3) + 1)


def com_init():
    fac_l[1] = 1
    inv_l[0] = 1
    inv_l[1] = 1
    finv_l[0] = 1
    finv_l[1] = 1
    for i in range(2, a+b+1):
        fac_l[i] = (fac_l[i-1] * i) % MOD
        inv_l[i] = MOD - (inv_l[MOD % i] * int(MOD / i)) % MOD
        finv_l[i] = (finv_l[i-1] * inv_l[i]) % MOD

def ncr(n, r):
    return (fac_l[n] * (finv_l[r] * finv_l[n-r]) % MOD) % MOD


if a % 3 != 0 or b % 3 != 0 or a > 0 or b > 0:
    print("0")
else:
    a = int(a/3)
    b = int(b/3)

    com_init()
    print(ncr(a+b, a))


# 73

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

a = 2*y - x
b = 2*x - y

fac_l = [0] * (int((a + b) / 3) + 1)
inv_l = [0] * (int((a + b) / 3) + 1)
finv_l = [0] * (int((a + b) / 3) + 1)


def com_init():
    fac_l[1] = 1
    inv_l[0] = 1
    inv_l[1] = 1
    finv_l[0] = 1
    finv_l[1] = 1
    for i in range(2, a+b+1):
        fac_l[i] = (fac_l[i-1] * i) % MOD
        inv_l[i] = MOD - (inv_l[MOD % i] * int(MOD / i)) % MOD
        finv_l[i] = (finv_l[i-1] * inv_l[i]) % MOD

def ncr(n, r):
    return (fac_l[n] * (finv_l[r] * finv_l[n-r]) % MOD) % MOD


if a % 3 != 0 or b % 3 != 0 or a < 0 or b < 0:
    print("0")
else:
    a = int(a/3)
    b = int(b/3)

    com_init()
    print(ncr(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):
X, Y = list(map(int, input().split()))

def f(x, p):
    a = 1
    for i in range(1, x + 1):
        a *= i
        a %= p
    return a
def nCr(a, b, p):
    if a < 0 or b < 0:
        return 0
    elif a < b:
        return 0
    c = 1
    c *= f(a, p)
    c *= pow(f(b, p), p - 2, p)
    c *= pow(f(a - b, p), p - 2, p)
    return c % p

if (2*X-Y)%3 != 0 or (2*Y-X)%3 != 0 or Y > X*2 or X > Y*2:
  print(0)
else:
  m = (2*X-Y)//3
  n = (2*Y-X)//3
  print(nCr(m+n, n))


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

def f(x, p):
    a = 1
    for i in range(1, x + 1):
        a *= i
        a %= p
    return a
def nCr(a, b, p):
    if a < 0 or b < 0:
        return 0
    elif a < b:
        return 0
    c = 1
    c *= f(a, p)
    c *= pow(f(b, p), p - 2, p)
    c *= pow(f(a - b, p), p - 2, p)
    return c % p

if (2*X-Y)%3 != 0 or (2*Y-X)%3 != 0 or Y > X*2 or X > Y*2:
  print(0)
else:
  m = (2*X-Y)//3
  n = (2*Y-X)//3
  print(nCr(m+n, n, 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())
f=[[0]*(10**3) for i in range(10**3)]
for i in range(x):
  for j in range(y):
    f[i][j]=f[i-1][j-2]+f[i-2][j-1]
print(f[x][y])

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

if (2*x-y)%3==0:
  a=(2*x-y)//3
else:
  flflag=False
if (2*y-x)%3==0:
  b=(2*y-x)//3
else:
  flflag=False

def kaijou(n):
  ans = 1
  for i in range(1,n+1):
    ans*=i%mod
    ans%=mod  
  return ans
if flflag:
  N=a+b
  R=min(a,b)
ans=0
if flflag==True and a>=0 and b>=0:
  ans=kaijou(N)
  ans1= (kaijou(N-R)*kaijou(R))%mod
  print((ans*pow(ans1,mod-2,mod))%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):
def main():
    mod = 10 ** 9 + 7
    X, Y = map(int, input().split(" "))
    if (2 * X - Y) % 3 == 0 and (2 * Y - X) % 3 == 0:
        s = (2 * X - Y) // 3
        t = (2 * Y - X) // 3
        if s < 0 or t < 0:
            print(0)
        else:
            numerator = 1
            denominator = 1
            for i in range(s - t + 1, s + 1):
                numerator = (numerator * i) % mod
            for i in range(1, t + 1):
                denominator = (denominator * i) % mod
            print(numerator * pow(denominator, mod - 2, mod) % mod)
            
    else:
        print(0)


if __name__ == '__main__':
    main()

def main():
    mod = 10 ** 9 + 7
    X, Y = map(int, input().split(" "))
    if (2 * X - Y) % 3 == 0 and (2 * Y - X) % 3 == 0:
        s = (2 * X - Y) // 3
        t = (2 * Y - X) // 3
        numerator = 1
        denominator = 1
        for i in range(s - t + 1, s + 1):
            numerator = (numerator * i) % mod
        for i in range(1, t + 1):
            denominator = (denominator * i) % mod
        print(numerator * pow(denominator, mod - 2, mod) % mod)
        
    else:
        print(0)


if __name__ == '__main__':
    main()

def main():
    mod = 10 ** 9 + 7
    X, Y = map(int, input().split(" "))
    if (2 * X - Y) % 3 == 0 and (2 * Y - X) % 3 == 0:
        s = (2 * X - Y) // 3
        t = (2 * Y - X) // 3
        if s < 0 or t < 0:
            print(0)
        else:
            numerator = 1
            denominator = 1
            for i in range(s + 1, s + t + 1):
                numerator = (numerator * i) % mod
            for i in range(1, t + 1):
                denominator = (denominator * i) % mod
            print(numerator * pow(denominator, mod - 2, mod) % mod)
            
    else:
        print(0)


if __name__ == '__main__':
    main()

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 cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

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

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

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

    return result


x, y = map(int, input().split())
if ((x + y) % 3 != 0):
	print("0")
elif (x > 2*y or y > 2_x):
	print("0")
else:
	n_x = (2 * x - y) // 3
	n_y = (2 * y - x) // 3
	n_xy = (x + y) // 3
	print(cmb(n_xy,n_x)%1000000007)


import math

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

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

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

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

    return result


x, y = map(int, input().split())
if ((x + y) % 3 != 0):
	print("0")
elif (x > 2*y || y > 2_x):
	print("0")
else:
	n_x = (2 * x - y) // 3
	n_y = (2 * y - x) // 3
	n_xy = (x + y) // 3
	print(cmb(n_xy,n_x)%1000000007)


import math

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

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

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

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

    return result


x, y = map(int, input().split())
if ((x + y) % 3 != 0):
	print("0")
elif (x > 2*y or y > 2*x):
	print("0")
else:
	n_x = (2 * x - y) // 3
	n_y = (2 * y - x) // 3
	n_xy = (x + y) // 3
	print(cmb(n_xy,n_x)%1000000007)


Verdicts: Runtime Error

Runtime Error

Accepted
Problem: There is a knight - the chess piece - at the origin (0, 0) of a two- dimensional grid.  When the knight is at the square (i, j), it can be moved to either (i+1,j+2) or (i+2, j+1).  In how many ways can the knight reach the square (X, Y)?  Find the number of ways modulo 10^9 + 7.

Submission attempts (in order):
import sys
input = sys.stdin.readline

MAX = 2000000
MOD = 1000000007

X, Y = map(int, input().split())
count_x = 2*X - Y
count_y = 2*Y - X
if count_x % 3 != 0 or count_y % 3 != 0:
    print(0)
    exit()
count_x = count_x // 3
count_y = count_y // 3

fac = [0]*MAX
inv = [0]*MAX
finv = [0]*MAX

fac[0], fac[1] = 1, 1
finv[0], finv[1] = 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):
    global fac
    global finv
    if n < k:
        return 0
    if n < 0 or k < 0:
        return 0
    return fac[n] * (finv[k] * finv[n-k] % MOD) % MOD

print(COM(count_x + count_y, min(count_x, count_y)))


import math, sys
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque
from copy import deepcopy
from functools import lru_cache
from heapq import heapify, heappop, heappush
from itertools import accumulate, combinations, permutations
input = sys.stdin.readline
p = 10**9 + 7
ns = lambda: input().strip()
ni = lambda: int(input().strip())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

def main():

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

    N = 10 ** 6  
    fact = [1, 1]  # fact[n] = (n! mod p)
    factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
    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)

    x, y = nm()

    if (x + y) % 3 != 0:
        print(0)
        exit()
    
    n = (2*y - x) // 3 
    m = (2*x - y) // 3 

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

    print(combination(n+m, n, p))

if __name__ == '__main__':
    main()

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())
 
if (x + y) % 3  != 0:
  print(0)
  exit()
  
k = x - (x+y)//3
m = y - (x+y)//3
 
if k < 0 or m < 0:
  print(0)
  exit()
  
def nCr(k,m):
  mod = 10**9 + 7
  k,m = max(k,m),min(k,m)
  l = s = 0
  for i in range(m,k - m + 1):
    l = l * (m + i) % mod
    s = s * (i + 1) % mod
    
print(l/s)

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

if (x + y) % 3  == 0:
  print(0)
  exit()
  
k = x - (x+y)//3
m = y - (x+y)//3

if k < 0 or m < 0:
  print(0)
  exit()
  
def nCr(k,m):
  mod = 10**9 + 7
  k,m = max(k,m),min(k,m)
  l = s = 0
  for i in range(m,k + 1):
    l = l * (m + i) % mod
    s = s * (i + 1) % mod
    
print(l/s)

x,y = map(int, input().split())
 
if (x + y) % 3  == 0:
  print(0)
  exit()
  
k = x - (x+y)//3
m = y - (x+y)//3
 
if k < 0 or m < 0:
  print(0)
  exit()
  
def nCr(k,m):
  mod = 10**9 + 7
  k,m = max(k,m),min(k,m)
  l = s = 0
  for i in range(m,k - m + 1):
    l = l * (m + i) % mod
    s = s * (i + 1) % mod
    
print(l/s)

import math
M = 10**9+7
X,Y = map(int,input().split())
if (X+Y)/3 != (X+Y)//3:
    print(0)
    exit()
n = (X+Y)//3
r = Y-n
if r<0 or r>n:
    print(0)
    exit()
 
 
#nCr and Mod
def nCr(n, r, mod=10**9+7):
    r = min(r, n-r)
    numer = denom = 1
    for i in range(1, r+1):
        numer = numer * (n+1-i) % mod
        denom = denom * i % mod
    return numer * pow(denom, mod-2, mod) % mod
 
print(nCr(n,r,M))

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
def print_ans(a,b):
    print((a*b+1)%MOD)

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

x=X
y=Y
a=0
b=0
if X % 2 == 1:
    x -= 1
    y -= 2
    a+=1
if Y % 2 == 1:
    x -= 2
    y -= 1
    b+=1
if x < 0 or  y < 0 or abs(x - y) % 2 == 1:
    print(0)
else:
    if x > y:
        c=x-y
        a+=c
        x-=c*2
        y-=c
    elif y < x:
        c=y-x
        b+=c
        x-=c
        y-=c*2
    if x < 0 or y < 0:
        print(0)
    else:
        if x % 3 == 0:
            a+=x/3
            b+=y/3
            print_ans(a,b)
        else:
            print(0)


MOD = 10**9 + 7

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

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 not (X+Y) % 3:
    m = (2*X - Y)//3
    n = (2*Y - X)//3
    if n >= 0 and m >= 0:
        print(comb(n+m,n))
    else:
        print(0)
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 sys
input = sys.stdin.readline

_x, _y = map(int, input().split())


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

n = (X + Y) // 3
r = Y - n
print(combination(n, r))


def nCk(n, k, m=10 ** 9 + 7):
    a = b = 1
    k = min(k, n - k)
    for i in range(k):
        a = (a * (n - i)) % m
        b = (b * (i + 1)) % m

    return (a * pow(b, m - 2, m)) % m


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

    if x == y:
        b = x // 3
        print(nCk(2 * b, b))
        return

    x, y = (x, y) if x < y else (y, x)

    b = 2 * x - y
    if b % 3 != 0:
        print(0)
        return

    d1, d2 = b // 3, x - 2 * (b // 3)
    u = d1 + d2

    print(nCk(u, d1))


chker(_x, _y)


import sys
input = sys.stdin.readline

_x, _y = map(int, input().split())


def nCk(n, k, m=10 ** 9 + 7):
    a = b = 1
    k = min(k, n - k)
    for i in range(k):
        a = (a * (n - i)) % m
        b = (b * (i + 1)) % m

    return (a * pow(b, m - 2, m)) % m


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

    if x == y:
        b = x // 3
        print(nCk(2 * b, b))
        return

    x, y = (x, y) if x < y else (y, x)

    b = 2 * x - y
    if b % 3 != 0:
        print(0)
        return

    d1, d2 = b // 3, x - 2 * (b // 3)
    u = d1 + d2

    print(nCk(u, d1))


chker(_x, _y)


Verdicts: Runtime Error

Accepted
Problem: There is a knight - the chess piece - at the origin (0, 0) of a two- dimensional grid.  When the knight is at the square (i, j), it can be moved to either (i+1,j+2) or (i+2, j+1).  In how many ways can the knight reach the square (X, Y)?  Find the number of ways modulo 10^9 + 7.

Submission attempts (in order):
def cmb(n, r, p):
    return fact[n] * factinv[r] * factinv[n-r] % p

p = 10 ** 9 + 7
n = 4*10**5  
N = 2*n
fact = [1, 1]  # fact[n] = (n! mod p)
factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1]  
 
for i in range(2, N + 1):
    fact.append((fact[-1] * i) % p)
    if i <= n:
        inv.append((-inv[p % i] * (p // i)) % p)
        factinv.append((factinv[-1] * inv[-1]) % p)
    
X, Y = map(int, input().split())
if X+Y//3 != 0:
    result = 0
else:
    result = cmb((X+Y)//3, Y-(X+Y)//3, p)
print(result)

def cmb(n, r, p):
    return fact[n] * factinv[r] * factinv[n-r] % p

p = 10 ** 9 + 7
n = 4*10**5  
N = 2*n
fact = [1, 1]  # fact[n] = (n! mod p)
factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1]  
 
for i in range(2, N + 1):
    fact.append((fact[-1] * i) % p)
    if i <= n:
        inv.append((-inv[p % i] * (p // i)) % p)
        factinv.append((factinv[-1] * inv[-1]) % p)
    
X, Y = map(int, input().split())
if (X+Y)//3 != 0:
    result = 0
else:
    result = cmb((X+Y)//3, Y-(X+Y)//3, p)
print(result)


def cmb(n, r, p):
    return fact[n] * factinv[r] * factinv[n-r] % p

p = 10 ** 9 + 7
n = 4*10**5  
N = 2*n
fact = [1, 1]  # fact[n] = (n! mod p)
factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1]  
 
for i in range(2, N + 1):
    fact.append((fact[-1] * i) % p)
    if i <= n:
        inv.append((-inv[p % i] * (p // i)) % p)
        factinv.append((factinv[-1] * inv[-1]) % p)
    
X, Y = map(int, input().split())
if X+Y//3 != 0:
    result = 0
else:
    result = cmb((X+Y)//3, Y-(X+Y)//3)
print(result)

def cmb(n, r, p):
    return fact[n] * factinv[r] * factinv[n-r] % p

p = 10 ** 9 + 7
n = 7*10**5  
N = 2*n
fact = [1, 1]  # fact[n] = (n! mod p)
factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1]  

for i in range(2, N + 1):
    fact.append((fact[-1] * i) % p)
    if i <= n:
        inv.append((-inv[p % i] * (p // i)) % p)
        factinv.append((factinv[-1] * inv[-1]) % p)
X, Y = map(int, input().split())
if (X+Y)%3 != 0:
    result = 0
else:
    n = Y-(X+Y)//3
    m = X-(X+Y)//3
    if n<0 or m<0:
        result = 0
    else:
        result = cmb(n+m, n, p)
print(result)


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

if (2*x-y)%3!=0 or (2*x-y)<0:
  print(0)
  exit()
if (2*y-x)%3!=0 or (2*y-x)<0:
  print(0)
  exit()
p=int((2*x-y)/3)
q=int((2*y-x)/3)
M=2*(10**6)
Mod=10**9+7

fac=[0]*M
finv=[0]*M
inv=[0]*M

def COMinit():
  fac[0]=fac[1]=1
  finv[0]=finv[1]=1
  inv[1]=1
  for i in range(2,M):
    fac[i]=(fac[i-1]*i%Mod)%Mod
    inv[i]=Mod-inv[Mod%i]*(Mod//i) %Mod
    finv[i]=(finv[i-1]*inv[i]%Mod)%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)%Mod

COMinit()
print(COM(p+q,p))

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

if (2*x-y)%3!=0 or (2*x-y)<0:
  print(0)
  exit()
if (2*y-x)%3!=0 or (2*y-x)<0:
  print(0)
  exit()
p=int((2*x-y)/3)
q=int((2*y-x)/3)
M=p+q+2
Mod=10**9+7

fac=[0]*M
finv=[0]*M
inv=[0]*M

def COMinit():
  fac[0]=fac[1]=1
  finv[0]=finv[1]=1
  inv[1]=1
  for i in range(2,M):
    fac[i]=(fac[i-1]*i%Mod)%Mod
    inv[i]=Mod-inv[Mod%i]*(Mod//i) %Mod
    finv[i]=(finv[i-1]*inv[i]%Mod)%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)%Mod

COMinit()
print(COM(p+q,p))

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):
def prepare(n, MOD):
 
    
    f = 1
    for m in range(1, n + 1):
        f *= m
        f %= MOD
    fn = f
     
    
    inv = pow(f, MOD - 2, MOD)
    
    invs = [1] * (n + 1)
    invs[n] = inv
    for m in range(n, 1, -1):
        inv *= m
        inv %= MOD
        invs[m - 1] = inv
     
    return fn, invs
  
  mod = int(1e9+7)
X, Y = map(int, input().split())
if (X+Y)%3 != 0:
    print(0)
else:
    total_steps = (X+Y)//3
    dif_steps = abs(X-Y)
    if dif_steps > total_steps:
        print(0)
    else:
        up_steps = (total_steps - dif_steps)//2
        fn, invs = prepare(total_steps, mod)
        print((fn*invs[up_steps]*invs[total_steps-up_steps])%mod)

def prepare(n, MOD):
 
    
    f = 1
    for m in range(1, n + 1):
        f *= m
        f %= MOD
    fn = f
     
    
    inv = pow(f, MOD - 2, MOD)
    
    invs = [1] * (n + 1)
    invs[n] = inv
    for m in range(n, 1, -1):
        inv *= m
        inv %= MOD
        invs[m - 1] = inv
     
    return fn, invs
  
mod = int(1e9+7)
X, Y = map(int, input().split())
if (X+Y)%3 != 0:
    print(0)
else:
    total_steps = (X+Y)//3
    dif_steps = abs(X-Y)
    if dif_steps > total_steps:
        print(0)
    else:
        up_steps = (total_steps - dif_steps)//2
        fn, invs = prepare(total_steps, mod)
        print((fn*invs[up_steps]*invs[total_steps-up_steps])%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 math

N = 10 ** 9 + 7

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

B3 = 2 * X - Y

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

B = B3 // 3

A = X - 2 * B

print(A)
print(B)


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

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


import math

N = 10 ** 9 + 7
X, Y = map(int, input().split())
B3 = 2 * X - Y
if B3 % 3:
    print(0)
    exit()
B = B3 // 3
A = X - 2 * B
if A < 0 or B < 0:
    print(0)
    exit()

# count = 1

#     count *= i

#     count //= i
# print(count % N)


#     return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
#
# print(combinations_count(A + B, A) % N)

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(cmb(A + B,A) % N)






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 sys

x,y = map(int,input().split())
MOD = 10**9+7
N = 10**6
if (x+y)%3 != 0:
    print(0)
    sys.exit()
else:
    m = (2*x-y)//3
    n = (2*y-x)//3
    print(m)
    print(n)
    if n < 0 or m < 0:
        print(0)
        sys.exit()
    else:
        A = [1,1]
        B = [1,1]
        Inv = [0,1]
        for i in range(2,N+1):
            A.append((A[-1]*i)%MOD)
            Inv.append((-Inv[MOD%i]*(MOD//i))%MOD)
            B.append((B[-1]*Inv[-1])%MOD)
print(A[m+n]*B[m]*B[n]%MOD)

import sys

x,y = map(int,input().split())
MOD = 10**9+7
N = 10**6
if (x+y)%3 != 0:
    print(0)
    sys.exit()
else:
    m = (2*x-y)//3
    n = (2*y-x)//3
    if n < 0 or m < 0:
        print(0)
        sys.exit()
    else:
        A = [1,1]
        B = [1,1]
        Inv = [0,1]
        for i in range(2,N+1):
            A.append((A[-1]*i)%MOD)
            Inv.append((-Inv[MOD%i]*(MOD//i))%MOD)
            B.append((B[-1]*Inv[-1])%MOD)
print(A[m+n]*B[m]*B[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):
MOD = 1000000007
MAX = 2*10**6  # max n

fac = [0 for _ in range(MAX)]  # = n! (mod MOD)
finv = [0 for _ in range(MAX)]  # = 1/r! (mod MOD)
inv = [0 for _ in range(MAX)]  # = 1/r (mod MOD)


# init
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

def main():
    # input
    x, y = map(int, input().split())
    if (x+y)%3 == 0:
        num = (x+y)//3
        for i in range(num):
            if i + 2*(num-i) == x and 2*i + (num-i) == y:
                move = i
                break
        else:
            print(0)
            return
    else:
        print(0)
        return

    # calc
    COMinit()
    print(COM(num, move))


if __name__ == '__main__':
    main()


MOD = 1000000007
MAX = 10**6  # max n

fac = [0 for _ in range(MAX)]  # = n! (mod MOD)
finv = [0 for _ in range(MAX)]  # = 1/r! (mod MOD)
inv = [0 for _ in range(MAX)]  # = 1/r (mod MOD)


# init
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

def main():
    # input
    x, y = map(int, input().split())
    if (x+y)%3 == 0:
        num = (x+y)//3
        for i in range(num+1):
            if i + 2*(num-i) == x and 2*i + (num-i) == y:
                break
        else:
            print(0)
            return
    else:
        print(0)
        return

    # calc
    COMinit()
    print(COM(num, i))


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

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


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

if (2*Y-X)%3!=0 and (2*X-Y)%3!=0:
  print(0)
else:
  P=(2*X-Y)//3
  Q=(2*Y-X)//3
  #maxi=
  ans=comb((P+Q),P,(10**9+7))
  #ans=combinations((P+Q),P)
  print(ans)

def framod(x,p=10**9+7):
  a=1
  for i in range(1,x+1):
    a = (a*i)%p
  return a
#############################################
X,Y=map(int,input().split())
p=10**9+7

if (X+Y)%3!=0:
  print(0)
else:
  a = (2*X-Y)//3
  b = (2*Y-X)//3
  t = a+b
  if a<0 or b<0:
    print(0)
  else:
    S=framod(t)
    T=pow(framod(a),p-2,p)
    U=pow(framod(b),p-2,p)
    print(((S*T)%p)*U%p)

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):
def make_tables(m):
    fac=[1,1]
    finv=[1,1]
    inv=[0,1]
    for i in range(2,m+1):
        fac.append((fac[-1]*i)%mod)
        inv.append((-inv[mod%i]*(mod//i))%mod)
        finv.append(finv[i-1]*inv[i]%mod)
    return fac,finv
 calc_nCk(n,k,fac,finv):
    if n<k or (n<0 or k<0):
        return 0
    k=min(k,n-k)
    return fac[n]*(finv[k]*finv[n-k]%mod)%mod

x,y=map(int,input().split())
mod=10**9+7
n=(y-0.5*x)/1.5
if int(n)!=n:
    print(0)
else:
    m=(y+x)//3
    l=int(n)
    fac,finv=make_tables(m)
    ans = calc_nCk(m,l,fac,finv)
    print(ans)


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

def nCk(n,k):
  MAX_N=n+5
  fac = [1,1] + [0]*MAX_N
  finv = [1,1] + [0]*MAX_N
  inv = [0,1] + [0]*MAX_N
  for i in range(2,MAX_N):
    fac[i] = fac[i-1] * i % mod
    inv[i] = mod - inv[mod % i] * (mod // i) % mod
    finv[i] = finv[i-1] * inv[i] % mod
  
  if n<k:
    return 0
  if n<0 or k<0:
    return 0
  return fac[n] * (finv[k] * finv[n-k] % mod) % mod

n=(y-0.5*x)/1.5
if int(n)!=n:
    print(0)
else:
    m=(y+x)//3
    l=int(n)
    print(nCk(m,l))

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 sys
input = sys.stdin.readline
from math import factorial as fact

MOD = 10 ** 9 + 7


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


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


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

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

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









if __name__ == '__main__':
    main()



import sys
input = sys.stdin.readline

def modPow(a, x, p):
    res = 1
    while x > 0:
        if x % 2 != 0:
            res = res * a % p
        a = a * a % p
        x = x // 2
    return res

def modInverse(a, p):
    return modPow(a, p - 2, p)

def modBinomial(n, k, p):
    numerator = 1
    for i in range(k):
        numerator = (numerator * (n - i)) % p

    denominator = 1
    for i in range(1, k + 1):
        denominator = (denominator * i) % p

    return (numerator * modInverse(denominator, p)) % p


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

    MOD = 10 ** 9 + 7
    y = (X - 2 * Y) // (-3)
    x = (X - y) // 2

    if y < 0 or x < 0:
        print(0)
        exit()
    if X == x * 2 + y and Y == x + 2 * y:
        print(modBinomial(x + y, x, MOD))
    else:
        print(0)









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

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

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

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(fact[n+m]*factinv[n]*factinv[m]%P)


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

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

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

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(fact[n+m]*factinv[n]*factinv[m]%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):
def gho1(x):
  g=1
  for i in range(1,x+1):
    g*=i
  return g
def gho2(x):
  g=1
  for i in range(1,x+1):
    g*=i;g=g%(10**9+7)
  return g

q,w=map(int,input().split())
e,d=divmod((2*w-q),3)
r,f=divmod((2*q-w),3)

if d!=0 or f!=0:print(0)
else:
  print((gho(e+r)//(gho(e)*gho(r)))%(10*9+7))


x,y=map(int,input().split());n=0;mod=10**9+7;ans=0
if not (x+y)%3:
  n=(x+y)//3;x-=n;y-=n
  if x>=0 and y>=0:
    ans=1
    for i in range(x):ans=ans*(n-i)*pow(i+1,mod-2,mod)%mod
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):
def cmb(n,r,mod=10**9+7):
    fac = [0] * (n+1)
    finv = [0] * (n+1)
    inv = [0]*(n+1)

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

    if n < r: return 0
    if n < 0 or r < 0: return 0
    return (fac[n]*(finv[r]*finv[n-r]%mod)%mod)

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

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

i = (x+y)//3
j = x-i

print(cmd(i,j))

def cmd(n,r,mod=10**9+7):
    fac = [0] * (n+1)
    finv = [0] * (n+1)
    inv = [0]*(n+1)

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

    if n < r: return 0
    if n < 0 or r < 0: return 0
    return (fac[n]*(finv[r]*finv[n-r]%mod)%mod)

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

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

i = (x+y)//3
j = x-i

print(cmd(i,j))

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())
ans = 0
if max(x,y)-min(x,y)%3!=0:
  ans = (2**(max(x,y)-min(x,y)))%(10**9+7) 
print(ans)

x,y = map(int,input().split())
n = 0
mod = 10**9+7
ans = 0
if not (x+y)%3:
  n = (x+y)//3
  x-=n
  y-=n
  if x>=0 and y>=0:
    ans = 1
    for i in range(x):
      ans = ans*(n-i)*pow(i+1,mod-2,mod)%mod
print(ans)

Verdicts: Wrong Answer

Accepted