Buggy python submission (verdict: Runtime Error):
N, W = list(map(int, input().split(" ")))
 
for i in range(0, N):
	for w in range(1, W+1):
		weight, vvalue = list(map(int, input().split(" ")))
		if w >= weight:
			dp[i + 1][w] = max([dp[i][w - weight] + value, dp[i][w]])
		else:
			dp[i + 1][w] = dp[i][w]
print(dp[N][W])

Fixed submission:
N, W = list(map(int, input().split(" ")))
dp =  [[0] * (W+1) for _ in range(N+1)]
 
for i in range(0, N):
	weight, value = map(int, input().split(" "))
	for w in range(1, W+1):
		if w >= weight:
			dp[i + 1][w] = max([dp[i][w - weight] + value, dp[i][w]])
		else:
			dp[i + 1][w] = dp[i][w]
print(dp[N][W])

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

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

for i in range(0, N):
	for w in range(1, W+1):
		weight = l[i-1][0]
		value = l[i-1][1]
		if w >= weight:
			dp[i + 1][w] = max([dp[i][w - weight] + value, dp[i][w]])
		else:
			dp[i + 1][w] = dp[i][w]
print(dp[N][W])


Fixed submission:
N, W = list(map(int, input().split(" ")))
dp =  [[0] * (W+1) for _ in range(N+1)]
 
for i in range(0, N):
	weight, value = map(int, input().split(" "))
	for w in range(1, W+1):
		if w >= weight:
			dp[i + 1][w] = max([dp[i][w - weight] + value, dp[i][w]])
		else:
			dp[i + 1][w] = dp[i][w]
print(dp[N][W])

Buggy python submission (verdict: Time Limit Exceeded):
from functools import lru_cache
import sys
 
sys.setrecursionlimit(1000000)
 
N, W = list(map(int, input().split(" ")))
 
l = []
for i in range(N):
	w, v = list(map(int, input().split(" ")))
	l.append((w, v))
    
@lru_cache(maxsize=1000000)
def dp(i, score, remaining_weight):
	if (i < 0):
		return score
	if remaining_weight >= l[i][0]:
		# on / off
		return max([dp(i - 1, score + l[i][1], remaining_weight - l[i][0]), dp(i - 1, score, remaining_weight)])
	else:
		return dp(i-1, score, remaining_weight)
 
print(dp(N-1, 0, W))

Fixed submission:
N, W = list(map(int, input().split(" ")))
dp =  [[0] * (W+1) for _ in range(N+1)]
 
for i in range(0, N):
	weight, value = map(int, input().split(" "))
	for w in range(1, W+1):
		if w >= weight:
			dp[i + 1][w] = max([dp[i][w - weight] + value, dp[i][w]])
		else:
			dp[i + 1][w] = dp[i][w]
print(dp[N][W])

Buggy python submission (verdict: Time Limit Exceeded):
from functools import lru_cache
import sys

sys.setrecursionlimit(1000000)
 
N, W = list(map(int, input().split(" ")))
 
l = []
for i in range(N):
	w, v = list(map(int, input().split(" ")))
	l.append((w, v))
    
@lru_cache(maxsize=1000000)
def dp(i, score, remaining_weight):
	if (i < 0):
		return score
	if remaining_weight >= l[i][0]:
		# on / off
		return max([dp(i - 1, score + l[i][1], remaining_weight - l[i][0]), dp(i - 1, score, remaining_weight)])
	else:
		return dp(i-1, score, remaining_weight)
 
print(dp(N-1, 0, W))

Fixed submission:
N, W = list(map(int, input().split(" ")))
dp =  [[0] * (W+1) for _ in range(N+1)]
 
for i in range(0, N):
	weight, value = map(int, input().split(" "))
	for w in range(1, W+1):
		if w >= weight:
			dp[i + 1][w] = max([dp[i][w - weight] + value, dp[i][w]])
		else:
			dp[i + 1][w] = dp[i][w]
print(dp[N][W])

Buggy python submission (verdict: Time Limit Exceeded):
from functools import lru_cache


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

l = []
for i in range(N):
	w, v = list(map(int, input().split(" ")))
	l.append((w, v))
    
@lru_cache(maxsize=1000000)
def dp(i, score, remaining_weight):
	if (i < 0):
		return score
	if remaining_weight >= l[i][0]:
		# on / off
		return max([dp(i - 1, score + l[i][1], remaining_weight - l[i][0]), dp(i - 1, score, remaining_weight)])
	else:
		return dp(i-1, score, remaining_weight)

print(dp(N-1, 0, W))

Fixed submission:
N, W = list(map(int, input().split(" ")))
dp =  [[0] * (W+1) for _ in range(N+1)]
 
for i in range(0, N):
	weight, value = map(int, input().split(" "))
	for w in range(1, W+1):
		if w >= weight:
			dp[i + 1][w] = max([dp[i][w - weight] + value, dp[i][w]])
		else:
			dp[i + 1][w] = dp[i][w]
print(dp[N][W])

Buggy python submission (verdict: Time Limit Exceeded):
from functools import lru_cache


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

l = []
for i in range(N):
	w, v = list(map(int, input().split(" ")))
	l.append((w, v))
    
@lru_cache(maxsize=1000)
def dp(i, score, remaining_weight):
	if (i < 0):
		return score
	if remaining_weight >= l[i][0]:
		# on / off
		return max([dp(i - 1, score + l[i][1], remaining_weight - l[i][0]), dp(i - 1, score, remaining_weight)])
	else:
		return dp(i-1, score, remaining_weight)

print(dp(N-1, 0, W))

Fixed submission:
N, W = list(map(int, input().split(" ")))
dp =  [[0] * (W+1) for _ in range(N+1)]
 
for i in range(0, N):
	weight, value = map(int, input().split(" "))
	for w in range(1, W+1):
		if w >= weight:
			dp[i + 1][w] = max([dp[i][w - weight] + value, dp[i][w]])
		else:
			dp[i + 1][w] = dp[i][w]
print(dp[N][W])

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

l = []
for i in range(N):
	w, v = list(map(int, input().split(" ")))
	l.append((w, v))

def dp(i, score, remaining_weight):
	if (i < 0):
		return score
	if remaining_weight >= l[i][0]:
		# on / off
		return max([dp(i - 1, score + l[i][1], remaining_weight - l[i][0]), dp(i - 1, score, remaining_weight)])
	else:
		return dp(i-1, score, remaining_weight)

print(dp(N-1, 0, W))

Fixed submission:
N, W = list(map(int, input().split(" ")))
dp =  [[0] * (W+1) for _ in range(N+1)]
 
for i in range(0, N):
	weight, value = map(int, input().split(" "))
	for w in range(1, W+1):
		if w >= weight:
			dp[i + 1][w] = max([dp[i][w - weight] + value, dp[i][w]])
		else:
			dp[i + 1][w] = dp[i][w]
print(dp[N][W])