Buggy python submission (verdict: Time Limit Exceeded):
import sys
input=sys.stdin.readline
n,w=map(int,input().split())
cos=[0]*(w+1)
for i in range(n):
 w1,v1=map(int,input().split())
 for j in range(w,w1-1,-1):
  f=cos[j-w1]+v1
  if(cos[j]<f):
   cos[j]=f
print(cos[-1])

  


Fixed submission:
import sys
input=sys.stdin.readline
def fun(n,w):
 cos=[0]*(w+1)
 for i in range(n):
  w1,v1=map(int,input().split())
  for j in range(w,w1-1,-1):
   f=cos[j-w1]+v1
   if(cos[j]<f):
    cos[j]=f
 print(cos[-1])
n,w=map(int,input().split())
fun(n,w)

Buggy python submission (verdict: Time Limit Exceeded):
n,w=map(int,input().split())
cos=[0]*(w+1)
for i in range(n):
 w1,v1=map(int,input().split())
 for j in range(w,w1-1,-1):
  f=cos[j-w1]+v1
  if(cos[j]<f):
   cos[j]=f
print(cos[-1])

  


Fixed submission:
import sys
input=sys.stdin.readline
def fun(n,w):
 cos=[0]*(w+1)
 for i in range(n):
  w1,v1=map(int,input().split())
  for j in range(w,w1-1,-1):
   f=cos[j-w1]+v1
   if(cos[j]<f):
    cos[j]=f
 print(cos[-1])
n,w=map(int,input().split())
fun(n,w)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10**6)
def bknap(curw,wei,val,n):
 if(n==0 or curw==0):
  return 0
 if(wei[n-1]>curw):
  return bknap(curw,wei,val,n-1)
 else:
  return max(val[n-1]+bknap(curw-wei[n-1],wei,val,n-1),bknap(curw,wei,val,n-1))
n,w=map(int,input().split())
wei=[]
val=[]
for i in range(n):
 w1,v1=map(int,input().split())
 wei.append(w1)
 val.append(v1)
print(bknap(w,wei,val,n))

  


Fixed submission:
import sys
input=sys.stdin.readline
def fun(n,w):
 cos=[0]*(w+1)
 for i in range(n):
  w1,v1=map(int,input().split())
  for j in range(w,w1-1,-1):
   f=cos[j-w1]+v1
   if(cos[j]<f):
    cos[j]=f
 print(cos[-1])
n,w=map(int,input().split())
fun(n,w)

Buggy python submission (verdict: Time Limit Exceeded):
def bknap(W, wt, val, n): 
 K = [[0 for x in range(W + 1)] for x in range(n + 1)] 
 for i in range(n + 1): 
  for w in range(W + 1): 
   if i == 0 or w == 0: 
    K[i][w] = 0
   elif wt[i-1] <= w: 
    K[i][w] = max(val[i-1] + K[i-1][w-wt[i-1]],  K[i-1][w]) 
   else: 
    K[i][w] = K[i-1][w] 
 return K[n][W] 
n,w=map(int,input().split())
wei=[]
val=[]
for i in range(n):
 w1,v1=map(int,input().split())
 wei.append(w1)
 val.append(v1)
print(bknap(w,wei,val,n))

  


Fixed submission:
import sys
input=sys.stdin.readline
def fun(n,w):
 cos=[0]*(w+1)
 for i in range(n):
  w1,v1=map(int,input().split())
  for j in range(w,w1-1,-1):
   f=cos[j-w1]+v1
   if(cos[j]<f):
    cos[j]=f
 print(cos[-1])
n,w=map(int,input().split())
fun(n,w)

Buggy python submission (verdict: Time Limit Exceeded):
def bknap(curw,wei,val,n):
 if(n==0 or curw==0):
  return 0
 if(wei[n-1]>curw):
  return bknap(curw,wei,val,n-1)
 else:
  return max(val[n-1]+bknap(curw-wei[n-1],wei,val,n-1),bknap(curw,wei,val,n-1))
n,w=map(int,input().split())
wei=[]
val=[]
for i in range(n):
 w1,v1=map(int,input().split())
 wei.append(w1)
 val.append(v1)
print(bknap(w,wei,val,n))

  


Fixed submission:
import sys
input=sys.stdin.readline
def fun(n,w):
 cos=[0]*(w+1)
 for i in range(n):
  w1,v1=map(int,input().split())
  for j in range(w,w1-1,-1):
   f=cos[j-w1]+v1
   if(cos[j]<f):
    cos[j]=f
 print(cos[-1])
n,w=map(int,input().split())
fun(n,w)