qyliang/CodeNanoFix huggingface dataset:
Buggy code:
N = int(input())
abc = []
for _ in range(N):
    x = tuple(map(int, input().split()))
    abc.append(x)
dp = [[0 for _ in range(3)] for _ in range(N)]
dp[0][0] = abc[0][0]
dp[0][1] = abc[0][1]
dp[0][2] = abc[0][2]
for i in range(1, N):
    dp[i][0] = max(dp[i][0], dp[i-1][1] + abc[i][0], dp[i-1][2] + abc[i][0])
    dp[i][1] = max(dp[i][1], dp[i-1][0] + abc[i][1], dp[i-1][1] + abc[i][1])
    dp[i][2] = max(dp[i][2], dp[i-1][0] + abc[i][2], dp[i-1][1] + abc[i][2])

# print(*dp, sep='\n')
print(max(dp[N-1]))

Fixed code:
N = int(input())
abc = []
for _ in range(N):
    x = tuple(map(int, input().split()))
    abc.append(x)
dp = [[0 for _ in range(3)] for _ in range(N)]
dp[0][0] = abc[0][0]
dp[0][1] = abc[0][1]
dp[0][2] = abc[0][2]
for i in range(1, N):
    dp[i][0] = max(dp[i][0], dp[i-1][1] + abc[i][0], dp[i-1][2] + abc[i][0])
    dp[i][1] = max(dp[i][1], dp[i-1][0] + abc[i][1], dp[i-1][2] + abc[i][1])
    dp[i][2] = max(dp[i][2], dp[i-1][0] + abc[i][2], dp[i-1][1] + abc[i][2])

# print(*dp, sep='\n')
print(max(dp[N-1]))
Buggy code:
n = int(input())
a = [list(map(int, input().split())) for _ in range(n)]

a, b, c = 0, 0, 0
for x, y, z in a:
    a, b, c = max(b, c) + x, max(a, c) + y, max(a, b) + z

print(max(a, b, c))

Fixed code:
n = int(input())
abc = [list(map(int, input().split())) for _ in range(n)]

a, b, c = 0, 0, 0
for x, y, z in abc:
    a, b, c = max(b, c) + x, max(a, c) + y, max(a, b) + z

print(max(a, b, c))
Buggy code:
N = int(input())

what_to_do = []
for i in range(N):
    input2 = input().split()
    tmp1,tmp2,tmp3 = list(map(int,input2))
    what_to_do.append([tmp1,tmp2,tmp3])
    
print(what_to_do)

dp = []
for _ in range(N+1):
    dp.append([0,0,0])

print(dp)

for i in range(N):
    for k in range(3):
        for j in range(3):
            if k != j:
                dp[i + 1][k] = max(dp[i + 1][k], dp[i][j] + what_to_do[i][k])
                

print(dp)                
print(max(dp[-1]))

Fixed code:
N = int(input())

what_to_do = []
for i in range(N):
    input2 = input().split()
    tmp1,tmp2,tmp3 = list(map(int,input2))
    what_to_do.append([tmp1,tmp2,tmp3])

dp = []
for _ in range(N+1):
    dp.append([0,0,0])

for i in range(N):
    for k in range(3):
        for j in range(3):
            if k != j:
                dp[i + 1][k] = max(dp[i + 1][k], dp[i][j] + what_to_do[i][k])
                
            
print(max(dp[-1]))
Buggy code:
n = int(input())
abc = [list(map(int, input().split())) for _ in range(n)]
dp = [[0, 0, 0] for _ in range(n)]
for i in range(n):
  for j in range(3):
  if i == 0:
    dp[i][j] = abc[i][j]
  else:
    for k in range(3):
      if k == j:
        continue
      dp[i][j] = max(dp[i][j], dp[i-1][k] + abc[i][j])
ans = max(dp[n-1])
print(ans)
    

Fixed code:
n = int(input())
abc = [list(map(int, input().split())) for _ in range(n)]
dp = [[0, 0, 0] for _ in range(n)]
for i in range(n):
  for j in range(3):
    if i == 0:
      dp[i][j] = abc[i][j]
    else:
      for k in range(3):
        if k == j:
          continue
        dp[i][j] = max(dp[i][j], dp[i-1][k] + abc[i][j])
ans = max(dp[n-1])
print(ans)
Buggy code:
def solve(actions, n):
    # 1-origin
    dp = [[0] * 4 for _ in range(n + 1)]

    for day, action in enumerate(actions, 1):
        action1, action2, action3 = action[0], action[1], action[2]
        for key in range(1, 4):
            if key == 1:
                dp[day][key] = action1 + max(dp[day - 1][2], dp[day - 1][3])
            elif key == 2:
                dp[day][key] = action2 + max(dp[day - 1][1], dp[day - 1][3])
            else:
                dp[day][key] = action3 + max(dp[day - 1][1], dp[day - 1][2])

    return dp[n][3]


def main():
    n = int(input())
    actions = []

    for i in range(n):
        actions.append(list(map(int, input().split())))

    ans = solve(actions, n)
    print(ans)


main()


Fixed code:
def solve(actions, n):
    # 1-origin
    dp = [[0] * 4 for _ in range(n + 1)]

    for day, action in enumerate(actions, 1):
        action1, action2, action3 = action[0], action[1], action[2]
        for key in range(1, 4):
            if key == 1:
                dp[day][key] = action1 + max(dp[day - 1][2], dp[day - 1][3])
            elif key == 2:
                dp[day][key] = action2 + max(dp[day - 1][1], dp[day - 1][3])
            else:
                dp[day][key] = action3 + max(dp[day - 1][1], dp[day - 1][2])

    return max(dp[n])


def main():
    n = int(input())
    actions = []

    for i in range(n):
        actions.append(list(map(int, input().split())))

    ans = solve(actions, n)
    print(ans)


main()
Buggy code:
N=int(input())
ABC=[]
for i in range(N):
	ABC+=[[int(i) for i in input().split()]]
DP=[[0,0,0] for i in range(N)]
for i in range(N):
	for j in range(3):
		DP[i][j]=int(ABC[i][j])+max(DP[i-1][(j+1)%3],DP[i-1][(j+2)%3])
print(max(DP[N-1]))

Fixed code:
N=int(input())
ABC=[]
for i in range(N):
	ABC+=[[int(i) for i in input().split()]]
DP=[[0,0,0] for i in range(N+1)]
for i in range(N):
	for j in range(3):
		DP[i][j]=ABC[i][j]+max(DP[i-1][(j+1)%3],DP[i-1][(j+2)%3])
print(max(DP[N-1]))
Buggy code:
N = int(input())
lis = [list(map(int, input().split())) for _ in range(N)]
dp = [[0]*3 for _ in range(N+1)]
for k in range(3):
    dp[1][k] = lis[0][k]
print(dp)
for i in range(2, N+1):
    dp[i][0] = max(dp[i-1][1] + lis[i-1][1], dp[i-1][2] + lis[i-1][2])
    dp[i][1] = max(dp[i-1][0] + lis[i-1][0], dp[i-1][2] + lis[i-1][2])
    dp[i][2] = max(dp[i-1][0] + lis[i-1][0], dp[i-1][1] + lis[i-1][1])
    print(dp)
print(max(dp[N]))

Fixed code:
N = int(input())
lis = [list(map(int, input().split())) for _ in range(N)]
dp = [[0]*3 for _ in range(N+1)]
for k in range(3):
    dp[1][k] = lis[0][k]
for i in range(2, N+1):
    dp[i][0] = max(dp[i-1][1], dp[i-1][2]) + lis[i-1][0]
    dp[i][1] = max(dp[i-1][0], dp[i-1][2]) + lis[i-1][1]
    dp[i][2] = max(dp[i-1][0], dp[i-1][1]) + lis[i-1][2]
print(max(dp[N]))
Buggy code:
# coding:utf-8

N = int(input())
act = []
for i in range(N):
	act.append([int(x) for x in input().split()])

dp = [[0 for x in range(3)] for y in range(N+1)]

for i in range(0, N):
	for j in range(3):
		for k in range(3):
			if j != k:
				dp[i+1][j] = max(dp[i+1][j], dp[i][j] + act[i][k])

m = 0
for i in range(3):
	m = max(m, dp[N][i])

print(m)

Fixed code:
# coding:utf-8

N = int(input())
act = []
for i in range(N):
	act.append([int(x) for x in input().split()])

dp = [[0 for x in range(3)] for y in range(N)]

dp[0][0] = act[0][0]
dp[0][1] = act[0][1]
dp[0][2] = act[0][2]

for i in range(1, N):
	for j in range(3):
		for k in range(3):
			if j != k:
				dp[i][j] = max(dp[i][j], dp[i-1][k] + act[i][j])

m = 0
for i in range(3):
	m = max(m, dp[N-1][i])

print(m)
Buggy code:
def main():
    n = int(input())

    table = []
    for _ in range(n):
        table.append([int(v) for v in input().split()])

    dp = [0] * 3

    for i in range(n):
        dp_n = [0] * 3

        a, b, c = table[i]

        a0 = dp[0]
        b0 = dp[1]
        c0 = dp[2]

        dp_n[0] = max(b0, c0) + a
        dp_n[1] = max(c0, a0) + b
        dp_n[2] = max(a0, b0) + c

        dp = dp_n

    print(max(dp))


Fixed code:
n = int(input())

table = []
for _ in range(n):
    table.append([int(v) for v in input().split()])

dp = [0] * 3

for i in range(n):
    dp_n = [0] * 3

    a, b, c = table[i]

    a0 = dp[0]
    b0 = dp[1]
    c0 = dp[2]

    dp_n[0] = max(b0, c0) + a
    dp_n[1] = max(c0, a0) + b
    dp_n[2] = max(a0, b0) + c

    dp = dp_n

print(max(dp))
Buggy code:
# -*- coding: utf-8 -*-
# Vacation

'''
3
10 40 70
20 50 80
30 60 90
'''

N = int(input())

dp = [[None] * 3 for _ in range(N)]
dp[0] = list(map(int, input().split()))
# print(dp)

for i in range(1, N):
    data = list(map(int, input().split()))
    print(data)

    dp[i][0] = max(dp[i-1][1], dp[i-1][2]) + data[0]
    dp[i][1] = max(dp[i-1][0], dp[i-1][2]) + data[1]
    dp[i][2] = max(dp[i-1][0], dp[i-1][1]) + data[2]

# print(dp)
print(max(dp[N-1]))

Fixed code:
# -*- coding: utf-8 -*-
# Vacation

'''
3
10 40 70
20 50 80
30 60 90
'''

N = int(input())

dp = [[None] * 3 for _ in range(N)]
dp[0] = list(map(int, input().split()))
# print(dp)

for i in range(1, N):
    data = list(map(int, input().split()))
    # print(data)

    dp[i][0] = max(dp[i-1][1], dp[i-1][2]) + data[0]
    dp[i][1] = max(dp[i-1][0], dp[i-1][2]) + data[1]
    dp[i][2] = max(dp[i-1][0], dp[i-1][1]) + data[2]

# print(dp)
print(max(dp[N-1]))
Buggy code:
def main_C1():

  N = int(input())
  a = [[int(item) for item in line.split()] for line in input()]
  
  dp = [[0, 0, 0] for i in range(N+1)]

  for i in range(N):
    for j in range(3):
      for k in range(3):
        if j == k:
          continue
        dp[i+1][k] = max(dp[i+1][k], dp[i][j] + a[i][k])
  
  print(max(dp[-1]))

if __name__ == "__main__":
  main_C1()
  # print(list(input_gen()))

Fixed code:
def main_C1():

  N = int(input())
  a = [[int(item) for item in input().split()] for i in range(N)]
  
  dp = [[0, 0, 0] for i in range(N+1)]

  for i in range(N):
    for j in range(3):
      for k in range(3):
        if j == k:
          continue
        dp[i+1][k] = max(dp[i+1][k], dp[i][j] + a[i][k])
  
  print(max(dp[-1]))

if __name__ == "__main__":
  main_C1()
  # print(list(input_gen()))
Buggy code:
import sys


def input():
    return sys.stdin.readline().strip()


def main():
    size = int(input())
    array = []
    dp = [0] * size
    for _ in range(size):
        z = (list(map(int, input().split())))
        newDp = [0] * size
        for i in range(3):
            for j in range(3):
                if j != i:
                    newDp[j] = max(newDp[j], dp[i] + z[j])
        dp = newDp
    print(max(dp[0],dp[1],dp[2]))


if __name__ == "__main__":
    main()


Fixed code:
import sys


def input():
    return sys.stdin.readline().strip()


def main():
    size = int(input())
    dp = [0] * 3
    for _ in range(size):
        z = (list(map(int, input().split())))
        newDp = [0] * 3
        for i in range(3):
            for j in range(3):
                if j != i:
                    # import pdb
                    # pdb.set_trace()
                    newDp[j] = max(newDp[j], dp[i] + z[j])
        dp = newDp
    print(max(dp[0],dp[1],dp[2]))


if __name__ == "__main__":
    main()
Buggy code:
n=int(input())
l=[list(map(int,input().split())) for _ in range(n)]
dp=[0]*3
for i in range(n):
    dp[0],dp[1],dp[2]=max(dp[1],dp[2])+l[i][0],max(dp[0],dp[2])+l[i][1],max(dp[0],dp[1])+l[i][2]
    print(dp)
print(max(dp))

Fixed code:
n=int(input())
l=[list(map(int,input().split())) for _ in range(n)]
dp=[0]*3
for i in range(n):
    dp[0],dp[1],dp[2]=max(dp[1],dp[2])+l[i][0],max(dp[0],dp[2])+l[i][1],max(dp[0],dp[1])+l[i][2]
    #print(dp)
print(max(dp))
Buggy code:
N = int(input())

dp = [[0]*3 for _ in range(N+1)]

for i in range(1, N):
  a, b, c = map(int, input().split())
  dp[i][0] = max(dp[i-1][1], dp[i-1][2]) + a
  dp[i][1] = max(dp[i-1][0], dp[i-1][2]) + b
  dp[i][2] = max(dp[i-1][0], dp[i-1][1]) + c

print(max(dp[N-1][0], dp[N-1][1], dp[N-1][2]))

Fixed code:
N = int(input())

dp = [[0]*3 for _ in range(N+1)]

for i in range(1, N+1):
  a, b, c = map(int, input().split())
  dp[i][0] = max(dp[i-1][1], dp[i-1][2]) + a
  dp[i][1] = max(dp[i-1][0], dp[i-1][2]) + b
  dp[i][2] = max(dp[i-1][0], dp[i-1][1]) + c

print(max(dp[N][0], dp[N][1], dp[N][2]))
Buggy code:
N, W = [int(x) for x in input().split()]

w, v = [], []
MAX_V = 10100
INF = 100000000001

for i in range(N):
  wi, vi = [int(x) for x in input().split()]
  w.append(wi)
  v.append(vi)

dp = []
for i in range(N+1):
  dp.append([INF] * MAX_V)

dp[0][0] = 0

for i in range(N):
  for sum_v in range(MAX_V):
    if sum_v - v[i] >= 0:
      dp[i+1][sum_v] = min(dp[i+1][sum_v], dp[i][sum_v - v[i]] + w[i])
      
    dp[i+1][sum_v] = min(dp[i+1][sum_v], dp[i][sum_v])


res = 0
for sum_v in range(MAX_V):
  if dp[N][sum_v] <= W:
    res = sum_v
  
print(res

Fixed code:
N, W = [int(x) for x in input().split()]

w, v = [], []
MAX_V = 100001
INF = 1000000000001

for i in range(N):
  wi, vi = [int(x) for x in input().split()]
  w.append(wi)
  v.append(vi)

dp = []
for i in range(N+1):
  dp.append([INF] * MAX_V)

dp[0][0] = 0

for i in range(N):
  for sum_v in range(MAX_V):
    if sum_v - v[i] >= 0:
      dp[i+1][sum_v] = min(dp[i+1][sum_v], dp[i][sum_v - v[i]] + w[i])
      
    dp[i+1][sum_v] = min(dp[i+1][sum_v], dp[i][sum_v])


res = 0
for sum_v in range(MAX_V):
  if dp[N][sum_v] <= W:
    res = sum_v
  
print(res)
Buggy code:
N,W=map(int,input().split())
oj=[]
for i in range(N):
  oj.append(list(map(int,input().split())))
M=100*1001
dp=[10**10]*M
dp[0]=0
for i in range(N):
  for j in range(M,-1,-1):
    if j+oj[i][1]<M:
      k=j+oj[i][1]
      dp[k]=min(dp[k,dp[j]+oj[i][0])
v=0
for i in range(M):
  if dp[i]<=W:v=i
print(v)


Fixed code:
N,W=map(int,input().split())
oj=[]
for i in range(N):
  oj.append(list(map(int,input().split())))
M=100*1001
dp=[10**10]*M
dp[0]=0
for i in range(N):
  for j in range(M,-1,-1):
    if j+oj[i][1]<M:
      k=j+oj[i][1]
      dp[k]=min(dp[k],dp[j]+oj[i][0])
v=0
for i in range(M):
  if dp[i]<=W:v=i
print(v)
Buggy code:
n, w = map(int, input().split())

nap = [list(map(int, input().split())) for _ in range(n)]

INF = float('inf')
num = 10**5 + 10
dp = [[INF]*(num) for _ in range(110)]

dp[0][0] = 0
for i in range(n):
    for v in range(num):
        if v + nap[i][1] <= num:
            dp[i+1][v+nap[i][1]] = min(dp[i+1][v+nap[i][1]], dp[i][v] + nap[i][0])
        dp[i+1][v] = min(dp[i+1][v], dp[i][v])

for v in reversed(range(num)):
    if dp[n][v] <= w:
        print(v)
        exit()


Fixed code:
n, w = map(int, input().split())

nap = [list(map(int, input().split())) for _ in range(n)]

INF = float('inf')
num = 10**5 + 10
dp = [[INF]*(10**5+10) for _ in range(110)]

dp[0][0] = 0
for i in range(n):
    for v in range(10**5+1):
        if v + nap[i][1] <= 10**5+1:
            dp[i+1][v+nap[i][1]] = min(dp[i+1][v+nap[i][1]], dp[i][v] + nap[i][0])
        dp[i+1][v] = min(dp[i+1][v], dp[i][v])

for v in reversed(range(10**5+1)):
    if dp[n][v] <= w:
        print(v)
        exit()
Buggy code:
import math


def read_int():
    return int(input().strip())


def read_ints():
    return list(map(int, input().strip().split(' ')))


def solve():
    """
    OPT[value] - minimum weight that achieves value
    OPT[value] = OPT[value-v[i]]
    """
    N, W = read_ints()
    max_value = 1000*N+1
    dp = [math.inf]*max_value
    return -1
    dp[0] = 0
    for i in range(N):
        w, v = read_ints()
        for j in range(max_value-1, -1, -1):
            if j >= v:
                dp[j] = min(dp[j], dp[j-v]+w)
    ans = 0
    for j in range(max_value):
        if dp[j] <= W:
            ans = j
    return ans


if __name__ == '__main__':
    print(solve())


Fixed code:


def read_int():
    return int(input().strip())


def read_ints():
    return list(map(int, input().strip().split(' ')))


def solve():
    """
    OPT[value] - minimum weight that achieves value
    OPT[value] = OPT[value-v[i]]
    """
    N, W = read_ints()
    max_value = 1000*N+1
    dp = [10**12+1]*max_value
    dp[0] = 0
    for i in range(N):
        w, v = read_ints()
        for j in range(max_value-1, -1, -1):
            if j >= v:
                dp[j] = min(dp[j], dp[j-v]+w)
    ans = 0
    for j in range(max_value):
        if dp[j] <= W:
            ans = j
    return ans


if __name__ == '__main__':
    print(solve())
Buggy code:
n,k=(int(i) for i in input().split())
e = [[int(i) for i in input().split()] for j in range(n)]
#print(n,k,e)
maxv=0
for i in range(n):
    maxv+=e[i][1]
#print(maxv)

dp = [[0 for i in range(maxv+1)] for j in range(n+1)]
#print(dp)

for i in range(1, maxv+1):
    dp[0][i] = float('inf')
#print(dp)

for j in range(n):
    for i in range(1, maxv+1):
        if i < e[j][1] :
            dp[j + 1][i] = dp[j][i]
        else:
            dp[j + 1][i] = min(dp[j][i], dp[j][i - e[j][1]] +e[j][0])
#print(dp)
ans = 0
for i in range(maxv):
    if dp[n][i] <= k and ans < i:
        ans = i
        
print(ans)

Fixed code:
n,k=(int(i) for i in input().split())
e = [[int(i) for i in input().split()] for j in range(n)]
#print(n,k,e)
maxv=0
for i in range(n):
    maxv+=e[i][1]
#print(maxv)

dp = [[0 for i in range(maxv+1)] for j in range(n+1)]
#print(dp)

for i in range(1, maxv+1):
    dp[0][i] = float('inf')
#print(dp)

for j in range(n):
    for i in range(1, maxv+1):
        if i < e[j][1] :
            dp[j + 1][i] = dp[j][i]
        else:
            dp[j + 1][i] = min(dp[j][i], dp[j][i - e[j][1]] +e[j][0])
#print(dp)
ans = 0
for i in range(maxv+1):
    if dp[n][i] <= k and ans < i:
        ans = i
        
print(ans)
Buggy code:
#dt = {} for i in x: dt[i] = dt.get(i,0)+1
import sys;input = sys.stdin.readline
inp,ip = lambda :int(input()),lambda :[int(w) for w in input().split()]

def knapsack(sm,W,n,V):
    K = [[0]*(sm+1) for i in range(n+1)]
    for i in range(1,n+1):
        for j in range(1,sm+1):
            K[i][j] = K[i-1][j]
            if W[i-1] <= j:
                K[i][j] = max(V[i-1]+K[i-1][j-W[i-1]], K[i-1][j])
    return K[n][sm]

n,wt = ip()
V,W = [0]*n,[0]*n
for i in range(n):
    w,v = ip()
    V[i] = v
    W[i] = w

ans = knapsack(wt,W,n,V)
print(ans)
    


Fixed code:
#dt = {} for i in x: dt[i] = dt.get(i,0)+1
import sys;input = sys.stdin.readline
inp,ip = lambda :int(input()),lambda :[int(w) for w in input().split()]

def knapsack(wt,sm,W,n,V):
    K = [float('inf')]*(sm+1)
    K[0] = 0
    for i in range(n):
        for j in range(sm-V[i],-1,-1):
                K[j+V[i]] = min(K[j+V[i]],K[j]+W[i])
    #print(K)
    return max([i for i in range(sm+1) if K[i] <= wt])

n,wt = ip()
V,W = [0]*n,[0]*n
for i in range(n):
    w,v = ip()
    V[i] = v
    W[i] = w
ans = knapsack(wt,sum(V),W,n,V)
print(ans)
Buggy code:
n,w=[int(k) for k in input().split()]
li=[]
 
 
ans=0
for i in range(n):
    li.append([int(k) for k in input().split()])
dp=[[0 for i in range(100001)] for j in range(n+1)]
for i in range(1,10001):
    dp[0][i]=10**10
dp[0][0]=0    
for a in range(1,n+1):
    for b in range(0,100001):
        if(li[a-1][1]<=b):
            x=li[a-1][0]+dp[a-1][b-li[a-1][1]]
            y=dp[a-1][b]
            dp[a][b]=min(x,y)
        else:
            dp[a][b]=dp[a-1][b]
        if dp[a][b]<=w:
          ans=max(ans,b)
 
 
print(ans)    
 

Fixed code:
n,w=[int(k) for k in input().split()]
li=[]
 
 
ans=0
for i in range(n):
    li.append([int(k) for k in input().split()])
dp=[[0 for i in range(100001)] for j in range(n+1)]
for i in range(1,100001):
    dp[0][i]=10**10
dp[0][0]=0    
for a in range(1,n+1):
    for b in range(0,100001):
        if(li[a-1][1]<=b):
            x=li[a-1][0]+dp[a-1][b-li[a-1][1]]
            y=dp[a-1][b]
            dp[a][b]=min(x,y)
        else:
            dp[a][b]=dp[a-1][b]
        if dp[a][b]<=w:
          ans=max(ans,b)
 
 
print(ans)
Buggy code:
N, W = map(int, input().split())
w, v = [0] * (N + 1), [0] * (N + 1)
INF = 10 ** 9
for i in range(1, N + 1):
    w[i], v[i] = map(int, input().split())

dp = [[INF] * ((10 ** 5) + 2) for i in range(N + 1)]
dp[0][0] = 0
for i in range(1, N + 1):
    for j in range(0, 10 **5+1):
        dp[i][j] = dp[i - 1][j]
        if j - v[i] >= 0:
            dp[i][j] = min(dp[i - 1][j], dp[i - 1][j - v[i]] + w[i])

ans = 0
for i in range(0, 10 ** 5+1):
    if dp[N][i] <= W:
        ans = i
#print(dp[N])
print(ans)

Fixed code:
'''
w,v = [0] * n, [0] * n
for i in range(n):
    w[i] , v[i] = map(int,input().split())
'''

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

dp = [[INF] * ((10 ** 5) + 2) for i in range(N + 1)]
dp[0][0] = 0
for i in range(1, N + 1):
    for j in range(0, 10 **5+1):
        dp[i][j] = dp[i - 1][j]
        if j - v[i] >= 0:
            dp[i][j] = min(dp[i - 1][j], dp[i - 1][j - v[i]] + w[i])

ans = 0
for i in range(0, 10 ** 5+1):
    if dp[N][i] <= W:
        ans = i
#print(dp[N])
print(ans)
Buggy code:
# -*- coding: utf-8 -*-
"""
Created on Tue Jan 21 18:19:39 2020

@author: matsui
"""


N,W=map(int,input().split())
vi,wi=[],[]
for i in range(N):
    w,v=map(int,input().split())
    wi.append(w)
    vi.append(v)

M=int(sum(vi))
dp1=[sum(wi)+1]*(M+1)
#dp2=[sum(wi)+1]*(M+1)
dp1[0]=0
   
#L = sorted([list(map(int,input().split())) for i in range(N)])
s=0

for w, v in zip(wi,vi):
    s+=v
    for j in range(min(s,M),v-1,-1):
        if j >= v: 
            if dp1[j] > dp1[j-v]+w: dp1[j]=dp1[j-v]+w
        if dp1[j] > dp1[j]: dp1[j]=dp1[j]
    print(dp1)
    #print(dp2)
    #dp1=[dp2[i] for i in range(M+1)]    
    
#print(max(dp))
m=0
for i in range(M+1):
    if dp1[i]<=W:
        m=i
print(m)
    


Fixed code:
# -*- coding: utf-8 -*-
"""
Created on Tue Jan 21 18:19:39 2020

@author: matsui
"""


N,W=map(int,input().split())
vi,wi=[],[]
for i in range(N):
    w,v=map(int,input().split())
    wi.append(w)
    vi.append(v)
    

#L = sorted([list(map(int,input().split())) for i in range(N)])

M=int(sum(vi))
dp=[W+1]*(M+1)
dp[0]=0
   
#L = sorted([list(map(int,input().split())) for i in range(N)])
s=0

for w, v in zip(wi,vi):
    s+=v
    for j in range(min(s,M),v-1,-1):
        if dp[j] > dp[j-v]+w: dp[j]=dp[j-v]+w
    #print(dp)

m=0
for i in range(M+1):
    if dp[i]<=W:
        m=i
print(m)
Buggy code:
N,W-map(int,input().split())
w=[]
v=[]
for i in range(n):
    a,b=map(int,input().split())
    w.append(a)
    v.append(b)
dp=[[10**22]*(N*(10**3)+1) for i in range(N+1)]
dp[0][0]=0
for i in range(1,N+1):
    for j in range(N*(10**3)+1):
        if j>=v[i]:
            dp[i][j]=min(dp[i-1][j-v[i]]+w[i],dp[i-1][j])
        else:
            dp[i][j]=dp[i-1][j]
for i in range(N*(10**3),-1,-1):
    if dp[N][i]<=W:
        print(i)
        break


Fixed code:
N,W=map(int,input().split())
taple=[]
for i in range(N):
    w,v=map(int,input().split())
    taple.append((w,v))
dp=[[10**22]*(N*(10**3)+1) for i in range(N+1)]
dp[0][0]=0
for i in range(1,N+1):
    w,v=taple[i-1]
    for j in range(N*(10**3)+1):
        if j>=v:
            dp[i][j]=min(dp[i-1][j-v]+w,dp[i-1][j])
        else:
            dp[i][j]=dp[i-1][j]
for i in range(N*(10**3),-1,-1):
    if dp[N][i]<=W:
        print(i)
        break
Buggy code:
N, W = map(int, input().split())

items = [list(map(int, input().split())) for _ in range(N)]
v_sum = sum([item[1] for item in items])

inf = float("inf")
dp = [inf for _ in range(v_sum + 1)]

dp[0] = 0
for i in range(N):
    for j in range(v_sum, -1, -1):
        if dp[j] >= dp[j - items[i][1] + items[i][0]]:
            dp[j] = dp[j - items[i][1]] + items[i][0]

for i in range(v_sum, -1, -1):
    if dp[i] <= W:
        print(i)
        exit()


Fixed code:
N, W = map(int, input().split())
items = [list(map(int, input().split())) for _ in range(N)]
sum_v = sum([item[1] for item in items])
inf = float("inf")
dp = [inf for _ in range(sum_v+1)]

dp[0] = 0
for i in range(N):
    for j in range(sum_v, -1, -1):
        if j - items[i][1] >= 0:
            dp[j] = min(dp[j], dp[j - items[i][1]] + items[i][0])

for v in range(sum_v, -1, -1):
    if dp[v] <= W:
        print(v)
        exit()
Buggy code:
N, W = map(int, input().split())
items = [list(map(int, input().split())) for _ in range(N)]
sum_v = sum([item[1] for item in items])
inf = float("inf")
dp = [[inf for _ in range(sum_v+1)] for _ in range(N+1)]


dp[0][0] = 0
for i in range(N):
    for j in range(sum_v):
        if j - items[i][0] >= 0:
            dp[i+1][j] = min(dp[i][j], dp[i][j - items[i][1]] + items[i][0])
        else:
            dp[i+1][j] = dp[i][j]

for v in range(sum_v, -1, -1):
    if dp[N][v] <= W:
        print(v)
        exit()



Fixed code:
N, W = map(int, input().split())
items = [list(map(int, input().split())) for _ in range(N)]
sum_v = sum([item[1] for item in items])
inf = float("inf")
dp = [[inf for _ in range(sum_v+1)] for _ in range(N+1)]


dp[0][0] = 0
for i in range(N):
    for j in range(sum_v+1):
        if j - items[i][1] >= 0:
            dp[i+1][j] = min(dp[i][j], dp[i][j - items[i][1]] + items[i][0])
        else:
            dp[i+1][j] = dp[i][j]
for v in range(sum_v, -1, -1):
    if dp[N][v] <= W:
        print(v)
        exit()