Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import math

# NO, PAY-PAY
#import numpy as np
#import statistics
#from statistics import mean, median,variance,stdev

def main():
	N, W = map(int, input().split())
	wv = []
	for i in range(N):
		w, v = map(int, input().split())
		if w <= W:
			wv.append((w,v))
		
	DP = [[0 for _ in range(100000)] for _ in range(N)]
	
	for i, val in enumerate(wv):
		w, v = val
		if i == 0:
			DP[i][w] = v
			continue
			
		for j in range(W):
			DP[i][j] = max(DP[i-1][j], DP[i][j])
			
			if j+w <= W:
				DP[i][j+w] = max(DP[i-1][j] + v, DP[i][j+w])
			
	print(max(DP[N-1]))
	
if __name__ == "__main__":
	main()


Fixed submission:
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import math

# NO, PAY-PAY
#import numpy as np
#import statistics
#from statistics import mean, median,variance,stdev

def main():
	N, W = map(int, input().split())
	wv = []
	for i in range(N):
		w, v = map(int, input().split())
		if w <= W:
			wv.append((w,v))
		
	DP = [[0 for _ in range(100001)] for _ in range(N)]
	
	for i, val in enumerate(wv):
		w, v = val
		if i == 0:
			DP[i][w] = v
			continue
			
		for j in range(W):
			DP[i][j] = max(DP[i-1][j], DP[i][j])
			
			if j+w <= W:
				DP[i][j+w] = max(DP[i-1][j] + v, DP[i][j+w])
			
	print(max(DP[N-1]))
	
if __name__ == "__main__":
	main()

Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import math

# NO, PAY-PAY
#import numpy as np
#import statistics
#from statistics import mean, median,variance,stdev

def main():
	N, W = map(int, input().split())
	wv = []
	for i in range(N):
		w, v = map(int, input().split())
		if w <= W:
			wv.append((w,v))
		
	DP = [[0 for _ in range(100000)] for _ in range(N)]
	
	for i, val in enumerate(wv):
		w, v = val
		if i == 0:
			DP[i][w] = v
			continue
			
		for j in range(W):
			DP[i][j] = max(DP[i-1][j], DP[i][j])
			
			if j+w <= W:
				DP[i][j+w] = max(DP[i-1][j] + v, DP[i][j+w])
			
	print(max(DP[N-1]))
	
if __name__ == "__main__":
	main()


Fixed submission:
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import math

# NO, PAY-PAY
#import numpy as np
#import statistics
#from statistics import mean, median,variance,stdev

def main():
	N, W = map(int, input().split())
	wv = []
	for i in range(N):
		w, v = map(int, input().split())
		if w <= W:
			wv.append((w,v))
		
	DP = [[0 for _ in range(100001)] for _ in range(N)]
	
	for i, val in enumerate(wv):
		w, v = val
		if i == 0:
			DP[i][w] = v
			continue
			
		for j in range(W):
			DP[i][j] = max(DP[i-1][j], DP[i][j])
			
			if j+w <= W:
				DP[i][j+w] = max(DP[i-1][j] + v, DP[i][j+w])
			
	print(max(DP[N-1]))
	
if __name__ == "__main__":
	main()

Buggy python submission (verdict: Runtime Error):
#include <iostream>
#include <queue>
using namespace std;

typedef long long ll;
#define repi(i, a, b) for(int i = int(a); i < int(b); ++i)
#define rep(i, n) repi(i, 0, n)
#define rerepi(i, a, b) for(int i = int(a)-1; i >= b; --i)
#define rerep(i, n) rerepi(i, n, 0)

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const long long INF = 1LL << 60;

ll N, W;
std::vector<ll> objs_w;
std::vector<ll> objs_v;
ll DP[110][100010];

// ここから開始だよ！
int main() {
	// 呪文エリア
	cin.tie(0);
	ios::sync_with_stdio(false);
	// 詠唱完了
  
  cin >> N >> W;
  rep(i, N) {
    ll w, v;
    cin >> w >> v;
    objs_w.push_back(w);
    objs_v.push_back(v);
  }
  
  DP[0][0] = 0;
  
  rep(nn, N+1) {
    rep(ww, W+1) {
      ll w = objs_w[nn];
      ll v = objs_v[nn];
      
      chmax(DP[nn+1][ww], DP[nn][ww]);
      if (ww - w >= 0) {
        chmax(DP[nn+1][ww], DP[nn][ww - w] + v);
      }
    }
  }
	
  cout << DP[N][W] << endl;
  
	return 0;
}


Fixed submission:
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import math

# NO, PAY-PAY
#import numpy as np
#import statistics
#from statistics import mean, median,variance,stdev

def main():
	N, W = map(int, input().split())
	wv = []
	for i in range(N):
		w, v = map(int, input().split())
		if w <= W:
			wv.append((w,v))
		
	DP = [[0 for _ in range(100001)] for _ in range(N)]
	
	for i, val in enumerate(wv):
		w, v = val
		if i == 0:
			DP[i][w] = v
			continue
			
		for j in range(W):
			DP[i][j] = max(DP[i-1][j], DP[i][j])
			
			if j+w <= W:
				DP[i][j+w] = max(DP[i-1][j] + v, DP[i][j+w])
			
	print(max(DP[N-1]))
	
if __name__ == "__main__":
	main()

Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
import sys

def main():
	N, W = map(int, input().split(" "))
	objs = []
	for _ in range(N):
		w, v = map(int, input().split(" "))
		objs.append((w, v))
		
	DP = [[0 for _ in range(W+2)] for _ in range(N+1)]
	
	for i, val in enumerate(objs):
		w, v = val
		for j in range(1, W+1):
			DP[i+1][j] = max(DP[i+1][j], DP[i][j])
			if j - w >= 0:
				#print("{} {}".format(j+w, i+1))
				DP[i+1][j] = max(DP[i+1][j], DP[i][j-w] + v)
				
	print(DP[N][W])
	
if __name__ == "__main__":
	main()


Fixed submission:
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import math

# NO, PAY-PAY
#import numpy as np
#import statistics
#from statistics import mean, median,variance,stdev

def main():
	N, W = map(int, input().split())
	wv = []
	for i in range(N):
		w, v = map(int, input().split())
		if w <= W:
			wv.append((w,v))
		
	DP = [[0 for _ in range(100001)] for _ in range(N)]
	
	for i, val in enumerate(wv):
		w, v = val
		if i == 0:
			DP[i][w] = v
			continue
			
		for j in range(W):
			DP[i][j] = max(DP[i-1][j], DP[i][j])
			
			if j+w <= W:
				DP[i][j+w] = max(DP[i-1][j] + v, DP[i][j+w])
			
	print(max(DP[N-1]))
	
if __name__ == "__main__":
	main()

Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
import sys

def main():
	N, W = map(int, input().split(" "))
	objs = []
	for _ in range(N):
		w, v = map(int, input().split(" "))
		objs.append((w, v))
		
	DP = [[0 for _ in range(W+2)] for _ in range(N+1)]
	
	for i, val in enumerate(objs):
		w, v = val
		for j in range(1, W+1):
			DP[i+1][j] = max(DP[i+1][j], DP[i][j])
			if j - w >= 0:
				#print("{} {}".format(j+w, i+1))
				DP[i+1][j] = max(DP[i+1][j], DP[i][j-w] + v)
				
	ans = 0
	#print(DP)
	for i in range(W+1):
		for j in range(N+1):
			if ans < DP[j][i]:
				ans = DP[j][i]
				
	print(ans)
	
if __name__ == "__main__":
	main()


Fixed submission:
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import math

# NO, PAY-PAY
#import numpy as np
#import statistics
#from statistics import mean, median,variance,stdev

def main():
	N, W = map(int, input().split())
	wv = []
	for i in range(N):
		w, v = map(int, input().split())
		if w <= W:
			wv.append((w,v))
		
	DP = [[0 for _ in range(100001)] for _ in range(N)]
	
	for i, val in enumerate(wv):
		w, v = val
		if i == 0:
			DP[i][w] = v
			continue
			
		for j in range(W):
			DP[i][j] = max(DP[i-1][j], DP[i][j])
			
			if j+w <= W:
				DP[i][j+w] = max(DP[i-1][j] + v, DP[i][j+w])
			
	print(max(DP[N-1]))
	
if __name__ == "__main__":
	main()

Buggy python submission (verdict: Time Limit Exceeded):
 # -*- coding: utf-8 -*-
import sys
input = sys.stdin.readline

def main():
	N, W = map(int, input().split(" "))
	#goods = []
	#for _ in range(N):
		#w, v = map(int, input().split(" "))
		#goods.append((w, v))
		
	DP = [[0] * (W+2) for _ in range(N+1)]
	for i in range(N):
		#w, v = goods[i]
		w, v = map(int, input().split(" "))
		for w_sum in range(W+1):
			DP[i+1][w_sum] = max(DP[i+1][w_sum], DP[i][w_sum])
			if w_sum - w >= 0:
				DP[i+1][w_sum] = max(DP[i+1][w_sum], DP[i][w_sum - w] + v)
		
	print(DP[N][W])
		
if __name__ == "__main__":
	main()
	

Fixed submission:
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import math

# NO, PAY-PAY
#import numpy as np
#import statistics
#from statistics import mean, median,variance,stdev

def main():
	N, W = map(int, input().split())
	wv = []
	for i in range(N):
		w, v = map(int, input().split())
		if w <= W:
			wv.append((w,v))
		
	DP = [[0 for _ in range(100001)] for _ in range(N)]
	
	for i, val in enumerate(wv):
		w, v = val
		if i == 0:
			DP[i][w] = v
			continue
			
		for j in range(W):
			DP[i][j] = max(DP[i-1][j], DP[i][j])
			
			if j+w <= W:
				DP[i][j+w] = max(DP[i-1][j] + v, DP[i][j+w])
			
	print(max(DP[N-1]))
	
if __name__ == "__main__":
	main()

Buggy python submission (verdict: Time Limit Exceeded):
 # -*- coding: utf-8 -*-
import sys
input = sys.stdin.readline

def main():
	N, W = map(int, input().split(" "))
	goods = []
	for _ in range(N):
		w, v = map(int, input().split(" "))
		goods.append((w, v))
		
	DP = [[0] * (W+2) for _ in range(N+1)]
	for i in range(N):
		w, v = goods[i]
		for w_sum in range(W+1):
			DP[i+1][w_sum] = max(DP[i+1][w_sum], DP[i][w_sum])
			if w_sum - w >= 0:
				DP[i+1][w_sum] = max(DP[i+1][w_sum], DP[i][w_sum - w] + v)
		
	print(DP[N][W])
		
if __name__ == "__main__":
	main()
	

Fixed submission:
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import math

# NO, PAY-PAY
#import numpy as np
#import statistics
#from statistics import mean, median,variance,stdev

def main():
	N, W = map(int, input().split())
	wv = []
	for i in range(N):
		w, v = map(int, input().split())
		if w <= W:
			wv.append((w,v))
		
	DP = [[0 for _ in range(100001)] for _ in range(N)]
	
	for i, val in enumerate(wv):
		w, v = val
		if i == 0:
			DP[i][w] = v
			continue
			
		for j in range(W):
			DP[i][j] = max(DP[i-1][j], DP[i][j])
			
			if j+w <= W:
				DP[i][j+w] = max(DP[i-1][j] + v, DP[i][j+w])
			
	print(max(DP[N-1]))
	
if __name__ == "__main__":
	main()

Buggy python submission (verdict: Time Limit Exceeded):
 # -*- coding: utf-8 -*-
import sys

def main():
	N, W = map(int, input().split(" "))
	goods = []
	for _ in range(N):
		w, v = map(int, input().split(" "))
		goods.append((w, v))
		
	DP = [[0 for _ in range(W+2)] for _ in range(N+1)]
	for i in range(N):
		w, v = goods[i]
		for w_sum in range(W+1):
			DP[i+1][w_sum] = max(DP[i+1][w_sum], DP[i][w_sum])
			if w_sum - w >= 0:
				DP[i+1][w_sum] = max(DP[i+1][w_sum], DP[i][w_sum - w] + v)
		
	print(DP[N][W])
		
if __name__ == "__main__":
	main()
	

Fixed submission:
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import math

# NO, PAY-PAY
#import numpy as np
#import statistics
#from statistics import mean, median,variance,stdev

def main():
	N, W = map(int, input().split())
	wv = []
	for i in range(N):
		w, v = map(int, input().split())
		if w <= W:
			wv.append((w,v))
		
	DP = [[0 for _ in range(100001)] for _ in range(N)]
	
	for i, val in enumerate(wv):
		w, v = val
		if i == 0:
			DP[i][w] = v
			continue
			
		for j in range(W):
			DP[i][j] = max(DP[i-1][j], DP[i][j])
			
			if j+w <= W:
				DP[i][j+w] = max(DP[i-1][j] + v, DP[i][j+w])
			
	print(max(DP[N-1]))
	
if __name__ == "__main__":
	main()

Buggy python submission (verdict: Time Limit Exceeded):
 # -*- coding: utf-8 -*-
import sys

def main():
	N, W = map(int, input().split(" "))
	goods = []
	for _ in range(N):
		w, v = map(int, input().split(" "))
		goods.append((w, v))
		
	ans = 0
	for i in range(2 ** N):
		val = 0
		wal = 0
		flg = True
		for j in range(N):
			if i >> j & 1 == 1:
				w, v = goods[j]
				val += v
				wal += w
				if W < wal:
					flg = False
					break
		if flg == False:
			continue
		if ans < val:
			ans = val
		
	print(ans)
		
if __name__ == "__main__":
	main()
	

Fixed submission:
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import math

# NO, PAY-PAY
#import numpy as np
#import statistics
#from statistics import mean, median,variance,stdev

def main():
	N, W = map(int, input().split())
	wv = []
	for i in range(N):
		w, v = map(int, input().split())
		if w <= W:
			wv.append((w,v))
		
	DP = [[0 for _ in range(100001)] for _ in range(N)]
	
	for i, val in enumerate(wv):
		w, v = val
		if i == 0:
			DP[i][w] = v
			continue
			
		for j in range(W):
			DP[i][j] = max(DP[i-1][j], DP[i][j])
			
			if j+w <= W:
				DP[i][j+w] = max(DP[i-1][j] + v, DP[i][j+w])
			
	print(max(DP[N-1]))
	
if __name__ == "__main__":
	main()

Buggy python submission (verdict: Time Limit Exceeded):
 # -*- coding: utf-8 -*-
import sys

def main():
	N, W = map(int, input().split(" "))
	goods = []
	for _ in range(N):
		w, v = map(int, input().split(" "))
		goods.append((w, v))
		
	ans = 0
	for i in range(2 ** N):
		val = 0
		wal = 0
		for j in range(N):
			if i >> j & 1 == 1:
				w, v = goods[j]
				val += v
				wal += w
		if W < wal:
			continue
		if ans < val:
			ans = val
		
	print(ans)
		
if __name__ == "__main__":
	main()
	

Fixed submission:
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import math

# NO, PAY-PAY
#import numpy as np
#import statistics
#from statistics import mean, median,variance,stdev

def main():
	N, W = map(int, input().split())
	wv = []
	for i in range(N):
		w, v = map(int, input().split())
		if w <= W:
			wv.append((w,v))
		
	DP = [[0 for _ in range(100001)] for _ in range(N)]
	
	for i, val in enumerate(wv):
		w, v = val
		if i == 0:
			DP[i][w] = v
			continue
			
		for j in range(W):
			DP[i][j] = max(DP[i-1][j], DP[i][j])
			
			if j+w <= W:
				DP[i][j+w] = max(DP[i-1][j] + v, DP[i][j+w])
			
	print(max(DP[N-1]))
	
if __name__ == "__main__":
	main()