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

from operator import mul
from functools import reduce
def combination_count(n, r):
  r = min(n-r, r)
  num = reduce(modmul, range(n, n-r, -1), 1)
  denom = reduce(modmul, range(r, 1, -1), 1)
  return num*pow(denom, 10**9+5, 10**9+7)

def modmul(a, b):
  return mul(a,b)%(10**9+7)

def modinv(a, b):
  d, x, y = extgcd(a, b)
  return (d + x%b) % b

def gcd(a, b):
  if (b==0):
    return a
  else:
    return gcd(b, a%b)

def extgcd(a,b):
    r = [1,0,a]
    w = [0,1,b]
    while w[2]!=1:
        q = r[2]//w[2]
        r2 = w
        w2 = [r[0]-q*w[0],r[1]-q*w[1],r[2]-q*w[2]]
        r = r2
        w = w2
    #[x,y]
    return [w[0],w[1]]


if (x+y)%3 != 0:
  print('0')
else:
  m = (2*x - y)//3
  n = x - 2*m
  c = combination_count(m+n, m)
  print(c%(10**9+7))

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

from operator import mul
from functools import reduce
def combination_count(n, r):
  r = min(n-r, r)
  num = reduce(modmul, range(n, n-r, -1), 1)
  denom = reduce(modmul, range(r, 1, -1), 1)
  return num*mod_inv(denom,10**9+7)

def modmul(a, b):
  return mul(a,b)%(10**9+7)

def extgcd(a,b):
    r = [1,0,a]
    w = [0,1,b]
    while w[2]!=1:
        q = r[2]//w[2]
        r2 = w
        w2 = [r[0]-q*w[0],r[1]-q*w[1],r[2]-q*w[2]]
        r = r2
        w = w2
    #[x,y]
    return [w[0],w[1]]


def mod_inv(a,m):
    x = extgcd(a,m)[0]
    return (m+x%m)%m

if (x+y)%3 != 0:
  print('0')
else:
  m = (2*x - y)//3
  n = x - 2*m
  if m < 0 or n < 0:
    print('0')
  else:
    c = combination_count(m+n, m)
    print(c%(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())
MAX_NUM = 2*10**6 + 1
pr = 10**9+7
fac  = [0 for _ in range(MAX_NUM)]
finv = [0 for _ in range(MAX_NUM)]
inv  = [0 for _ in range(MAX_NUM)]
fac[0]  = fac[1] = 1
finv[0] = finv[1] = 1
inv[1] = 1
for i in range(2,MAX_NUM):
    fac[i] = fac[i-1] * i % pr
    inv[i] = pr - inv[pr%i] * (pr // i) % pr
    finv[i] = finv[i-1] * inv[i] % pr
def c(n,k):
    if n < k:
        return 0
    if n < 0 or k < 0:
        return 0
    return fac[n] * (finv[k] * finv[n-k] % pr) % pr
if (x+y)%3:
    print(0)
else:
    n=(x+y)//3
    x-=n
    y-=n
    print(c(x+y,x))


x,y=map(int,input().split())
MAX_NUM = 2*10**6 + 1
MAX_NUM//=3
MAX_NUM+=1
pr = 10**9+7
fac  = [0 for _ in range(MAX_NUM)]
finv = [0 for _ in range(MAX_NUM)]
inv  = [0 for _ in range(MAX_NUM)]
fac[0]  = fac[1] = 1
finv[0] = finv[1] = 1
inv[1] = 1
for i in range(2,MAX_NUM):
    fac[i] = fac[i-1] * i % pr
    inv[i] = pr - inv[pr%i] * (pr // i) % pr
    finv[i] = finv[i-1] * inv[i] % pr
def c(n,k):
    if n < k:
        return 0
    if n < 0 or k < 0:
        return 0
    return fac[n] * (finv[k] * finv[n-k] % pr) % pr
if (x+y)%3:
    print(0)
else:
    n=(x+y)//3
    x-=n
    y-=n
    print(c(x+y,x))


Verdicts: Time Limit Exceeded

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

Submission attempts (in order):
x,y=map(int,input().split())
mod=10**9+7
n_max=10**6+1
F,FI=[0]*(n_max+1),[0]*(n_max+1)
F[0],FI[0]=1,1
for i in range(n_max):
  F[i+1]=(F[i]*(i+1))%mod
  FI[i+1]=pow(F[i+1],mod-2,mod)
def comb(x,y):
  return (F[x]*FI[x-y]*FI[y])%mod
a,b=2*y-x,2*x-y
if a<0 or b<0:
  print(0)
elif a%3!=0 or b%3!=0:
  print(0)
else:
  a//=3
  b//=3
  print(comb(a+b,a))


import sys
input=lambda: sys.stdin.readline().rstrip()
mod=10**9+7
n_max=2*(10**6+1)
F,FI=[0]*(n_max+1),[0]*(n_max+1)
F[0],FI[0]=1,1
for i in range(n_max):
  F[i+1]=(F[i]*(i+1))%mod
FI[n_max-1]=pow(F[n_max-1],mod-2,mod)
for i in reversed(range(n_max-1)):
  FI[i]=(FI[i+1]*(i+1))%mod
def comb(x,y):
  return (F[x]*FI[x-y]*FI[y])%mod
x,y=map(int,input().split())
if (x+y)%3!=0:
  print(0)
else:
  n=(x+y)//3
  if x<n or y<n:
    print(0)
  else:
    print(comb(n,x-n))

Verdicts: Time Limit Exceeded

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

Submission attempts (in order):
import math

def comb(n, k, MOD, N):
    fact = [1]*(N+1)
    rfact = [1]*(N+1)
    r = 1
    for i in range(1, N+1):
        fact[i] = r = r * i % MOD
    rfact[N] = r = pow(fact[N], MOD-2, MOD)
    for i in range(N, 0, -1):
        rfact[i-1] = r = r * i % MOD
    return fact[n] * rfact[k] * rfact[n-k] % MOD

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

diff = abs(x-y)
if (min(x, y) - diff) % 3 != 0:
    print(0)
else:
    count = (min(x, y) - diff) // 3
    print(comb(2*count+diff, count, mod, 10**7))

import math

def comb(n, k, MOD, N):
    fact = [1]*(N+1)
    rfact = [1]*(N+1)
    r = 1
    for i in range(1, N+1):
        fact[i] = r = r * i % MOD
    rfact[N] = r = pow(fact[N], MOD-2, MOD)
    for i in range(N, 0, -1):
        rfact[i-1] = r = r * i % MOD
    return fact[n] * rfact[k] * rfact[n-k] % MOD

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

diff = abs(x-y)
if (min(x, y) - diff) % 3 != 0 or (min(x, y) - diff) < 0:
    print(0)
else:
    count = (min(x, y) - diff) // 3
    print(comb(2*count+diff, count, mod, 10**6))

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):
class Combination:
    
 
    def __init__(self, n, mod):
        self.fact = [1]
        for i in range(1, n + 1):
            self.fact.append(self.fact[-1] * i % mod)
        self.inv_fact = [pow(self.fact[i], mod - 2, mod) for i in range(n + 1)]
        self.mod = mod
 
    def factorial(self, k):
        
        return self.fact[k]
 
    def inverse_factorial(self, k):
        
        return self.inv_fact[k]
 
    def permutation(self, k, r):
        
        if k < r:
            return 0
        return (self.fact[k] * self.inv_fact[r]) % self.mod
 
    def combination(self, k, r):
        
        if k < r:
            return 0
        return (self.fact[k] * self.inv_fact[k - r] * self.inv_fact[r]) % self.mod

    def combination_large(self, k, r):
        
        if k < r:
            return 0
        res = 1
        for l in range(r):
            res *= (k - l)
            res %= self.mod
        return (res * self.inv_fact[r]) % self.mod

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

if (x+y)%3 != 0:
    print(0)
    exit(0)
i = (2*x-y)//3
j = (2*y-x)//3
print(comb.combination(i+j, i))


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

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

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


Verdicts: Time Limit Exceeded

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

Submission attempts (in order):
from scipy.misc import comb

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

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

N = (X+Y) // 3

A = X - N
B = Y - N

ans = comb(A+B, A) % MOD
print(ans)



from scipy.misc import comb

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

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

N = (X+Y) // 3

A = X - N
B = Y - N

ans = comb(A+B, A, exact=True) % MOD
print(ans)



def mod_inv(a, m):
    return pow(a, m-2, m)


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

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

n = (X + Y) // 3
nx, ny = X - n, Y - n

if nx < 0 or ny < 0:
    print(0)
    exit()

ans = 1
for i in range(nx + 1, nx + ny + 1):
    ans = ans * mod_inv(i, MOD) % MOD
for i in range(1, ny + 1):
    ans = ans * mod_inv(i, MOD) % MOD

print(ans)


def mod_inv(a, m):
    return pow(a, m-2, m)


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

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

n = (X + Y) // 3
nx, ny = X - n, Y - n

if nx < 0 or ny < 0:
    print(0)
    exit()

ans = 1
for i in range(nx + 1, nx + ny + 1):
    ans = ans * i % MOD
for i in range(1, ny + 1):
    ans = ans * mod_inv(i, MOD) % MOD

print(ans)



Verdicts: Wrong Answer

Time Limit Exceeded

Wrong Answer

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

Submission attempts (in order):
import math

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

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

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

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

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

print(ans)

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

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

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

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

mi = min(n,m)
num = n+m
mod = 10**9+7
a = 1
b = 1

for i in range(mi):
    a = a*(num-i)%mod
    b = b*(mi-i)%mod

print((a*pow(b,mod-2,mod))%mod)

Verdicts: Runtime Error

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

Submission attempts (in order):
# -*- coding: utf-8 -*-

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

ans = 0
if X % 2 == 0 and Y % 2 == 0:
    print(0)
else:
    for i in range(X):
        if X == (1 + 2) * i:
            a = i
    print(a)
    print((a * 2) % (10 ** 9 + 7))


# -*- coding: utf-8 -*-

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

N = 10 ** 6  
mod = pow(10, 9) + 7
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) % mod)
    inv.append((-inv[mod % i] * (mod // i)) % mod)
    factinv.append((factinv[-1] * inv[-1]) % mod)

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

if (2 * y - x) % 3 != 0 and (2 * x - y) % 3 != 0:
    print(0)
else:
    a = (2 * y - x) // 3
    b = (2 * x - y) // 3
    ans = cmb(a+b, a)
    print(ans % (pow(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())
tmp = 2*y - x
if tmp%3 != 0:
    print(0)
    exit()
up = tmp // 3
total = y - up*2 + up

n = total
k = up
mod = 10**9 + 7

print(n)
print(k)
print()

if k <= 0:
    print(1)
    exit()
#try:
modinv_table = [-1] * (k+1)
modinv_table[1] = 1
for i in range(2, k+1):
    modinv_table[i] = (-modinv_table[mod % i] * (mod // i)) % mod
#except:
    
    #modinv_table = [-1] * (k + 1)
    #modinv_table[1] = 1
    
        #modinv_table[i] = (-modinv_table[mod % i] * (mod // i)) % mod

def binomial_coefficients(n, k):
    ans = 1
    for i in range(k):
        ans *= n-i
        ans *= modinv_table[i + 1]
        ans %= mod
    return ans

print(binomial_coefficients(n, k))

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

n = total
k = up
mod = 10**9 + 7

#print(n)
#print(k)

if k == 0:
    print(1)
    exit()
try:
    modinv_table = [-1] * (k+1)
    modinv_table[1] = 1
    for i in range(2, k+1):
        modinv_table[i] = (-modinv_table[mod % i] * (mod // i)) % mod
except:
    k = total - up
    modinv_table = [-1] * (k + 1)
    modinv_table[1] = 1
    for i in range(2, k + 1):
        modinv_table[i] = (-modinv_table[mod % i] * (mod // i)) % mod

def binomial_coefficients(n, k):
    ans = 1
    for i in range(k):
        ans *= n-i
        ans *= modinv_table[i + 1]
        ans %= mod
    return ans

print(binomial_coefficients(n, k))

Verdicts: Wrong Answer

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

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

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




def comb_mod(n, r, MOD):
    if n < 0 or r < 0 or n < r:
        return 0

    factrial = [1] * (n+1)
    for k in range(1, n+1):
        factrial[k] = (factrial[k-1] * k) % MOD

    fact_inv = [1] * (n+1)
    fact_inv[n] = pow(factrial[n], MOD - 2, MOD)
    for k in range(n-1, -1, -1):
        fact_inv[k] = (fact_inv[k+1] * (k+1)) % MOD

    return (factrial[n] * fact_inv[r] * fact_inv[n-r]) % MOD

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

if (2*y-x)%3!=0 or (2*x-y)%3!=0:
    print(0)
else:
    k=(2*y-x)//3
    l=(2*x-y)//3
    a = comb_mod(k+l,l,10**9+7)
    print(a)


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 cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 
N = 10**6
g1 = [1, 1] 
g2 = [1, 1] 
inverse = [0, 1] 計算用テーブル

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

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

if diff > 0:
    x -= diff*2
    y -= diff
else:
    y -= diff*2
    x -= diff

if x%3 == 0:
    temp = x//3
    total = diff + temp*2
    ans = cmb(total, temp, mod)
else:
    ans = 0

print(ans)

x, y = map(int, input().split())
diff = abs(x - y)
ref = (min(x, y) - diff)//3
total = ref*2 + diff
mod = 10**9 + 7
ans = 1
ie = 1

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


for i in range(min(ref, total - ref)):
    ans = ans*(total - i)%mod
    ie = ie*(i + 1)%mod

ie = pow(ie, mod - 2, mod)
ans = ans*ie%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):
def cmb(n, k, mod, fac, infac):
  k = min(k,n-k)
  return fac[n] * infac[k] * infac[n-k] % mod

def tables(mod, n):
  fac = [1, 1] 
  infac = [1, 1] 
  inverse = [0, 1] 
  for i in range(2, n+1):
    fac.append((fac[-1] * i) % mod)
    inverse.append((-inverse[mod % i] * (mod // i)) % mod)
    infac.append((infac[-1] * inverse[-1]) % mod)
  return fac,infac

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

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

move = X + Y

if move % 3 != 0:
  print(0)
else:
  total = move // 3
  n = X - total
  
  if n > 0:
    print(0)
  else:
    MOD = 10 ** 9 + 7
    fac, infac = tables(MOD, total)
    ans = cmb(total, n, MOD, fac, infac)
    
    print(ans)

import math
from scipy.misc import comb

#def permod(n, r):
  #return (math.factorial(n) // math.factorial(n - r)) % (10 ** 9 + 7)

def main():
  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)
    
    ans = comb(total,m,exact = True)
    print(ans)
    
main()

X,Y = map(int,input().split())
M = max(X,Y)
m = min(X,Y)
mod = 10 ** 9 + 7

con = (X + Y) // 3
dif = M - m
n = (con - dif) // 2

if (X + Y) % 3 != 0 or n < 0:
  print(0)
  
else:
  def comb(n, r):
    n += 1
    over = 1
    under = 1
    for i in range(1,r + 1):
      over = over * (n - i) % mod
      under = under * i % mod
    
    return over * pow(under,mod - 2,mod) % mod
  
  ans = comb(con,n)
  
  print(ans)

Verdicts: Runtime Error

Time Limit Exceeded

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

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



if (X+Y)%3!=0:
    print("0")##immposible
else:
    a=((X+Y)//3+(X-Y))/2
    b=((X+Y)//3-(X-Y))/2
    ###(a+b)combination a!
    a=min(a,b)
    b=max(a,b)
    c=1
    d=1
    if a>0 and b>=0:
        for i in range(a):
            c*=(a+b-i)
            c=c%mod
            d*=(i+1)
            d=d%mod
        print((c*pow(d,mod-2,mod))%mod)
    elif a==0 and b>0:
        for i in range(b):
            c*=(b-i)
            c=c%mod
            print(c)
    else:
        print("0")

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



if (X+Y)%3!=0:
    print("0")##immposible
else:
    a=((X+Y)//3+(X-Y))//2
    b=((X+Y)//3-(X-Y))//2
    ###(a+b)combination a!
    a=min(a,b)
    b=max(a,b)
    c=1
    d=1
    print(a,b)
    if a>0 and b>=0:
        for i in range(a):
            c*=(a+b-i)
            c=c%mod
            d*=(i+1)
            d=d%mod
        print((c*pow(d,mod-2,mod))%mod)
    elif a==0 and b>0:
        print("1")
    else:
        print("0")

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



if (X+Y)%3!=0:
    print("0")##immposible
else:
    a=((X+Y)//3+(X-Y))/2
    b=((X+Y)//3-(X-Y))/2
    ###(a+b)combination a!
    a=min(a,b)
    b=max(a,b)
    c=1
    d=1
    if a>0 and b>=0:
        for i in range(a):
            c*=(a+b-i)
            c=c%mod
            d*=(i+1)
            d=d%mod
        print((c*pow(d,mod-2,mod))%mod)
    elif a==0 and b>0:
        for i in range(b):
            c*=(b-i)
            c=c%mod
        print(c)
    else:
        print("0")

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



if (X+Y)%3!=0:
    print("0")##immposible
else:
    a=min(((X+Y)//3+(X-Y))//2,((X+Y)//3-(X-Y))//2)
    b=max(((X+Y)//3+(X-Y))//2,((X+Y)//3-(X-Y))//2)
    ###(a+b)combination a
    c=1
    d=1
    if a>0 and b>=0:
        for i in range(a):
            c*=(a+b-i)
            c=c%mod
            d*=(i+1)
            d=d%mod
        print((c*pow(d,mod-2,mod))%mod)
    elif a==0 and b>0:
        print("1")
    else:
        print("0")

Verdicts: Runtime Error

Wrong Answer

Runtime Error

Accepted
Problem: Takahashi is at an all-you-can-eat restaurant.  The restaurant offers N kinds of dishes. It takes A_i minutes to eat the i-th dish, whose deliciousness is B_i.  The restaurant has the following rules:    * You can only order one dish at a time. The dish ordered will be immediately served and ready to eat.   * You cannot order the same kind of dish more than once.   * Until you finish eating the dish already served, you cannot order a new dish.   * After T-0.5 minutes from the first order, you can no longer place a new order, but you can continue eating the dish already served.  Let Takahashi's happiness be the sum of the deliciousness of the dishes he eats in this restaurant.  What is the maximum possible happiness achieved by making optimal choices?

Submission attempts (in order):
import numpy as np
n,t = map(int, input().split())
item = [None]*n
ans = 0
dp = np.zeros(t, dtype=int)

for i in range(n):
    a,b = map(int, input().split())
    item[i]=[a,b]
item.sort(key=lambda x:x[0])
print(item)

for i in range(n):
    a,b = item[i]
    ans = max(ans, dp.max()+b)
    dp[a:] = np.maximum(dp[a:], dp[:-a]+b)
    print("a:{},b:{}".format(a,b))
    print(dp)

print(ans)


import numpy as np
n,t = map(int, input().split())
item = [None]*n
ans = 0
dp = np.zeros(t, dtype=int)

for i in range(n):
    a,b = map(int, input().split())
    item[i]=[a,b]
item.sort(key=lambda x:x[0])

for i in range(n):
    a,b = item[i]
    ans = max(ans, dp.max()+b)
    dp[a:] = np.maximum(dp[a:], dp[:-a]+b)

print(ans)


Verdicts: Wrong Answer

Accepted
Problem: Takahashi is at an all-you-can-eat restaurant.  The restaurant offers N kinds of dishes. It takes A_i minutes to eat the i-th dish, whose deliciousness is B_i.  The restaurant has the following rules:    * You can only order one dish at a time. The dish ordered will be immediately served and ready to eat.   * You cannot order the same kind of dish more than once.   * Until you finish eating the dish already served, you cannot order a new dish.   * After T-0.5 minutes from the first order, you can no longer place a new order, but you can continue eating the dish already served.  Let Takahashi's happiness be the sum of the deliciousness of the dishes he eats in this restaurant.  What is the maximum possible happiness achieved by making optimal choices?

Submission attempts (in order):
N,T = map(int,input().split())
import numpy as np
A,B = np.array([list(map(int,input().split())) for _ in range(N)]).T
dp1 = np.array([[0]*T for _ in range(N+1)])
rev_A,rev_B = A[::-1],B[::-1]
dp2 = np.array([[0]*T for _ in range(N+1)])


for i in range(1,N+1):
  a = A[i-1]
  rev_a = rev_A[i-1]
  b = B[i-1]
  rev_b = rev_B[i-1]
  
  dp1[i,:a] = dp1[i-1,:a]
  dp2[i,:rev_a] = dp2[i-1,:rev_a]
  dp1[i,a:] = np.fmax(dp1[i-1,a:],dp1[i-1,:-a]+b)
  dp2[i,rev_a:] = np.fmax(dp2[i-1,rev_a:],dp2[i-1,:-rev_a]+rev_b)

      
lis = [0]*N
for i in range(1,N):
  lis[i-1] = (np.max(dp1[i-1]+dp2[N-i][::-1]) + B[i-1])
 
    
print(max(lis))

N,T = map(int,input().split())
import numpy as np
A,B = np.array([list(map(int,input().split())) for _ in range(N)]).T
dp1 = np.array([[0]*T for _ in range(N+1)])
rev_A,rev_B = A[::-1],B[::-1]
dp2 = np.array([[0]*T for _ in range(N+1)])


for i in range(1,N+1):
  a = A[i-1]
  rev_a = rev_A[i-1]
  b = B[i-1]
  rev_b = rev_B[i-1]
  
  dp1[i,:a] = dp1[i-1,:a]
  dp2[i,:rev_a] = dp2[i-1,:rev_a]
  dp1[i,a:] = np.fmax(dp1[i-1,a:],dp1[i-1,:-a]+b)
  dp2[i,rev_a:] = np.fmax(dp2[i-1,rev_a:],dp2[i-1,:-rev_a]+rev_b)

      
lis = [0]*N
for i in range(1,N+1):
  lis[i-1] = (np.max(dp1[i-1]+dp2[N-i][::-1]) + B[i-1])
 
    
print(max(lis))

Verdicts: Wrong Answer

Accepted
Problem: Takahashi is at an all-you-can-eat restaurant.  The restaurant offers N kinds of dishes. It takes A_i minutes to eat the i-th dish, whose deliciousness is B_i.  The restaurant has the following rules:    * You can only order one dish at a time. The dish ordered will be immediately served and ready to eat.   * You cannot order the same kind of dish more than once.   * Until you finish eating the dish already served, you cannot order a new dish.   * After T-0.5 minutes from the first order, you can no longer place a new order, but you can continue eating the dish already served.  Let Takahashi's happiness be the sum of the deliciousness of the dishes he eats in this restaurant.  What is the maximum possible happiness achieved by making optimal choices?

Submission attempts (in order):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N, T = map(int, readline().split())

AB= list(map(int, read().split()))
A = AB[0::2]
B = AB[1::2]
ls = sorted(zip(A, B))

deli = [0]*N
deli[- 1] = ls[-1][- 1]
for i in range(N - 2, 0, - 1):
    deli[i] = max(deli[i + 1], ls[i][- 1])

res = 0
dp = [0]*T
for i in range(N - 1):
    a, b = ls[i]
    for j in range(T - 1, a - 1, - 1):
        dp[j] = max(dp[j], dp[j - a] + b)
    if res > dp[- 1] + deli[i + 1]:
        res = max(res, dp[- 1] + deli[i + 1])
print(res)

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
 
import numpy as np
 
N,T = map(int,readline().split())
m = map(int,read().split())
AB = sorted(zip(m,m))
 
can_add = [0] * N
for n in range(N-1,0,-1):
    x = can_add[n]
    y = AB[n][1]
    can_add[n-1] = x if x > y else y
dp = np.zeros(T,np.int64)
 
answer = 0
for i,(a,b) in enumerate(AB):
    np.maximum(dp[a:], dp[:-a] + b, out = dp[a:])
    x = dp.max() + can_add[i]
    if answer < x:
        answer = x
print(answer)

Verdicts: Wrong Answer

Accepted
Problem: Takahashi is at an all-you-can-eat restaurant.  The restaurant offers N kinds of dishes. It takes A_i minutes to eat the i-th dish, whose deliciousness is B_i.  The restaurant has the following rules:    * You can only order one dish at a time. The dish ordered will be immediately served and ready to eat.   * You cannot order the same kind of dish more than once.   * Until you finish eating the dish already served, you cannot order a new dish.   * After T-0.5 minutes from the first order, you can no longer place a new order, but you can continue eating the dish already served.  Let Takahashi's happiness be the sum of the deliciousness of the dishes he eats in this restaurant.  What is the maximum possible happiness achieved by making optimal choices?

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

n,t = (int(i) for i in input().split())


ab = [[int(i) for i in input().split()] for i in range(n)]
# 0:weight 1:value

ab = sorted(ab,key=lambda x: x[1])

dp = np.zeros((n+1,t),int)
dp2 = np.zeros((n+1,t),int)

for i in range(n):
    for w in range(t):
        if w >= ab[i][0] :
            dp[i+1][w] = np.max(dp[i][w-ab[i][0]] + ab[i][1], dp[i][w])
        else:
            dp[i+1][w] = dp[i][w]
        if w >= ab[i][0] :
            dp2[i+1][w] = np.max(dp2[i][w-ab[i][0]] + ab[i][1],dp[i][w] + ab[i][1], dp[i][w])
        else:
            dp2[i+1][w] = np.max(dp[i][w] + ab[i][1], dp[i][w])

answer =0
for i in range(n+1):
    for w in range(t):
        answer = np.max(answer, dp2[i][w])
print(answer)

#print(dp2)


#
import sys
import math
import numpy as np
import itertools

n,t = (int(i) for i in input().split())


ab = [[int(i) for i in input().split()] for i in range(n)]
# 0:weight 1:value

ab = sorted(ab,key=lambda x: x[1])

dp = np.zeros((n+1,t),int)
dp2 = np.zeros((n+1,t),int)

for i in range(n):
    for w in range(t):
        if w >= ab[i][0] :
            dp[i+1][w] = max(dp[i][w-ab[i][0]] + ab[i][1], dp[i][w])
        else:
            dp[i+1][w] = dp[i][w]
        if w >= ab[i][0] :
            dp2[i+1][w] = max(dp2[i][w-ab[i][0]] + ab[i][1],dp[i][w] + ab[i][1], dp[i][w])
        else:
            dp2[i+1][w] = max(dp[i][w] + ab[i][1], dp[i][w])

answer =0

#    for w in range(t):

print(answer)

#print(dp2)


#
import sys
import math
import numpy as np
import itertools

n,t = (int(i) for i in input().split())


ab = [[int(i) for i in input().split()] for i in range(n)]
# 0:weight 1:value

ab = sorted(ab,key=lambda x: x[1])

dp = np.zeros((n+1,t),int)
dp2 = np.zeros((n+1,t),int)

for i in range(n):
    w = ab[i][0]
    dp[i+1][w:] = np.fmax(dp[i][:-w] + ab[i][1], dp[i][w:])
    dp2[i+1][w:] = np.fmax(dp2[i][:-w] + ab[i][1],dp[i][w:] + ab[i][1], dp2[i][w:])
    dp[i+1][:w] = dp[i][:w]
    dp2[i+1][:w] = np.fmax(dp[i][:w] + ab[i][1], dp2[i][:w])

answer = np.amax(dp2)
print(answer)



Verdicts: Runtime Error

Wrong Answer

Accepted
Problem: Takahashi is at an all-you-can-eat restaurant.  The restaurant offers N kinds of dishes. It takes A_i minutes to eat the i-th dish, whose deliciousness is B_i.  The restaurant has the following rules:    * You can only order one dish at a time. The dish ordered will be immediately served and ready to eat.   * You cannot order the same kind of dish more than once.   * Until you finish eating the dish already served, you cannot order a new dish.   * After T-0.5 minutes from the first order, you can no longer place a new order, but you can continue eating the dish already served.  Let Takahashi's happiness be the sum of the deliciousness of the dishes he eats in this restaurant.  What is the maximum possible happiness achieved by making optimal choices?

Submission attempts (in order):
import sys
import numpy as np
sys.setrecursionlimit(10 ** 7)

N, T = map(int, input().split())
FOOD = [[int(x) for x in input().split()] for _ in range(N)]

FOOD.sort(reverse=True, key=lambda x: x[1])
dp = np.array([np.zeros(T+1, dtype=np.int64) for _ in range(N + 1)])
for i in range(N):
    a, b = FOOD[i]
    dp[i + 1][a:] = np.maximum(dp[i][:-a] + b, dp[i][a:])

    if len(dp[i][-a+1:T]) > 0:
        dp[i + 1][T] = max(dp[i + 1][T], max(dp[i][-a+1:T]) + b)


print(dp[N][T])


import sys
import numpy as np
sys.setrecursionlimit(10 ** 7)





N, T = map(int, input().split())
FOOD = [[int(x) for x in input().split()] for _ in range(N)]

FOOD.sort()
dp = np.array([np.zeros(T + 1, dtype=np.int64) for _ in range(N + 1)])
ans = 0
for i in range(N):
    a, b = FOOD[i]
    dp[i + 1][a:] = np.maximum(dp[i][:-a] + b, dp[i][a:])

    # if len(dp[i][-a+1:T]) > 0:
    # dp[i + 1][T] = max(dp[i + 1][T], max(dp[i][-a+1:T]) + b)
    now = 0
    if i != N-1:
        now = dp[i + 1][T - 1] + max(FOOD[i + 1:], key=lambda x: x[1])[1]
        #print(FOOD[i + 1:])
        #print(max(FOOD[i + 1:], key=lambda x: x[1])[1])
        #print(now)

    ans = max(ans, now)

    # print(dp[i+1])

print(ans)


Verdicts: Wrong Answer

Accepted
Problem: Takahashi is at an all-you-can-eat restaurant.  The restaurant offers N kinds of dishes. It takes A_i minutes to eat the i-th dish, whose deliciousness is B_i.  The restaurant has the following rules:    * You can only order one dish at a time. The dish ordered will be immediately served and ready to eat.   * You cannot order the same kind of dish more than once.   * Until you finish eating the dish already served, you cannot order a new dish.   * After T-0.5 minutes from the first order, you can no longer place a new order, but you can continue eating the dish already served.  Let Takahashi's happiness be the sum of the deliciousness of the dishes he eats in this restaurant.  What is the maximum possible happiness achieved by making optimal choices?

Submission attempts (in order):
import sys
sys.setrecursionlimit(10 ** 7)

N, T = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(N)]
AB.sort(key=lambda x: x[0])
print(AB)
def dfs(i, sum, time, remain):
    global answer
    if i == N or time + AB[i][0] > T:
        if time < T and len(remain) >= 1:
            sum += AB[min(remain)][1]
        if sum > answer:
            answer = sum
    else:
        dfs(i+1, sum, time, remain)
        if time < T:
            dfs(i+1, sum + AB[i][1], time + AB[i][0], remain-{i})

answer = 0
dfs(0, 0, 0, set(range(N)))
print(answer)

N, T = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(N)]
AB.sort()
dp = [[0] * 3000 for i in range(N+1)]
answer = 0
for i in range(1, N-1):
    a, b = AB[i]
    for j in range(a, 3000):
        dp[i][j] = max(dp[i-1][j], dp[i-1][j-a] + b)
    result = dp[i][T-1] + sorted(AB[i+1:], key=lambda x:x[1])[-1][1]
    if result > answer:
        answer = result
print(answer)

import sys
import numpy as np

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N, T = lr()
AB = [lr() for _ in range(N)]
AB.sort()

dp = np.zeros(T, np.int64)
answer = 0
for a, b in AB:
    answer = max(answer, dp.max() + b)
    prev = dp
    dp[a:] = np.maximum(prev[a:], prev[:-a] + b)

print(answer)


Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: Takahashi is at an all-you-can-eat restaurant.  The restaurant offers N kinds of dishes. It takes A_i minutes to eat the i-th dish, whose deliciousness is B_i.  The restaurant has the following rules:    * You can only order one dish at a time. The dish ordered will be immediately served and ready to eat.   * You cannot order the same kind of dish more than once.   * Until you finish eating the dish already served, you cannot order a new dish.   * After T-0.5 minutes from the first order, you can no longer place a new order, but you can continue eating the dish already served.  Let Takahashi's happiness be the sum of the deliciousness of the dishes he eats in this restaurant.  What is the maximum possible happiness achieved by making optimal choices?

Submission attempts (in order):
N , T = map(int,input().split(' '))
AB = []
for _ in range(N):
    AB.append(list(map(int,input().split())))
print(AB)

dp = [-1] * (T+3000)
dp[0] = 0
for a,b in sorted(AB):
    for i in range(T-1,-1,-1):
        if dp[i] == -1:
            continue
        if dp[i+a] < dp[i] + b:
            dp[i+a] = dp[i] +b 
print(max(dp))

import numpy as np
 
N, T = map(int, input().split())
data = []
for i in range(N):
  a, b = map(int, input().split())
  data.append((a,b))
data.sort()
data = np.array(data)

dp = np.zeros(T)
ans = 0
for a, b in data:
    ans = max(ans,dp[-1]+b)
    if a< T:
        newtable = dp[:T-a] + b
        dp[a:] = np.maximum(dp[a:], newtable)

print(int(ans))

Verdicts: Wrong Answer

Accepted
Problem: Takahashi is at an all-you-can-eat restaurant.  The restaurant offers N kinds of dishes. It takes A_i minutes to eat the i-th dish, whose deliciousness is B_i.  The restaurant has the following rules:    * You can only order one dish at a time. The dish ordered will be immediately served and ready to eat.   * You cannot order the same kind of dish more than once.   * Until you finish eating the dish already served, you cannot order a new dish.   * After T-0.5 minutes from the first order, you can no longer place a new order, but you can continue eating the dish already served.  Let Takahashi's happiness be the sum of the deliciousness of the dishes he eats in this restaurant.  What is the maximum possible happiness achieved by making optimal choices?

Submission attempts (in order):
import numpy as np
n,t=map(int,input().split())
s=[list(map(int,input().split()))for i in range(n)]
a,b=np.zeros((n+1,t+1)),np.zeros((n+1,t+1))
for i in range(n):
    a[i+1]=a[i]
    a[i+1][s[i][0]:]=np.maximum(a[i+1][s[i][0]:],a[i][:t+1-s[i][0]]+s[i][1])
    b[n-i-1]=b[n-i]
    b[n-i-1][s[n-i-1][0]:]=np.maximum(b[n-i-1][s[n-i-1][0]:],b[n-i][:t-s[n-i-1][0]+1]+s[n-i-1][1])
p=0
print(a,b)
for i in range(n):
    for j in range(t):
        p=max(p,a[i][j]+b[i+1][t-1-j]+s[i][1])
print(int(p))

import numpy as np
n,t=map(int,input().split())
s=[list(map(int,input().split()))for i in range(n)]
a,b=np.zeros((n+1,t+1)),np.zeros((n+1,t+1))
for i in range(n):
    a[i+1]=a[i]
    a[i+1][s[i][1]:]=np.maximum(a[i+1][s[i][1]:],a[i][:t+1-s[i][1]]+s[i][0])
    b[n-i-1]=b[n-i]
    b[n-i-1][s[n-i-1][1]:]=np.maximum(b[n-i-1][s[n-i-1][1]:],b[n-i][:t-s[n-i-1][1]+1]+s[n-i-1][0])
p=0
for i in range(n):
    for j in range(t+1):
        p=max(p,a[i][j]+b[i+1][t-j]+s[i][0])
print(int(p))

import numpy as np
n,t=map(int,input().split())
a=[list(map(int,input().split()))for i in range(n)]
b=np.zeros((n+1,t))
c=np.zeros((n+1,t))
for i in range(n):
    b[i+1]=b[i]
    b[i+1][a[i][0]:]=np.maximum(b[i+1][a[i][0]:],b[i][:-a[i][0]]+a[i][1])
    c[-i-2]=c[-i-1]
    c[-i-2][a[-i-1][0]:]=np.maximum(c[-i-2][a[-i-1][0]:],c[-i-1][:-a[-i-1][0]]+a[-i-1][1])
q=0
for i in range(n):
    q=max(q,max(b[i]+c[i+1][::-1])+a[i][1])
print(int(q))

Verdicts: Runtime Error

Runtime Error

Accepted
Problem: Takahashi is at an all-you-can-eat restaurant.  The restaurant offers N kinds of dishes. It takes A_i minutes to eat the i-th dish, whose deliciousness is B_i.  The restaurant has the following rules:    * You can only order one dish at a time. The dish ordered will be immediately served and ready to eat.   * You cannot order the same kind of dish more than once.   * Until you finish eating the dish already served, you cannot order a new dish.   * After T-0.5 minutes from the first order, you can no longer place a new order, but you can continue eating the dish already served.  Let Takahashi's happiness be the sum of the deliciousness of the dishes he eats in this restaurant.  What is the maximum possible happiness achieved by making optimal choices?

Submission attempts (in order):
import sys
input = sys.stdin.buffer.readline
from operator import itemgetter
import numpy as np

def main():
    N,T = map(int,input().split())
    food = []
    for _ in range(N):
        a,b = map(int,input().split())
        food.append((a,b))
        
    dp = np.zeros(T,dtype=int)
    food.sort(key = itemgetter(0))
    
    ans = 0
    for a,b in food:
        ans = max(ans,dp[-1]+b)
        dp[a:] = np.maximum(dp[a:],dp[:-a]+b)
        print(dp)

    print(ans)
    
if __name__ == "__main__":
    main()

import sys
input = sys.stdin.buffer.readline
from operator import itemgetter
import numpy as np

def main():
    N,T = map(int,input().split())
    food = []
    for _ in range(N):
        a,b = map(int,input().split())
        food.append((a,b))
        
    dp = np.zeros(T,dtype=int)
    food.sort(key = itemgetter(0))
    
    ans = 0
    for a,b in food:
        ans = max(ans,dp[-1]+b)
        dp[a:] = np.maximum(dp[a:],dp[:-a]+b)

    print(ans)
    
if __name__ == "__main__":
    main()

Verdicts: Wrong Answer

Accepted
Problem: Takahashi is at an all-you-can-eat restaurant.  The restaurant offers N kinds of dishes. It takes A_i minutes to eat the i-th dish, whose deliciousness is B_i.  The restaurant has the following rules:    * You can only order one dish at a time. The dish ordered will be immediately served and ready to eat.   * You cannot order the same kind of dish more than once.   * Until you finish eating the dish already served, you cannot order a new dish.   * After T-0.5 minutes from the first order, you can no longer place a new order, but you can continue eating the dish already served.  Let Takahashi's happiness be the sum of the deliciousness of the dishes he eats in this restaurant.  What is the maximum possible happiness achieved by making optimal choices?

Submission attempts (in order):
# E
import numpy as np
N, T = map(int, input().split())
# A=cost. B=value
A, B = np.array([input().split() for _ in range(N)], dtype=int).T

weight,value = A, B

d0 = np.zeros((N,T),int)

d1 = np.zeros((N,T),int)

d0[0,weight[0]:] = value[0]
d1[0,:] = value[0]

for n in range(1, N):
  for w in range(T):
    if (w >= weight[n]):
      d0[n][w] = np.max(d0[n-1][w-weight[n]] + value[n], d0[n-1][w])
      d1[n][w] = np.max(d1[n-1][w-weight[n]] + value[n], d1[n-1][w], d0[n-1][w] + value[n])
    else:
      d0[n][w] = d0[n-1][w]
      d1[n][w] = np.max(d1[n-1][w], d0[n-1][w] + value[n])

print(d1[-1,-1])

# E
import numpy as np
N, T = map(int, input().split())
# A=cost. B=value
A, B = np.array([input().split() for _ in range(N)], dtype=int).T

weight,value = A, B

d0 = np.zeros((N,T),int)

d1 = np.zeros((N,T),int)

d0[0,weight[0]:] = value[0]
d1[0,:] = value[0]

for n in range(1, N):
  w = weight[n]
  # w < weight[n]
  d0[n][:w] = d0[n-1][:w]
  d1[n][:w] = np.fmax(d1[n-1][:w], d0[n-1][:w] + value[n])
  # w >= weight[n]
  d0[n][w:] = np.fmax(d0[n-1][:-w] + value[n], d0[n-1][w:])
  d1[n][w:] = np.fmax(np.fmax(d1[n-1][:-w] + value[n], d1[n-1][w:]), d0[n-1][w:] + value[n])

print(d1[-1,-1])

Verdicts: Runtime Error

Accepted
Problem: Takahashi is at an all-you-can-eat restaurant.  The restaurant offers N kinds of dishes. It takes A_i minutes to eat the i-th dish, whose deliciousness is B_i.  The restaurant has the following rules:    * You can only order one dish at a time. The dish ordered will be immediately served and ready to eat.   * You cannot order the same kind of dish more than once.   * Until you finish eating the dish already served, you cannot order a new dish.   * After T-0.5 minutes from the first order, you can no longer place a new order, but you can continue eating the dish already served.  Let Takahashi's happiness be the sum of the deliciousness of the dishes he eats in this restaurant.  What is the maximum possible happiness achieved by making optimal choices?

Submission attempts (in order):
def main():
  N,T=map(int,input().split())
  L=[[int(x) for x in input().split()] for _ in range(N)]
  L.sort(key=lambda x:x[1])
  dp=[[0]*T for _ in range(2)]

  for i in range(N-1):
    for j in range(T):
      if L[i][0]>j:
        dp[-~i%2][j]=dp[i%2][j]
      else:
        dp[-~i%2][j]=max(dp[i%2][j],dp[i%2][j-L[i][0]]+L[i][1])
  print(max(dp[(N-1)%2])+L[N-1][1])

if __name__ == 'main':
  main()


def main():
  N,T=map(int,input().split())
  L=[[int(x) for x in input().split()] for _ in range(N)]
  L.sort(key=lambda x:x[0])
  dp=[0]+[-1]*(T+L[-1][0])

  for a,b in L:
    for j in range(T-1,-1,-1):
      if dp[j]>=0 and dp[j+a]<dp[j]+b:
        dp[j+a]=dp[j]+b

  print(max(dp))

if __name__ == '__main__':
  main()


Verdicts: Wrong Answer

Accepted
Problem: Takahashi is at an all-you-can-eat restaurant.  The restaurant offers N kinds of dishes. It takes A_i minutes to eat the i-th dish, whose deliciousness is B_i.  The restaurant has the following rules:    * You can only order one dish at a time. The dish ordered will be immediately served and ready to eat.   * You cannot order the same kind of dish more than once.   * Until you finish eating the dish already served, you cannot order a new dish.   * After T-0.5 minutes from the first order, you can no longer place a new order, but you can continue eating the dish already served.  Let Takahashi's happiness be the sum of the deliciousness of the dishes he eats in this restaurant.  What is the maximum possible happiness achieved by making optimal choices?

Submission attempts (in order):
import numpy as np
n,t=map(int,input().split())
ab=[list(map(int,input().split())) for _ in range(n)]
dp1=np.zeros((n+1,3001),np.int64)
dp2=np.zeros((n+2,3001),np.int64)


for i in range(n):
  a,b=ab[i]
  dp1[i+1,a:]=np.maximum(dp1[i,a:],dp1[i,:-a]+b)
  j=n-i
  a,b=ab[j-1]
  dp2[j,a:]=np.maximum(dp2[j+1,a:],dp2[j+1,:-a]+b)
ans=0
for i in range(1,n+1):
  ai=max([dp1[i-1][j]+dp2[i+1][t-1-j]+ab[i-1][1] for j in range(t)])
  ans=max(ans,ai)
print(ans)
print(dp2[n,:25])
print(dp2[n+1])

n,t=map(int,input().split())
ab=[list(map(int,input().split())) for _ in range(n)]
ab.sort(key=lambda x:x[0])
import numpy as np
ans=0
dp=np.zeros(t,np.int64)

for i in range(n):
  a,b=ab[i]
  ans=max(ans,dp[-1]+b)
  dp[a:]=np.maximum(dp[a:],dp[:-a]+b)
print(ans)


Verdicts: Wrong Answer

Accepted
Problem: Takahashi is at an all-you-can-eat restaurant.  The restaurant offers N kinds of dishes. It takes A_i minutes to eat the i-th dish, whose deliciousness is B_i.  The restaurant has the following rules:    * You can only order one dish at a time. The dish ordered will be immediately served and ready to eat.   * You cannot order the same kind of dish more than once.   * Until you finish eating the dish already served, you cannot order a new dish.   * After T-0.5 minutes from the first order, you can no longer place a new order, but you can continue eating the dish already served.  Let Takahashi's happiness be the sum of the deliciousness of the dishes he eats in this restaurant.  What is the maximum possible happiness achieved by making optimal choices?

Submission attempts (in order):
from numpy import zeros, maximum
N, T, *AB = map(int, open(0).read().split()) 
print(AB)
dp = zeros(6010, int)
for w, v in sorted(zip(*[iter(AB)] * 2)):
  dp[w:T + w] = maximum(dp[w:T + w], dp[:T] + v)
print(dp.max())

from numpy import zeros, maximum
N, T, *AB = map(int, open(0).read().split()) 
dp = zeros(6010, int)
for w, v in sorted(zip(*[iter(AB)] * 2)):
  dp[w:T + w] = maximum(dp[w:T + w], dp[:T] + v)
print(dp.max())

Verdicts: Wrong Answer

Accepted
Problem: Takahashi is at an all-you-can-eat restaurant.  The restaurant offers N kinds of dishes. It takes A_i minutes to eat the i-th dish, whose deliciousness is B_i.  The restaurant has the following rules:    * You can only order one dish at a time. The dish ordered will be immediately served and ready to eat.   * You cannot order the same kind of dish more than once.   * Until you finish eating the dish already served, you cannot order a new dish.   * After T-0.5 minutes from the first order, you can no longer place a new order, but you can continue eating the dish already served.  Let Takahashi's happiness be the sum of the deliciousness of the dishes he eats in this restaurant.  What is the maximum possible happiness achieved by making optimal choices?

Submission attempts (in order):
def solve():
    from sys import stdin
    #f_i = stdin
    f_i = open('ABC_145_E_in_s3')#
    
    N, T = map(int, f_i.readline().split())
    AB = [tuple(map(int, f_i.readline().split())) for i in range(N)]
    AB.sort()
    
    dp = [[0] * T for i in range(N + 1)]
    
    for i, AB_i in enumerate(AB, start=1):
        A_i, B_i = AB_i
        for j in range(A_i, T):
            dp[i][j] = max(dp[i-1][j], dp[i-1][j-A_i] + B_i)
    
    ans = max(dp[k][-1] + AB[k][1] for k in range(N))
    print(ans)

solve()

def solve():
    from sys import stdin
    #f_i = stdin
    f_i = open('ABC_145_E_in_s4')#
    
    N, T = map(int, f_i.readline().split())
    AB = [tuple(map(int, f_i.readline().split())) for i in range(N)]
    AB.sort()
    
    dp = [[0] * T for i in range(N + 1)]
    
    for i, AB_i in enumerate(AB, start=1):
        A_i, B_i = AB_i
        dp_i = dp[i]
        dp_pre = dp[i-1]
        for j, t in enumerate(zip(dp_pre[A_i:], dp_pre), start=A_i):
            x, y = t
            if x < y + B_i:
                dp_i[j] = y + B_i
            else:
                dp_i[j] = x
    
    ans = max(dp[k][-1] + AB[k][1] for k in range(N))
    ans = max(ans, dp[-1][-1])
    print(ans)

solve()

def solve():
    import numpy as np
    from sys import stdin
    f_i = stdin
    
    N, T = map(int, f_i.readline().split())
    AB = [tuple(map(int, f_i.readline().split())) for i in range(N)]
    AB.sort()
    max_Ai = AB[-1][0]
    
    dp = [[0] * T for i in range(N + 1)]
    dp = np.zeros(max_Ai + T, dtype=int)
    
    
    for A_i, B_i in AB:
        dp[A_i:A_i+T] = np.maximum(dp[A_i:A_i+T], dp[:T] + B_i)
    
    print(max(dp))

solve()

Verdicts: Runtime Error

Runtime Error

Accepted