Buggy python submission (verdict: Time Limit Exceeded):
n,w = map(int,input().split())
dp = [-1] * (w + 1)
dp[0] = 0
for i in range(n):
  weight,value = map(int,input().split())
  for j in range(w,-1,-1):
    if dp[j] != -1 and weight + j <= w:
      dp[weight+j] = max(dp[weight+j],dp[j] + value)
print(max(dp))

Fixed submission:
def dp():
    n,w = map(int,input().split())
    lis = (map(int,input().split()) for i in range(n))
    
    dpp = [0] * (w + 1)
    for weight, value in lis:
        for j in range(w,weight-1,-1):
            dp = dpp[j-weight] + value
            if dpp[j] < dp:
                dpp[j] = dp
    return max(dpp)
print(dp())

Buggy python submission (verdict: Time Limit Exceeded):
n,w = map(int,input().split())
dp = {(0,0)}
for i in range(n):
  weight,value = map(int,input().split())
  gone=set()
  for noww,nowv in dp:
    if noww + weight <= w:
      gone.add((noww + weight,nowv + value))
    gone.add((noww,nowv))
  dp = gone
ans = 0
for lastw,lastv in dp:
  ans = max(ans,lastv)
print(ans)

Fixed submission:
def dp():
    n,w = map(int,input().split())
    lis = (map(int,input().split()) for i in range(n))
    
    dpp = [0] * (w + 1)
    for weight, value in lis:
        for j in range(w,weight-1,-1):
            dp = dpp[j-weight] + value
            if dpp[j] < dp:
                dpp[j] = dp
    return max(dpp)
print(dp())

Buggy python submission (verdict: Time Limit Exceeded):
n,w = map(int,input().split())
dp = {(0,0)}
for i in range(n):
  weight,value = map(int,input().split())
  gone=set()
  for noww,nowv in dp:
    if noww + weight <= w:
      gone.add((noww + weight,nowv + value))
    gone.add((noww,nowv))
  dp = gone
ans = 0
for lastw,lastv in dp:
  ans = max(ans,lastv)
print(ans)

Fixed submission:
def dp():
    n,w = map(int,input().split())
    lis = (map(int,input().split()) for i in range(n))
    
    dpp = [0] * (w + 1)
    for weight, value in lis:
        for j in range(w,weight-1,-1):
            dp = dpp[j-weight] + value
            if dpp[j] < dp:
                dpp[j] = dp
    return max(dpp)
print(dp())

Buggy python submission (verdict: Runtime Error):
def dp():
    n,w = map(int,input().split())
    lis = (map(int,input().split()) for i in range(n))
    
    dpp = [0] * (w + 1)
    for meight, value in lis:
        for j in range(w,weight-1,-1):
            dp = dpp[j-w] + value
            if dpp[j] < dp:
                dpp[j] = dp
    return max(dpp)
print(dp())

Fixed submission:
def dp():
    n,w = map(int,input().split())
    lis = (map(int,input().split()) for i in range(n))
    
    dpp = [0] * (w + 1)
    for weight, value in lis:
        for j in range(w,weight-1,-1):
            dp = dpp[j-weight] + value
            if dpp[j] < dp:
                dpp[j] = dp
    return max(dpp)
print(dp())

Buggy python submission (verdict: Time Limit Exceeded):
n,w = map(int,input().split())
lis = [list(map(int,input().split())) for i in range(n)]
knap = {(0,0)}
for weight,value in lis:
    gone = set()
    for num,now in knap:
        if num + weight <= w:gone.add((num+weight,now+value))
    for nn,nu in gone:
        knap.add((nn,nu))
ans = 0

for num,value in knap:
    ans = max(ans,value)
print(ans)


Fixed submission:
def dp():
    n,w = map(int,input().split())
    lis = (map(int,input().split()) for i in range(n))
    
    dpp = [0] * (w + 1)
    for weight, value in lis:
        for j in range(w,weight-1,-1):
            dp = dpp[j-weight] + value
            if dpp[j] < dp:
                dpp[j] = dp
    return max(dpp)
print(dp())

Buggy python submission (verdict: Time Limit Exceeded):
n,w = map(int,input().split())
lis = [list(map(int,input().split())) for i in range(n)]
knap = {(0,0)}
for weight,value in lis:
    gone = set()
    for num,now in knap:
        if num + weight <= w:gone.add((num+weight,now+value))
    for nn,nu in gone:
        knap.add((nn,nu))
ans = 0

for num,value in knap:
    ans = max(ans,value)
print(ans)

Fixed submission:
def dp():
    n,w = map(int,input().split())
    lis = (map(int,input().split()) for i in range(n))
    
    dpp = [0] * (w + 1)
    for weight, value in lis:
        for j in range(w,weight-1,-1):
            dp = dpp[j-weight] + value
            if dpp[j] < dp:
                dpp[j] = dp
    return max(dpp)
print(dp())