qyliang/CodeNanoFix huggingface dataset:
Buggy code:
n,W=map(int,input().split())
sumv=0
v,w=[],[]
m=10**9
for i in range(n):
    a,b=map(int,input().split())
    w.append(a)
    v.append(b)
    sumv+=b
dp=[m]*(sumv+1)
dp[0]=0
for i in range(n):
    for j in range(sumv,v[i]-1,-1):
        dp[j]=min(dp[j],dp[j-v[i]]+w[i])
ans=0

for i in range(sumv):
    if dp[i]<=W:
        ans=i 
# print(dp)
print(ans)


Fixed code:
n,W=map(int,input().split())
sumv=0
v,w=[],[]
m=10**9
for i in range(n):
    a,b=map(int,input().split())
    w.append(a)
    v.append(b)
    sumv+=b
dp=[m]*(sumv+1)
dp[0]=0
for i in range(n):
    for j in range(sumv,v[i]-1,-1):
        dp[j]=min(dp[j],dp[j-v[i]]+w[i])
ans=0

for i in range(sumv+1):
    if dp[i]<=W:
        ans=i 
# print(dp)
print(ans)
Buggy code:
def main():
  N,W=map(int,input().split())
  Wlist=[]
  Vlist=[]
  for i in range(N):
    w,v=map(int,input().split())
    Wlist+=[w]
    Vlist+=[v]
  Vmax=max(Vlist)
  V=Vmax*N
  dp=[[0 for p in range(V+1)] for i in range(N)]
  for i in range(V+1):
    if i<=Vlist[0]:
      dp[0][i]=Wlist[0]
  for i in range(1,N):
    vi=Vlist[i]
    for j in range(V+1):
      if j-vi>=0:
        dp[i][j]=min(dp[i-1][j-vi]+Wlist[i],dp[i-1][j])
      else:
        dp[i][j]=min(dp[i-1][j],dp[i][j])
    print(dp)
  dpn=dp[N-1]
  ans=0
  for i in range(V+1):
    if dpn[i]<=W:
      ans=i
  print(ans)
if __name__ == '__main__':
  main()

Fixed code:
def main():
  N,W=map(int,input().split())
  Wlist=[]
  Vlist=[]
  for i in range(N):
    w,v=map(int,input().split())
    Wlist+=[w]
    Vlist+=[v]
  Vmax=max(Vlist)
  V=Vmax*N
  dp=[[float('inf') for p in range(V+1)] for i in range(N)]
  for i in range(V+1):
    if i<=Vlist[0]:
      dp[0][i]=Wlist[0]
  dp[0][0]=0
  for i in range(1,N):
    vi=Vlist[i]
    wi=Wlist[i]
    for j in range(V+1):
      if j-vi>=0:
        dp[i][j]=min(dp[i-1][j-vi]+wi,dp[i-1][j])
      else:
        dp[i][j]=min(dp[i-1][j],dp[i][j])
  dpn=dp[N-1]
  ans=0
  for i in range(V+1):
    if dpn[i]<=W:
      ans=i
  print(ans)
if __name__ == '__main__':
  main()
Buggy code:
N, W = map(int, input().split())
items = []
for _ in range(N):
    items.append(tuple(map(int, input().split())))
MAX_V = sum([v for _, v in items])
dp = [[0 for j in range(MAX_V+1)] for i in range(N+1)]
for i in range(1, N+1):
    w, v = items[i-1]
    for j in range(MAX_V+1):
        if j - v >= 0:
            dp[i][j] = min(dp[i-1][j-v] + w, dp[i-1][j])
        else:
            dp[i][j] = dp[i-1][j]
for v in range(MAX_V, -1, -1):
    if dp[N][v] <= W:
        break
print(v)

Fixed code:
N, W = map(int, input().split())
items = []
INF = 10**12
for _ in range(N):
    items.append(tuple(map(int, input().split())))
MAX_V = sum([v for _, v in items])
dp = [[INF for j in range(MAX_V+1)] for i in range(N+1)]
dp[0][0] = 0
for i in range(1, N+1):
    w, v = items[i-1]
    for j in range(MAX_V+1):
        if j - v >= 0:
            dp[i][j] = min(dp[i-1][j-v] + w, dp[i-1][j])
        else:
            dp[i][j] = dp[i-1][j]
for v in range(MAX_V, -1, -1):
    if dp[N][v] <= W:
        break
print(v)
Buggy code:
N, W = map(int, input().split())
w, v = [0]*N, [0]*N
total_v = 0
for _ in range(N):
  w[i], v[i] = map(int, input().split())
  total_v += v[i]

dp = [[float('inf') for _ in range(total_v+1)] for _ in range(N+1)]
dp[0][0] = 0

for i in range(1, N+1):
  for j in range(1, total_v+1):
    if j < v[i-1]:
      dp[i][j] = dp[i-1][v]
    else:
      dp[i][j] = min(dp[i-1][j], dp[i-1][j-v[i-1]] + w[i-1])
for i in range(total_v, -1, -1):
  if dp[-1][i] <= W:
    print(i)
    break

Fixed code:
N, W = map(int, input().split())
w, v = [0]*N, [0]*N
total_v = 0
for i in range(N):
  w[i], v[i] = map(int, input().split())
  total_v += v[i]

dp = [[float('inf') for _ in range(total_v+1)] for _ in range(N+1)]
dp[0][0] = 0

for i in range(1, N+1):
  for j in range(total_v+1):
    if j < v[i-1]:
      dp[i][j] = dp[i-1][j]
    else:
      dp[i][j] = min(dp[i-1][j], dp[i-1][j-v[i-1]] + w[i-1])
for i in range(total_v, -1, -1):
  if dp[N][i] <= W:
    print(i)
    break
Buggy code:
n, w = map(int, input().split())
nums = [list(map(int, input().split())) for _ in range(n)]

total_v = sum(nums[1])
dp = [[float('inf') for _ in range(total_v+1)] for _ in range(n)]
dp[0][0] = 0

for i in range(1, n+1):
  for j in range(total_v+1):
    if j < nums[i-1][1]:
      dp[i][j] = dp[i-1][j]
    else:
      dp[i][j] = min(dp[i-1][j], dp[i-1][j-nums[i-1][1]] + nums[i-1][0])
for i in range(total_v, -1, -1):
  if dp[-1][i] <= w:
    print(i)
    break

Fixed code:
n, w = map(int, input().split())
nums = []
for _ in range(n):
  nums.append(list(map(int, input().split())))
  
total_v = sum(nums[i][1] for i in range(n))

dp = [[float('inf') for _ in range(total_v+1)] for _ in range(n+1)]
dp[0][0] = 0

for i in range(1, n+1):
  for j in range(total_v+1):
    if j < nums[i-1][1]:
      dp[i][j] = dp[i-1][j]
    else:
      dp[i][j] = min(dp[i-1][j], dp[i-1][j-nums[i-1][1]] + nums[i-1][0])
for i in range(total_v, -1, -1):
  if dp[n][i] != float('inf') and dp[n][i] <= w:
    print(i)
    break
Buggy code:
N, W = map(int, input().split())
wv = [list(map(int, input().split())) for i in range(N)]
dp = {0: 0}
for i in range(N):
    for j in sorted(dp.keys(), reverse=True):
        w, v = wv[i][0], wv[i][1]
        nw = dp[j] + w
        nv = j + v
        if nw <= W:
            if nv in dp:
                dp[nv] = nw
        else:
            dp[nv] = nw
            
print(max(dp.key()))

Fixed code:
N, W = map(int, input().split())
wv = [list(map(int, input().split())) for i in range(N)]
dp = {0: 0}
for i in range(N):
    for j in sorted(dp.keys(), reverse=True):
        w, v = wv[i][0], wv[i][1]
        nw = dp[j] + w
        nv = j + v
        if nw <= W:
            if nv in dp:
                if nw < dp[nv]:
                    dp[nv] = nw
            else:
                dp[nv] = nw


print(max(dp.keys()))
Buggy code:
N, W = list(map(int, input().split()))
INF = int(1e11)
dp = [[INF for i in range(int(1e5)+1)] for j in range(N+1)]
dp[0][0] = 0

for i in range(1, N+1):
    w, v = list(map(int, input().split()))
    for j in range(0, int(1e5)+1):
        dp[i][j] = min(dp[i-1][j], dp[i-1][j-v]+w)

for i in range(N+1):
    for j in reversed(range(int(1e5)+1)):
        if dp[i][j] <= W:
            print(j)
            break

Fixed code:
N, W = list(map(int, input().split()))
INF = int(1e11)
dp = [[INF for i in range(int(1e5)+1)] for j in range(N+1)]
dp[0][0] = 0

for i in range(1, N+1):
    w, v = list(map(int, input().split()))
    for j in range(0, int(1e5)+1):
        dp[i][j] = min(dp[i-1][j], dp[i-1][j-v]+w)

for j in reversed(range(int(1e5)+1)):
    for i in range(N+1):
        if dp[i][j] <= W:
            print(j)
            break
    else:
        continue
    break
Buggy code:
N, W = map(int, input().split())
w = []
v = []
for _ in range(N):
    x, y = map(int, input().split())
    w.append(x)
    v.append(y)
    
V = N * max(v)

inf = float('inf')
dp = [[inf] * (V + 1) for i in range(N + 1)]
dp[0][0] = 0
for i in range(N):
    for j in range(V + 1):
        if v[i] > j:
            dp[i + 1][j] = dp[i][j]
        else:
            dp[i + 1][j] = min(dp[i][j], dp[i][j - v[i]] + w[i])
            
ans = 0
for i in range(V):
    if dp[N][i] <= W:
        ans = i
print(ans)

Fixed code:
N, W = map(int, input().split())
w = []
v = []
for _ in range(N):
    x, y = map(int, input().split())
    w.append(x)
    v.append(y)
    
V = N * max(v)

inf = float('inf')
dp = [[inf] * (V + 1) for i in range(N + 1)]
dp[0][0] = 0
for i in range(N):
    for j in range(V + 1):
        if v[i] > j:
            dp[i + 1][j] = dp[i][j]
        else:
            dp[i + 1][j] = min(dp[i][j], dp[i][j - v[i]] + w[i])
            
ans = 0
for i in range(V + 1):
    if dp[N][i] <= W:
        ans = i
print(ans)
Buggy code:
from sys import stdin
N, W = map(int, input().split())
s = list(list(map(int, line.split())) for line in stdin.read().splitlines())

sumv = sum(s[i][1] for i in range(N))

INF = 10e12
dp = [INF] * (sumv + 1)  # minimum w required to achieve  value V. dp[v] = w

dp[0] = 0

for n in range(N):
    w0, v0 = s[n]
    for v in range(sumv, v0 - 1, -1):
        if dp[v - v0] + w0 <= W:
            dp[v] = min(dp[v], dp[v - v0] + w0)

for i in range(sumv, -1, -1):
    if dp[i] <= INF:
        print(i)
        break


Fixed code:
from sys import stdin
N, W = map(int, input().split())
s = list(list(map(int, line.split())) for line in stdin.read().splitlines())

sumv = sum(s[i][1] for i in range(N))

INF = float('inf')
dp = [INF] * (sumv + 1)  # minimum w required to achieve  value V. dp[v] = w
dp[sumv] = sum(s[i][0] for i in range(N))
dp[0] = 0

for n in range(N):
    w0, v0 = s[n]
    for v in range(sumv, v0 - 1, -1):
        dp[v] = min(dp[v], dp[v - v0] + w0)

for i in range(sumv, -1, -1):
    if dp[i] <= W:
        print(i)
        break
Buggy code:
N,W,*l = map(int,open(0).read().split())
wl = l[::2]
vl = l[1::2]
M = N*max(vl)
INF = float("inf")
dp = [[INF]*M for _ in range(N+1)]
dp[0][0] = 0

# minimum weight with value == j
for i in range(N):
	w,v = wl[i],vl[i]
	for j in range(M):
		if j >= v:
			dp[i+1][j] = min(dp[i][j],dp[i][j-v]+w)
		else:
			dp[i+1][j] = dp[i][j]
		
# maximum value provided dp[N][value] <= W
ans=0
for val,wei in enumerate(dp[N]):
	if wei <= W:
		ans = max(ans,val)
print(ans)

Fixed code:
N,W,*l = map(int,open(0).read().split())
wl = l[::2]
vl = l[1::2]
M = N*max(vl)
INF = float("inf")
dp = [[INF]*(M+1) for _ in range(N+1)]
dp[0][0] = 0

# minimum weight with value == j
for i in range(N):
	w,v = wl[i],vl[i]
	for j in range(M+1):
		if j >= v:
			dp[i+1][j] = min(dp[i][j],dp[i][j-v]+w)
		else:
			dp[i+1][j] = dp[i][j]
		
# maximum value provided dp[N][value] <= W
ans=0
for val,wei in enumerate(dp[-1]):
	if wei <= W:
		ans = max(ans,val)
print(ans)
Buggy code:
N,W=[int(x) for x in input().split()]
w=[-1 for _ in range(N)]
v=[-1 for _ in range(N)]
for i in range(N):
	w[i],v[i]=[int(x) for x in input().split()]
#Constraints N<=100 W<=10^9 w[i]<=10^9 and v[i]<=10^3
#dp[w] used to store maximum value at weight<=w
#dp[v] used to store minimum weight at value==v
dp=[10000000 for _ in range(100002)]
dp[0]=0
for i in range(N):
	for v_ in range(100001,v[i]-1,-1):
		#print(v_-v[i])
		dp[v_]=min(dp[v_],dp[v_-v[i]]+w[i])
for v_ in range(100001,-1,-1):
	if dp[v_]<=W: print(v_); break

Fixed code:
N,W=[int(x) for x in input().split()]
w=[-1 for _ in range(N)]
v=[-1 for _ in range(N)]
for i in range(N):
	w[i],v[i]=[int(x) for x in input().split()]
#Constraints N<=100 W<=10^9 w[i]<=10^9 and v[i]<=10^3
#dp[w] used to store maximum value at weight<=w
#dp[v] used to store minimum weight at value==v
dp=[1000000002 for _ in range(100001)]
dp[0]=0
for i in range(N):
	for v_ in range(100000,v[i]-1,-1):
		#print(v_-v[i])
		dp[v_]=min(dp[v_],dp[v_-v[i]]+w[i])
for v_ in range(100000,-1,-1):
	if dp[v_]<=W: print(v_); break
Buggy code:
import sys
input = sys.stdin.readline
import bisect
N,W= map(int,input().split())
ans= [[float('inf') for e in range(10**5+1)] for f in range(N+1)]
for i in range(N):
 w,v=map(int,input().split())
 for j in range(0,v):
  ans[i+1][j]=min(ans[i][j],w)
 for j in range(v,10**5+1):
  ans[i+1][j]=min(ans[i][j],ans[i][j-v]+w)
print(bisect.bisect(ans[N],W))
print(ans[N])


Fixed code:
import sys
input = sys.stdin.readline
import bisect
N,W= map(int,input().split())
ans= [[float('inf') for e in range(10**5+1)] for f in range(N+1)]
for i in range(N):
 w,v=map(int,input().split())
 for j in range(0,v):
  ans[i+1][j]=min(ans[i][j],w)
 for j in range(v,10**5+1):
  ans[i+1][j]=min(ans[i][j],ans[i][j-v]+w)
print(bisect.bisect(ans[N],W))
Buggy code:
import sys
input = sys.stdin.readline

N,W=map(int,input().split())
V = 1000
INF = 1e+9
wv = [list(map(int, input().split())) for _ in range(N)]
dp = [[INF]*(N*V+1) for _ in range(N+1)]
dp[0][0] = 0

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

for i in reversed(range(N*V+1)):
    if dp[N][i] <= W:
        print(i)
        break
    


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

N,W=map(int,input().split())
V = 1000
INF = 1e+10
wv = [list(map(int, input().split())) for _ in range(N)]
dp = [[INF]*(N*V+1) for _ in range(N+1)]
dp[0][0] = 0

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

for i in reversed(range(N*V+1)):
    if dp[N][i] <= W:
        print(i)
        break
Buggy code:
import sys
input = sys.stdin.readline

N, W = [int(i) for i in input().split()]

def ans(N, W):
    d = [float("inf")] * N * 1000
    d[0] = 0
    V = 0

    for i in range(N):
        wi, vi = [int(i) for i in input().split()]
        V = V + vi

        for v in range(V, V-vi-1, -1):
            w_ = d[v - vi] + wi
            if w_ < d[v]:
                d[v] = w_

    for v in range(V, -1, -1):
        if d[v] <= W:
            return v

print(ans(N, W))


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

N, W = [int(i) for i in input().split()]

def ans(N, W):
    d = [float("inf")] * (N * 1000 + 1)
    d[0] = 0
    V = 0

    for i in range(N):
        wi, vi = [int(i) for i in input().split()]
        V = V + vi

        for v in range(V, vi-1, -1):
            w_ = d[v - vi] + wi
            if w_ < d[v]:
                d[v] = w_

    for v in range(V, -1, -1):
        if d[v] <= W:
            return v

print(ans(N, W))
Buggy code:
N, W = (int(x) for x in input().split())
weights = []
values = []
for _ in range(N):
  w, v = (int(x) for x in input().split())
  weights.append(w)
  values.append(v)

sumValues = sum(values)
dp = [float('inf')] * (sumValues + 1) # Minimum weight at value v.
dp[0] = 0
for item in range(N):
  for value in range(sumValues-values[item], -1, -1):
    dp[value+values[item]] = min(dp[value+values[item]], dp[value]+weights[item])

res = 0
for i in range(sumValues):
  if dp[i] <= W:
    res = max(res, i)
print(res)

Fixed code:
N, W = (int(x) for x in input().split())
weights = []
values = []
for _ in range(N):
  w, v = (int(x) for x in input().split())
  weights.append(w)
  values.append(v)

sumValues = sum(values)
dp = [float('inf')] * (sumValues + 1) # Minimum weight at value v.
dp[0] = 0
for item in range(N):
  for value in range(sumValues-values[item], -1, -1):
    dp[value+values[item]] = min(dp[value+values[item]], dp[value]+weights[item])

res = 0
for i in range(sumValues+1):
  if dp[i] <= W:
    res = max(res, i)
print(res)
Buggy code:
import sys
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
N,W = LI()
wv = [LI() for _ in range(N)]
V = N*10**3
dp = [[float('INF')]*(V+1) for _ in range(N+1)]
dp[0][0] = 0
for i in range(1,N+1):
    w,v = wv[i-1]
        for j in range(V+1)):
        if j-v>=0 and dp[i-1][j-v]+w<=W:
            dp[i][j] = min(dp[i][j],dp[i-1][j-v]+w)
        dp[i][j] = min(dp[i][j],dp[i-1][j])
print(max([i for i in range(V+1) if dp[-1][i]<=W]))

Fixed code:
import itertools,sys
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
N,W = LI()
wv = [LI() for _ in range(N)]
V = N*10**3
dp = [[float('INF')]*(V+1) for _ in range(N+1)]
dp[0][0] = 0
for i,j in itertools.product(range(1,N+1),range(V+1)):
    w,v = wv[i-1]
    if j-v>=0:
        dp[i][j] = min(dp[i][j],dp[i-1][j-v]+w)
    dp[i][j] = min(dp[i][j],dp[i-1][j])
print(max([i for i in range(V+1) if dp[-1][i]<=W]))
Buggy code:
N, W = map(int, input().split())

w, v = [0]*N, [0]*N
for i in range(N):
    w[i], v[i] = map(int, input().split())
V = sum(v)

dp = [[float("inf")] * (V+1)  for _ in range(N+1)]
dp[0][0] = 0

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

ans = 0
for i in range(V+1):
    if dp[N][i] <= W:
        ans = i
print(ans)                        

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

V = sum(v)
dp = [[float("inf")] * (V + 1) for _ in range(N + 1)]
dp[0][0] = 0
for i in range(N):
	for j in range(V + 1):
		if j - v[i] >= 0:
			dp[i + 1][j] = min(dp[i + 1][j], dp[i][j - v[i]] + w[i])
		dp[i + 1][j] = min(dp[i + 1][j], dp[i][j])

ans = 0
for j in range(V + 1):
	if dp[N][j] <= W:
		ans = j

print(ans)
Buggy code:
N, W = map(int, input().split())
max_value = N*(10**3)
dp = [[10**11]*(max_value+1) for _ in range(N+1)]
dp[0][0]=0
for j in range(1, N+1):
    w, v = map(int, input().split())
    for k in range(1, max_value+1):
        if k < v:
            dp[j][k] = dp[j-1][k]
        else:
            dp[j][k] = min(dp[j-1][k-v]+w, dp[j-1][k])
answer = 0
for index, weight in enumerate(dp[N]):
    if weight <= W:
        answer = index
print(answer)

Fixed code:
N, W = map(int, input().split())
max_value = N*(10**3)
dp = [[10**11]*(max_value+1) for _ in range(N+1)]
dp[0][0]=0
for j in range(1, N+1):
    w, v = map(int, input().split())
    for k in range(0, max_value+1):
        if k < v:
            dp[j][k] = dp[j-1][k]
        else:
            dp[j][k] = min(dp[j-1][k-v]+w, dp[j-1][k])
answer = 0
for index, weight in enumerate(dp[N]):
    if weight <= W:
        answer = index
print(answer)
Buggy code:
N, W = [int(i) for i in input().split()]
Things = [[int(i) for i in input().split()] for j in range(N)]

dp = defaultdict(lambda: float('inf'))
dp[0] = 0
for w, v in Things:
    for nv, nw in list(dp.items()):
        if nw + w <= W:
            dp[nv + v] = min(dp[nv + v], nw + w)
ans = 0
for v, w in dp.items():
    if w <= W and v >= ans:
        ans = v
print(ans)

Fixed code:
from collections import defaultdict
N, W = [int(i) for i in input().split()]
Things = [[int(i) for i in input().split()] for j in range(N)]

dp = defaultdict(lambda: float('inf'))
dp[0] = 0
for w, v in Things:
    for nv, nw in list(dp.items()):
        if nw + w <= W:
            dp[nv + v] = min(dp[nv + v], nw + w)
ans = 0
for v, w in dp.items():
    if w <= W and v >= ans:
        ans = v
print(ans)
Buggy code:
N, W = map(int, input().split())
w, v = [], []
for i in range(N):
    wi, vi = map(int, input().split())
    w.append(wi)
    v.append(vi)

v_sum = sum(v) + 1
inf = float('inf')
dp = [inf] * v_sum
dp[0] = 0

for i in range(N):
    for j in reversed(range(v_sum)):
        if j + v[i] < v_sum and dp[j] != inf:
            dp[j + v[i]] = min(dp[j + v[i]], dp[j] + w[i])

print(dp)

for i in reversed(range(v_sum)):
    if dp[i] <= W:
        print(i)
        break

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

v_sum = sum(v) + 1
inf = float('inf')
dp = [inf] * v_sum
dp[0] = 0

for i in range(N):
    for j in reversed(range(v_sum)):
        if j + v[i] < v_sum and dp[j] != inf:
            dp[j + v[i]] = min(dp[j + v[i]], dp[j] + w[i])

for i in reversed(range(v_sum)):
    if dp[i] <= W:
        print(i)
        break
Buggy code:
N,W = map(int, input().split())
w = [0] * N
v = [0] * N
for i in range(N):
    w[i], v[i] = map(int, input().split())
inf = float('inf')    
dp=[[inf for i in range(N+1)] for j in range(N*1000+1)] 

dp[0][0]=0

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

for i in reversed(range(N*1000+1)):
    if dp[i][N]<=W:
        print(i)
        break

Fixed code:
N,W = map(int, input().split())
w = [0] * N
v = [0] * N
for i in range(N):
    w[i], v[i] = map(int, input().split())
inf = float('inf')    
dp=[[inf for i in range(N+1)] for j in range(N*1000+1)] 

dp[0][0]=0

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


            
for i in reversed(range(N*1000+1)):
    if dp[i][N]<=W:
        print(i)
        break
#for i in reversed(range(N*1000+1)):
 #   print('{} '.format(i),dp[i][N])
Buggy code:
N,W=map(int,input().split())
w=[0]*N
v=[0]*N
for i in range(N):
    a,b=map(int,input().split())
    w.append(a)
    v.append(b)
V=sum(v)

dp=[[float("inf") ]*(V+1) for _ in range(110)]
dp[0][0]=0

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

        dp[i+1][j]=min(dp[i+1][j],dp[i][j])


ans=0

for j in range(V+1):
    if dp[N][j]<=W:
        ans=j

print(ans)


Fixed code:
N,W=map(int,input().split())
w=[0]*N
v=[0]*N
for i in range(N):
    w[i],v[i]=map(int,input().split())
V=sum(v)

dp=[[float("inf") ]*(V+1) for _ in range(110)]
dp[0][0]=0

for i in range(0,N):
    for j in range(V+1):
        if j-v[i]>=0:
            dp[i+1][j]=min(dp[i+1][j],dp[i][j-v[i]]+w[i])
        dp[i+1][j]=min(dp[i+1][j],dp[i][j])
ans=0
for j in range(V+1):
    if dp[N][j]<=W:
        ans=j
print(ans)
Buggy code:
N, W = [int(i) for i in input().split()]
weight, value = [0] * (N), [0] * (N)
for i in range(N):
    weight[i], value[i] = [int(i) for i in input().split()]

#%%

sum_value = sum(value)
dp = [[float("inf")] * (sum_value + 1) for _ in range(N + 1)]
dp[0][0] = 0

#%%

for i in range(N):
    for j in range(sum_value + 1):
        if j >= value[i]:
            dp[i + 1][j] = min(weight[i] + dp[i][j - value[i]], dp[i + 1][j])
        else:
            dp[i + 1][j] = min(dp[i + 1][j], dp[i][j])

#%%

ans = 0
for i in range(sum_value + 1):
    if dp[N][i] <= W:
        ans = i
        
print(ans)


Fixed code:
N, W = [int(i) for i in input().split()]
weight, value = [0] * (N), [0] * (N)
for i in range(N):
    weight[i], value[i] = [int(i) for i in input().split()]

#%%

sum_value = sum(value)
dp = [[float("inf")] * (sum_value + 1) for _ in range(N + 1)]
dp[0][0] = 0

#%%

for i in range(N):
    for j in range(sum_value + 1):
        if j >= value[i]:
            dp[i + 1][j] = min(weight[i] + dp[i][j - value[i]], dp[i + 1][j])
        dp[i + 1][j] = min(dp[i + 1][j], dp[i][j])

#%%

ans = 0
for i in range(sum_value + 1):
    if dp[N][i] <= W:
        ans = i
        
print(ans)
Buggy code:
def main():
    INF = 10**9
    N,W = map(int,input().split())
    wv = [list(map(int,input().split())) for _ in range(N)]
    sumv = sum([v for w,v in wv])
    dp = [[INF]*(sumv+1) for _ in range(N+1)]
    dp[0][0] = 0
    for i in range(N):
        for j in range(sumv+1):
            if j-wv[i][1] >= 0:
                dp[i+1][j] = min(dp[i][j],dp[i][j-wv[i][1]]+wv[i][0])
            else:
                dp[i+1][j] = dp[i][j]
    ans = 0
    for i in range(sumv+1):
        if dp[N][i] <= W:
            ans = max(ans,i)
    print(ans)
    print(dp)
if __name__ == '__main__':
    main()

Fixed code:
def main():
    INF = float('inf')
    N,W = map(int,input().split())
    wv = [list(map(int,input().split())) for _ in range(N)]
    sumv = sum([v for w,v in wv])
    dp = [[INF]*(sumv+1) for _ in range(N+1)]
    dp[0][0] = 0
    for i in range(N):
        for j in range(sumv+1):
            if j-wv[i][1] >= 0:
                dp[i+1][j] = min(dp[i][j],dp[i][j-wv[i][1]]+wv[i][0])
            else:
                dp[i+1][j] = dp[i][j]
    ans = 0
    for i in range(sumv+1):
        if dp[N][i] <= W:
            ans = max(ans,i)
    print(ans)
if __name__ == '__main__':
    main()
Buggy code:
import sys


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    n, w = list(map(int, readline().split()))
    wv = [list(map(int, readline().split())) for _ in range(n)]
    dp = [0] * (w + 1)
    for ww, vv in wv:
        for i in range(w-ww+1, -1, -1):
            if i + ww <= w:
                dp[i+ww] = max(dp[i+ww], dp[i] + vv)
    print(dp[-1])


if __name__ == '__main__':
    solve()


Fixed code:
import sys


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    n, w = list(map(int, readline().split()))
    wv = [list(map(int, readline().split())) for _ in range(n)]
    dp = [10 ** 10] * (10 ** 3 * n + 1)
    dp[0] = 0
    max_v = 0
    for ww, vv in wv:
        for i in range(max_v, -1, -1):
            dp[i+vv] = min(dp[i+vv], dp[i] + ww)
            max_v = max(max_v, i+vv)
    mt = 0
    for i in range(len(dp)):
        if dp[i] <= w:
            mt = max(mt, i)
    print(mt)


if __name__ == '__main__':
    solve()