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

def f(n,W):
    wv = [list(map(int, input().split())) for _ in range(n)]
    dp = [[0] * (W + 1) for _ in range(n + 1)]
    for i, (w, v) in enumerate(wv):
        dp[i + 1][:w] = dp[i][:w]
        for j, (v1, v2) in enumerate(zip(dp[i], dp[i][w:])):
            nv = v1 + v
            if nv > v2:
                dp[i + 1][j + w] = nv
            else:
                dp[i + 1][j + w] = v2
    print(dp[-1][-1])

n, W = map(int, input().split())
f(n,W)


Fixed submission:
import sys
input=sys.stdin.readline

n, cap = map(int, input().split())
val =[0]*(cap+1)
def nap(n,cap):
    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)
print(nap(n,cap))

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

def f(n,W):
    wv = [list(map(int, input().split())) for _ in range(n)]
    dp = [0] + [-1] * W
    dp[0] = 0
    for w, v in wv:
        ndp = deepcopy(dp)
        for i, (dpi, dpj) in enumerate(zip(dp, dp[w:])):
            if dpi == -1: continue
            nv = dpi + v
            if nv > dpj:
                ndp[i + w] = nv
        dp = ndp
    print(max(dp))

n, W = map(int, input().split())
f(n,W)


Fixed submission:
import sys
input=sys.stdin.readline

n, cap = map(int, input().split())
val =[0]*(cap+1)
def nap(n,cap):
    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)
print(nap(n,cap))

Buggy python submission (verdict: Time Limit Exceeded):
n,W=map(int,input().split())
wv=[list(map(int,input().split())) for _ in range(n)]
dp=[-1]*(W+1)
dp[0]=0
for w,v in wv:
    for i in range(W-w,-1,-1):
        if dp[i]==-1:continue
        nv=dp[i]+v
        if nv>dp[i+w]:
            dp[i+w]=nv
print(max(dp))

Fixed submission:
import sys
input=sys.stdin.readline

n, cap = map(int, input().split())
val =[0]*(cap+1)
def nap(n,cap):
    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)
print(nap(n,cap))

Buggy python submission (verdict: Time Limit Exceeded):
n,W=map(int,input().split())
wv=[list(map(int,input().split())) for _ in range(n)]
dp=[0]*(W+1)
for w,v in wv:
    for i in range(W,w-1,-1):
        nv=dp[i-w]+v
        if nv>dp[i]:
            dp[i]=nv
print(dp[-1])

Fixed submission:
import sys
input=sys.stdin.readline

n, cap = map(int, input().split())
val =[0]*(cap+1)
def nap(n,cap):
    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)
print(nap(n,cap))

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

n, cap = map(int, input().split())
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
print(val[-1])


Fixed submission:
import sys
input=sys.stdin.readline

n, cap = map(int, input().split())
val =[0]*(cap+1)
def nap(n,cap):
    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)
print(nap(n,cap))

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

n, cap = map(int, input().split())
val =[0]*(cap+1)
for _ in range(n):
    w, v = map(int, input().split())
    for wk in range(cap,w-1,-1):
        val[wk]=max(val[wk],val[wk-w]+v)
print(val[-1])


Fixed submission:
import sys
input=sys.stdin.readline

n, cap = map(int, input().split())
val =[0]*(cap+1)
def nap(n,cap):
    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)
print(nap(n,cap))

Buggy python submission (verdict: Time Limit Exceeded):
n, cap = map(int, input().split())
val =[0]*(cap+1)
for _ in range(n):
    w, v = map(int, input().split())
    for wk in range(cap,w-1,-1):
        val[wk]=max(val[wk],val[wk-w]+v)
print(val[-1])


Fixed submission:
import sys
input=sys.stdin.readline

n, cap = map(int, input().split())
val =[0]*(cap+1)
def nap(n,cap):
    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)
print(nap(n,cap))

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

n, cap = map(int, input().split())
v_w = {0: 0}
for _ in range(n):
    w, v = map(int, input().split())
    for wk, vk in sorted(v_w.items()):
        nw = w + wk
        if nw > cap: break
        if nw in v_w:
            v_w[nw] = max(v_w[nw], v + vk)
        else:
            v_w[nw] = v + vk
print(max(v_w.values()))


Fixed submission:
import sys
input=sys.stdin.readline

n, cap = map(int, input().split())
val =[0]*(cap+1)
def nap(n,cap):
    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)
print(nap(n,cap))

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

n, cap = map(int, input().split())
v_w = {0: 0}
for _ in range(n):
    w, v = map(int, input().split())
    v_w2 = v_w.copy()
    for wk, vk in v_w2.items():
        nw = w + wk
        if nw > cap: continue
        if nw in v_w2:
            v_w[nw] = max(v_w[nw], v + vk)
        else:
            v_w[nw] = v + vk
print(max(v_w.values()))


Fixed submission:
import sys
input=sys.stdin.readline

n, cap = map(int, input().split())
val =[0]*(cap+1)
def nap(n,cap):
    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)
print(nap(n,cap))

Buggy python submission (verdict: Time Limit Exceeded):
n, cap = map(int, input().split())
v_w = {0: 0}
for _ in range(n):
    w, v = map(int, input().split())
    v_w2 = v_w.copy()
    for wk, vk in v_w2.items():
        nw = w + wk
        if nw > cap: continue
        if nw in v_w2:
            v_w[nw] = max(v_w[nw], v + vk)
        else:
            v_w[nw] = v + vk
print(max(v_w.values()))


Fixed submission:
import sys
input=sys.stdin.readline

n, cap = map(int, input().split())
val =[0]*(cap+1)
def nap(n,cap):
    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)
print(nap(n,cap))