Buggy python submission (verdict: Time Limit Exceeded):
N, W = map(int, input().split())

dp = [0]  * (W + 1)
items = []
for i in range(N):
  w, v = map(int, input().split())
  items.append((w, v))

for w, v in items:  
  for wk in range(W, w - 1, -1):
    tv = dp[wk - w] + v
    if tv > dp[wk]:
      dp[wk] = tv
res = max(dp)
print(res)


Fixed submission:
def nap(n, cap):
    val = [0] * (cap + 1)
    for _ in range(n):
        w, v = map(int, input().split())
        for wk in range(cap, w - 1, -1):
            nv = val[wk - w] + v
            if val[wk] < nv:
                val[wk] = nv
    return max(val)


n, cap = map(int, input().split())
print(nap(n, cap))

Buggy python submission (verdict: Runtime Error):
import sys
 
input = sys.stdin.readline
 
def nap(n, cap):
    val = [0] * (cap + 1)
    for _ in range(n):
        w, v = map(int, input().split())
        for wk in range(cap, w - 1, -1):
            nv = val[wk - w] + v
            if val[wk] < nv:
                val[wk] = nv
    return max(val)
 
 
n, cap = map(int, input().split())
print(nap(n, cap)

Fixed submission:
def nap(n, cap):
    val = [0] * (cap + 1)
    for _ in range(n):
        w, v = map(int, input().split())
        for wk in range(cap, w - 1, -1):
            nv = val[wk - w] + v
            if val[wk] < nv:
                val[wk] = nv
    return max(val)


n, cap = map(int, input().split())
print(nap(n, cap))

Buggy python submission (verdict: Runtime Error):
def nap(n, cap):
    val = [0] * (cap + 1)
    for _ in range(n):
        w, v = map(int, input().split())
        for wk in range(cap, w - 1, -1):
            nv = val[wk - w] + v
            if val[wk] < nv:
                val[wk] = nv
    return max(val)
 
 
n, cap = map(int, input().split())
print(nap(n, cap)

Fixed submission:
def nap(n, cap):
    val = [0] * (cap + 1)
    for _ in range(n):
        w, v = map(int, input().split())
        for wk in range(cap, w - 1, -1):
            nv = val[wk - w] + v
            if val[wk] < nv:
                val[wk] = nv
    return max(val)


n, cap = map(int, input().split())
print(nap(n, cap))

Buggy python submission (verdict: Time Limit Exceeded):
N, W = map(int, input().split())

dp = [0]  * (W + 1)
items = []
for i in range(N):
  w, v = map(int, input().split())
  items.append((w, v))
  
for w, v in items:
  for wk in range(W, w - 1, -1):
    tv = dp[wk - w] + v
    if tv > dp[wk]:
      dp[wk] = tv
print(max(dp))


Fixed submission:
def nap(n, cap):
    val = [0] * (cap + 1)
    for _ in range(n):
        w, v = map(int, input().split())
        for wk in range(cap, w - 1, -1):
            nv = val[wk - w] + v
            if val[wk] < nv:
                val[wk] = nv
    return max(val)


n, cap = map(int, input().split())
print(nap(n, cap))

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input=sys.stdin.readline

N, W = map(int, input().split())

dp = [0 for j in range(W + 1)]
items = []
for i in range(N):
  w, v = map(int, input().split())
  items.append((w, v))
  
for w, v in items:
  for wk in range(W, w - 1, -1):
    tv = dp[wk - w] + v
    if tv > dp[wk]:
      dp[wk] = tv
print(max(dp))


Fixed submission:
def nap(n, cap):
    val = [0] * (cap + 1)
    for _ in range(n):
        w, v = map(int, input().split())
        for wk in range(cap, w - 1, -1):
            nv = val[wk - w] + v
            if val[wk] < nv:
                val[wk] = nv
    return max(val)


n, cap = map(int, input().split())
print(nap(n, cap))

Buggy python submission (verdict: Time Limit Exceeded):
N, W = map(int, input().split())

dp = [0 for j in range(W + 1)]
items = []
for i in range(N):
  w, v = map(int, input().split())
  items.append((w, v))
  
for w, v in items:
  for wk in range(W, w - 1, -1):
      tv = dp[wk - w] + v
      if tv > dp[wk]:
        dp[wk] = tv
print(max(dp))

Fixed submission:
def nap(n, cap):
    val = [0] * (cap + 1)
    for _ in range(n):
        w, v = map(int, input().split())
        for wk in range(cap, w - 1, -1):
            nv = val[wk - w] + v
            if val[wk] < nv:
                val[wk] = nv
    return max(val)


n, cap = map(int, input().split())
print(nap(n, cap))

Buggy python submission (verdict: Time Limit Exceeded):
N, W = map(int, input().split())

dp = [0 for j in range(W + 1)]
for i in range(N):
  w, v = map(int, input().split())
  for wk in range(W, w - 1, -1):
    tv = dp[wk - w] + v
    if tv > dp[wk]:
      dp[wk] = tv

print(max(dp))


Fixed submission:
def nap(n, cap):
    val = [0] * (cap + 1)
    for _ in range(n):
        w, v = map(int, input().split())
        for wk in range(cap, w - 1, -1):
            nv = val[wk - w] + v
            if val[wk] < nv:
                val[wk] = nv
    return max(val)


n, cap = map(int, input().split())
print(nap(n, cap))

Buggy python submission (verdict: Time Limit Exceeded):
N, W = map(int, input().split())

dp = [0 for j in range(W + 1)]
for i in range(N):
  w, v = map(int, input().split())
  for wk in range(W, w - 1, -1):
    if dp[wk - w] + v > dp[wk]:
      dp[wk] = dp[wk - w] + v

print(max(dp))

Fixed submission:
def nap(n, cap):
    val = [0] * (cap + 1)
    for _ in range(n):
        w, v = map(int, input().split())
        for wk in range(cap, w - 1, -1):
            nv = val[wk - w] + v
            if val[wk] < nv:
                val[wk] = nv
    return max(val)


n, cap = map(int, input().split())
print(nap(n, cap))

Buggy python submission (verdict: Time Limit Exceeded):
N, W = map(int, input().split())

l_w = []
l_v = []
dp = [[0 for i in range(W + 1)] for j in range(N)]
for i in range(N):
  w, v = map(int, input().split())
  l_w.append(w)
  l_v.append(v)

def knapsack(id, rem_w):
  if rem_w == 0 or id == N:
    return 0
  if dp[id][rem_w] != 0:
    return dp[id][rem_w]
  if l_w[id] > rem_w:
    dp[id][rem_w] = knapsack(id + 1, rem_w)
  elif l_w[id] <= rem_w:
    dp[id][rem_w] = max(knapsack(id + 1, rem_w), l_v[id] + knapsack(id + 1, rem_w - l_w[id]))
  return dp[id][rem_w]
print(knapsack(0, W))


Fixed submission:
def nap(n, cap):
    val = [0] * (cap + 1)
    for _ in range(n):
        w, v = map(int, input().split())
        for wk in range(cap, w - 1, -1):
            nv = val[wk - w] + v
            if val[wk] < nv:
                val[wk] = nv
    return max(val)


n, cap = map(int, input().split())
print(nap(n, cap))