Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
def main():
	N,W = map(int, input().split())
	dp = [0 for _ in range(W+1)]
	for _ in range(N):
		w,v = map(int, input().split())
		for i in range(W,0,-1):
			if i>=w:
				dp[i] = max(dp[i],dp[i-w]+v)
		
	print(dp[-1])

if __name__ == '__main__':
	main()

Fixed submission:
import sys
input = sys.stdin.readline
def main():
	N,W = map(int, input().split())
	dp = [0 for _ in range(W+1)]
	for _ in range(N):
		w,v = map(int, input().split())
		for i in range(W,0,-1):
			if i>=w:
				a = dp[i]
				b = dp[i-w]+v
				if a>b:
					dp[i] = a
				else:
					dp[i] = b
		
	print(dp[-1])

if __name__ == '__main__':
	main()

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

N,W = map(int, input().split())
dp = [0 for _ in range(W+1)]
for _ in range(N):
	w,v = map(int, input().split())
	for i in range(W,0,-1):
		if i>=w:
			dp[i] = max(dp[i],dp[i-w]+v)
	
print(dp[-1])

Fixed submission:
import sys
input = sys.stdin.readline
def main():
	N,W = map(int, input().split())
	dp = [0 for _ in range(W+1)]
	for _ in range(N):
		w,v = map(int, input().split())
		for i in range(W,0,-1):
			if i>=w:
				a = dp[i]
				b = dp[i-w]+v
				if a>b:
					dp[i] = a
				else:
					dp[i] = b
		
	print(dp[-1])

if __name__ == '__main__':
	main()

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

N,W = map(int, sys.stdin.buffer.readline().split())
dp = [0 for _ in range(W+1)]
for _ in range(N):
	w,v = map(int, sys.stdin.buffer.readline().split())
	for i in range(W,0,-1):
		if i-w>=0:
			dp[i] = max(dp[i],dp[i-w]+v)
	
print(dp[W])

Fixed submission:
import sys
input = sys.stdin.readline
def main():
	N,W = map(int, input().split())
	dp = [0 for _ in range(W+1)]
	for _ in range(N):
		w,v = map(int, input().split())
		for i in range(W,0,-1):
			if i>=w:
				a = dp[i]
				b = dp[i-w]+v
				if a>b:
					dp[i] = a
				else:
					dp[i] = b
		
	print(dp[-1])

if __name__ == '__main__':
	main()

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

Fixed submission:
import sys
input = sys.stdin.readline
def main():
	N,W = map(int, input().split())
	dp = [0 for _ in range(W+1)]
	for _ in range(N):
		w,v = map(int, input().split())
		for i in range(W,0,-1):
			if i>=w:
				a = dp[i]
				b = dp[i-w]+v
				if a>b:
					dp[i] = a
				else:
					dp[i] = b
		
	print(dp[-1])

if __name__ == '__main__':
	main()

Buggy python submission (verdict: Time Limit Exceeded):
N,W = map(int, input().split())
item = []
for i in range(N):
	item.append(list(map(int, input().split())))
item = [[0,0]] + item

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

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

Fixed submission:
import sys
input = sys.stdin.readline
def main():
	N,W = map(int, input().split())
	dp = [0 for _ in range(W+1)]
	for _ in range(N):
		w,v = map(int, input().split())
		for i in range(W,0,-1):
			if i>=w:
				a = dp[i]
				b = dp[i-w]+v
				if a>b:
					dp[i] = a
				else:
					dp[i] = b
		
	print(dp[-1])

if __name__ == '__main__':
	main()

Buggy python submission (verdict: Time Limit Exceeded):
N,W = map(int, input().split())
item = []
for i in range(N):
	item.append(list(map(int, input().split())))
item = [[0,0]] + item

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

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

Fixed submission:
import sys
input = sys.stdin.readline
def main():
	N,W = map(int, input().split())
	dp = [0 for _ in range(W+1)]
	for _ in range(N):
		w,v = map(int, input().split())
		for i in range(W,0,-1):
			if i>=w:
				a = dp[i]
				b = dp[i-w]+v
				if a>b:
					dp[i] = a
				else:
					dp[i] = b
		
	print(dp[-1])

if __name__ == '__main__':
	main()