Buggy python submission (verdict: Runtime Error):
# from sys import stdin, stdout
n,capacity=map(int,input().split())
weights=[0]*n
values=[0]*n
for i in range(n):
    weights[i],values[i]=map(int,input().split())
dp=[[0]*(capacity+1) for i in range(n+1)]
for i in range(1,n+1):
    for j in range(1,weights+1):
        if(weights[i-1]<=j):
            dp[i][j]=max(values[i-1]+dp[i-1][j-weights[i-1]],dp[i-1][j])
        else:
            dp[i][j]=dp[i-1][j]
print(dp[n][capacity])

Fixed submission:
# from sys import stdin, stdout
n,capacity=map(int,input().split())
weights=[0]*n
values=[0]*n
for i in range(n):
    weights[i],values[i]=map(int,input().split())
dp=[[0]*(capacity+1) for i in range(n+1)]
for i in range(1,n+1):
    for j in range(1,capacity+1):
        if(weights[i-1]<=j):
            dp[i][j]=max(values[i-1]+dp[i-1][j-weights[i-1]],dp[i-1][j])
        else:
            dp[i][j]=dp[i-1][j]
print(dp[n][capacity])

Buggy python submission (verdict: Runtime Error):
from sys import stdin, stdout
n,capacity=map(int,stdin.readline().split())
weights=[0]*n
values=[0]*n
for i in range(n):
    weights[i],values[i]=map(int,stdin.readline().split())
dp=[[0]*(capacity+1) for i in range(n+1)]
for i in range(n+1):
    for j in range(weights+1):
        if(weights[i-1]<=j):
            dp[i][j]=max(values[i-1]+dp[i-1][j-weights[i-1]],dp[i-1][j])
        else:
            dp[i][j]=dp[i-1][j]
print(dp[n][capacity])

Fixed submission:
# from sys import stdin, stdout
n,capacity=map(int,input().split())
weights=[0]*n
values=[0]*n
for i in range(n):
    weights[i],values[i]=map(int,input().split())
dp=[[0]*(capacity+1) for i in range(n+1)]
for i in range(1,n+1):
    for j in range(1,capacity+1):
        if(weights[i-1]<=j):
            dp[i][j]=max(values[i-1]+dp[i-1][j-weights[i-1]],dp[i-1][j])
        else:
            dp[i][j]=dp[i-1][j]
print(dp[n][capacity])

Buggy python submission (verdict: Runtime Error):
from sys import stdin, stdout
def knapsack(weights,values,capacity,n,memo):
    if(memo[n][capacity]!=-1):
        return memo[n][capacity]
    if(n==0 or capacity==0):
        return 0
    val=0
    left=values[n-1]+knapsack(weights,values,capacity-weights[n-1],n-1,memo)
    right=knapsack(weights,values,capacity,n-1,memo)
    if(weights[n-1]<=capacity):
        temp=max(left,right)
        memo[n][capacity]=temp
        return temp
    memo[n][capacity]=right
    return right

n,capacity=map(int,stdin.readline().split())
weights=[0]*n
values=[0]*n
for i in range(n):
    weights[i],values[i]=map(int,stdin.readline().split())
memo=[[-1]*(capacity+1) for i in range(n+1)]
stdout.write(str(knapsack(weights,values,capacity,n,memo)))

Fixed submission:
# from sys import stdin, stdout
n,capacity=map(int,input().split())
weights=[0]*n
values=[0]*n
for i in range(n):
    weights[i],values[i]=map(int,input().split())
dp=[[0]*(capacity+1) for i in range(n+1)]
for i in range(1,n+1):
    for j in range(1,capacity+1):
        if(weights[i-1]<=j):
            dp[i][j]=max(values[i-1]+dp[i-1][j-weights[i-1]],dp[i-1][j])
        else:
            dp[i][j]=dp[i-1][j]
print(dp[n][capacity])

Buggy python submission (verdict: Time Limit Exceeded):
from sys import stdin, stdout
def knapsack(weights,values,capacity,n,memo):
    if(memo[n][capacity]!=-1):
        return memo[n][capacity]
    if(n==0 or capacity==0):
        return 0
    val=0
    if(weights[n-1]<=capacity):
        memo[n][capacity]=max(values[n-1]+knapsack(weights,values,capacity-weights[n-1],n-1,memo),knapsack(weights,values,capacity,n-1,memo))
        return memo[n][capacity]
    memo[n][capacity]=knapsack(weights,values,capacity,n-1,memo)
    return memo[n][capacity]

n,capacity=map(int,stdin.readline().split())
weights=[0]*n
values=[0]*n
for i in range(n):
    weights[i],values[i]=map(int,stdin.readline().split())
memo=[[-1]*(capacity+1) for i in range(n+1)]
stdout.write(str(knapsack(weights,values,capacity,n,memo)))

Fixed submission:
# from sys import stdin, stdout
n,capacity=map(int,input().split())
weights=[0]*n
values=[0]*n
for i in range(n):
    weights[i],values[i]=map(int,input().split())
dp=[[0]*(capacity+1) for i in range(n+1)]
for i in range(1,n+1):
    for j in range(1,capacity+1):
        if(weights[i-1]<=j):
            dp[i][j]=max(values[i-1]+dp[i-1][j-weights[i-1]],dp[i-1][j])
        else:
            dp[i][j]=dp[i-1][j]
print(dp[n][capacity])

Buggy python submission (verdict: Time Limit Exceeded):
from sys import stdin, stdout
def knapsack(weights,values,capacity,n,memo):
    if(memo[n][capacity]!=-1):
        return memo[n][capacity]
    if(n==0 or capacity==0):
        return 0
    val=0
    if(weights[n-1]<=capacity):
        memo[n][capacity]=max(values[n-1]+knapsack(weights,values,capacity-weights[n-1],n-1,memo),knapsack(weights,values,capacity,n-1,memo))
        return memo[n][capacity]
    memo[n][capacity]=knapsack(weights,values,capacity,n-1,memo)
    return memo[n][capacity]

n,capacity=map(int,stdin.readline().split())
weights=[0]*n
values=[0]*n
for i in range(n):
    weights[i],values[i]=map(int,stdin.readline().split())
memo=[[-1]*(capacity+1) for i in range(n+1)]
stdout.write(str(knapsack(weights,values,capacity,n,memo)))

Fixed submission:
# from sys import stdin, stdout
n,capacity=map(int,input().split())
weights=[0]*n
values=[0]*n
for i in range(n):
    weights[i],values[i]=map(int,input().split())
dp=[[0]*(capacity+1) for i in range(n+1)]
for i in range(1,n+1):
    for j in range(1,capacity+1):
        if(weights[i-1]<=j):
            dp[i][j]=max(values[i-1]+dp[i-1][j-weights[i-1]],dp[i-1][j])
        else:
            dp[i][j]=dp[i-1][j]
print(dp[n][capacity])

Buggy python submission (verdict: Time Limit Exceeded):
def knapsack(weights,values,capacity,n,memo):
    if(memo[n][capacity]!=-1):
        return memo[n][capacity]
    if(n==0 or capacity==0):
        return 0
    val=0
    if(weights[n-1]<=capacity):
        memo[n][capacity]=max(values[n-1]+knapsack(weights,values,capacity-weights[n-1],n-1,memo),knapsack(weights,values,capacity,n-1,memo))
        return memo[n][capacity]
    memo[n][capacity]=knapsack(weights,values,capacity,n-1,memo)
    return memo[n][capacity]

n,capacity=map(int,input().split())
weights=[0]*n
values=[0]*n
for i in range(n):
    weights[i],values[i]=map(int,input().split())
memo=[[-1]*(capacity+1) for i in range(n+1)]
print(knapsack(weights,values,capacity,n,memo))

Fixed submission:
# from sys import stdin, stdout
n,capacity=map(int,input().split())
weights=[0]*n
values=[0]*n
for i in range(n):
    weights[i],values[i]=map(int,input().split())
dp=[[0]*(capacity+1) for i in range(n+1)]
for i in range(1,n+1):
    for j in range(1,capacity+1):
        if(weights[i-1]<=j):
            dp[i][j]=max(values[i-1]+dp[i-1][j-weights[i-1]],dp[i-1][j])
        else:
            dp[i][j]=dp[i-1][j]
print(dp[n][capacity])