Buggy python submission (verdict: Time Limit Exceeded):
N, W = map(int, input().split())
# dp = np.zeros((N+1, W+1))  #i個目の品物までで重さw以下のときの価値の最大値 
dp = [[0]*(W+1) for _ in range(N+1)]
"""
dp[i, wi:W+1] = max(i番目の重さwiの品物を入れた場合, 入れなかった場合)
         = np.max(dp[i-1, :W-wi+1] + v, dp[i-1, wi:W+1])
"""

for i in range(1, N+1):
    w, v = map(int, input().split())

    for j in range(W+1):
        if j - w >= 0:
            for k in range(1, i+1):
                tmp = max(dp[i-k][j], dp[i-k][j-w] + v)
                dp[i][j] = max(dp[i][j], tmp)

print(dp[-1][-1])


Fixed submission:
N, W = map(int, input().split())
#i個目の品物までで重さw以下のときの価値の最大値 
dp = [[0]*(W+1) for _ in range(N+1)]
"""
dp[i, wi:W+1] = max(i番目の重さwiの品物を入れた場合, 入れなかった場合)
         = np.max(dp[i-1, :W-wi+1] + v, dp[i-1, wi:W+1])
"""

for i in range(1, N+1):
    w, v = map(int, input().split())

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

print(dp[-1][-1])

Buggy python submission (verdict: Runtime Error):
# import numpy as np

# N, W = map(int, input().split())
# dp = np.zeros((N+1, W+1))  #i個目の品物までで重さw以下のときの価値の最大値 
# """
# dp[i, wi:W+1] = max(i番目の重さwiの品物を入れた場合, 入れなかった場合)
#          = np.max(dp[i-1, :W-wi+1] + v, dp[i-1, wi:W+1])
# """
# for i in range(1, N+1):
#     wi, vi = map(int, input().split())
#     for k in range(1, i+1):
#         tmp = np.maximum(dp[i-k, :W-wi+1] + vi, dp[i-k, wi:W+1])
#         dp[i, wi:W+1] = np.maximum(dp[i, wi:W+1], tmp)
    

# print(int(dp[-1,-1]))


N, W = map(int, input().split())
# dp = np.zeros((N+1, W+1))  #i個目の品物までで重さw以下のときの価値の最大値 
dp = [[0]*(W+1) for _ in range(N+1)]
"""
dp[i, wi:W+1] = max(i番目の重さwiの品物を入れた場合, 入れなかった場合)
         = np.max(dp[i-1, :W-wi+1] + v, dp[i-1, wi:W+1])
"""

def maximum(list1, list2):
    ans = []
    for i in range(len(list1)):
        ans.append(max(list1[i], list2[i]))
    return ans

for i in range(1, N+1):
    wi, vi = map(int, input().split())
    for k in range(1, i+1):
        tmp2 = [val + vi for val in dp[i-k][:W-wi+1]]
        tmp = maximum(tmp2, dp[i-k][wi:W+1].copy())
        dp[i][wi:W+1] = maximum(dp[i][wi:W+1], tmp)
    

print(int(dp[-1][-1]))


Fixed submission:
N, W = map(int, input().split())
#i個目の品物までで重さw以下のときの価値の最大値 
dp = [[0]*(W+1) for _ in range(N+1)]
"""
dp[i, wi:W+1] = max(i番目の重さwiの品物を入れた場合, 入れなかった場合)
         = np.max(dp[i-1, :W-wi+1] + v, dp[i-1, wi:W+1])
"""

for i in range(1, N+1):
    w, v = map(int, input().split())

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

print(dp[-1][-1])

Buggy python submission (verdict: Runtime Error):
import numpy as np

N, W = map(int, input().split())
dp = np.zeros((N+1, W+1))  #i個目の品物までで重さw以下のときの価値の最大値 
"""
dp[i, wi:W+1] = max(i番目の重さwiの品物を入れた場合, 入れなかった場合)
         = np.max(dp[i-1, :W-wi+1] + v, dp[i-1, wi:W+1])
"""
for i in range(1, N+1):
    wi, vi = map(int, input().split())
    for k in range(1, i+1):
        tmp = np.maximum(dp[i-k, :W-wi+1] + vi, dp[i-k, wi:W+1])
        dp[i, wi:W+1] = np.maximum(dp[i, wi:W+1], tmp)
    

print(int(dp[-1,-1]))


Fixed submission:
N, W = map(int, input().split())
#i個目の品物までで重さw以下のときの価値の最大値 
dp = [[0]*(W+1) for _ in range(N+1)]
"""
dp[i, wi:W+1] = max(i番目の重さwiの品物を入れた場合, 入れなかった場合)
         = np.max(dp[i-1, :W-wi+1] + v, dp[i-1, wi:W+1])
"""

for i in range(1, N+1):
    w, v = map(int, input().split())

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

print(dp[-1][-1])

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

N, W = map(int, input().split())
dp = np.zeros((N+1, W+1))  #i個目の品物までで重さw以下のときの価値の最大値 
"""
dp[i, wi:W+1] = max(i番目の重さwiの品物を入れた場合, 入れなかった場合)
         = np.max(dp[i-1, :W-wi+1] + v, dp[i-1, wi:W+1])
"""
for i in range(1, N+1):
    wi, vi = map(int, input().split())
    for k in range(1, i+1):
        tmp = np.maximum(dp[i-k, :W-wi+1] + vi, dp[i-k, wi:W+1])
        dp[i, wi:W+1] = np.maximum(dp[i, wi:W+1], tmp)
    

print(int(dp[-1,-1]))


Fixed submission:
N, W = map(int, input().split())
#i個目の品物までで重さw以下のときの価値の最大値 
dp = [[0]*(W+1) for _ in range(N+1)]
"""
dp[i, wi:W+1] = max(i番目の重さwiの品物を入れた場合, 入れなかった場合)
         = np.max(dp[i-1, :W-wi+1] + v, dp[i-1, wi:W+1])
"""

for i in range(1, N+1):
    w, v = map(int, input().split())

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

print(dp[-1][-1])

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

input = sys.stdin.readline

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

def knapsack(N, W):
    dp = np.zeros((N+1, W+1))
    maximum = 0
    for i in range(N):
        weight, val = map(int, input().split())
        for w in range(W+1):
            if w >= weight:
                dp[i+1, w] = dp[i, w - weight] + val
                maximum = max(maximum, dp[i+1, w])
            else:
                dp[i+1, w] = dp[i, w]
            
    print(int(maximum))

knapsack(N, W)


Fixed submission:
N, W = map(int, input().split())
#i個目の品物までで重さw以下のときの価値の最大値 
dp = [[0]*(W+1) for _ in range(N+1)]
"""
dp[i, wi:W+1] = max(i番目の重さwiの品物を入れた場合, 入れなかった場合)
         = np.max(dp[i-1, :W-wi+1] + v, dp[i-1, wi:W+1])
"""

for i in range(1, N+1):
    w, v = map(int, input().split())

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

print(dp[-1][-1])

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

input = sys.stdin.readline

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

def knapsack(N, W):
    Weight, V = [], []
    for i in range(N):
        w, v = map(int, input().split())
        Weight.append(w)
        V.append(v)

    dp = np.zeros((N+1, W+1))

    maximum = 0
    for i in range(N):
        for w in range(W+1):
            if w >= Weight[i]:
                dp[i+1, w] = dp[i, w - Weight[i]] + V[i]
                maximum = max(maximum, dp[i+1, w])
            else:
                dp[i+1, w] = dp[i, w]
            
    print(int(maximum))

knapsack(N, W)


Fixed submission:
N, W = map(int, input().split())
#i個目の品物までで重さw以下のときの価値の最大値 
dp = [[0]*(W+1) for _ in range(N+1)]
"""
dp[i, wi:W+1] = max(i番目の重さwiの品物を入れた場合, 入れなかった場合)
         = np.max(dp[i-1, :W-wi+1] + v, dp[i-1, wi:W+1])
"""

for i in range(1, N+1):
    w, v = map(int, input().split())

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

print(dp[-1][-1])

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

input = sys.stdin.readline

N, W = map(int, input().split())
Weight, V = [], []
for i in range(N):
    w, v = map(int, input().split())
    Weight.append(w)
    V.append(v)

dp = np.zeros((N+1, W+1))

maximum = 0
for i in range(N):
    for w in range(W+1):
        if w >= Weight[i]:
            dp[i+1, w] = dp[i, w - Weight[i]] + V[i]
            maximum = max(maximum, dp[i+1, w])
        else:
            dp[i+1, w] = dp[i, w]
        
print(int(maximum))


Fixed submission:
N, W = map(int, input().split())
#i個目の品物までで重さw以下のときの価値の最大値 
dp = [[0]*(W+1) for _ in range(N+1)]
"""
dp[i, wi:W+1] = max(i番目の重さwiの品物を入れた場合, 入れなかった場合)
         = np.max(dp[i-1, :W-wi+1] + v, dp[i-1, wi:W+1])
"""

for i in range(1, N+1):
    w, v = map(int, input().split())

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

print(dp[-1][-1])

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

input = sys.stdin.readline

N, W = map(int, input().split())
Weight, V = [], []
for i in range(N):
    w, v = map(int, input().split())
    Weight.append(w)
    V.append(v)

dp = np.zeros((N+1, W+1))

maximum = 0
for i in range(N):
    for w in range(W+1):
        if w >= Weight[i]:
            dp[i+1, w] = dp[i, w - Weight[i]] + V[i]
        else:
            dp[i+1, w] = dp[i, w]
        if maximum < dp[i+1,w]:
            maximum = dp[i+1,w]

        
print(int(maximum))


Fixed submission:
N, W = map(int, input().split())
#i個目の品物までで重さw以下のときの価値の最大値 
dp = [[0]*(W+1) for _ in range(N+1)]
"""
dp[i, wi:W+1] = max(i番目の重さwiの品物を入れた場合, 入れなかった場合)
         = np.max(dp[i-1, :W-wi+1] + v, dp[i-1, wi:W+1])
"""

for i in range(1, N+1):
    w, v = map(int, input().split())

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

print(dp[-1][-1])

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

input = sys.stdin.readline

N, W = map(int, input().split())
Weight, V = [], []
for i in range(N):
    w, v = map(int, input().split())
    Weight.append(w)
    V.append(v)

dp = np.zeros((N+1, W+1))

for i in range(N):
    for w in range(W+1):
        if w >= Weight[i]:
            dp[i+1, w] = dp[i, w - Weight[i]] + V[i]
        else:
            dp[i+1, w] = dp[i, w]
maximum = 0
for i in range(N+1):
    for j in range(W+1):
        if maximum < dp[i,j]:
            maximum = dp[i,j]
print(int(maximum))


Fixed submission:
N, W = map(int, input().split())
#i個目の品物までで重さw以下のときの価値の最大値 
dp = [[0]*(W+1) for _ in range(N+1)]
"""
dp[i, wi:W+1] = max(i番目の重さwiの品物を入れた場合, 入れなかった場合)
         = np.max(dp[i-1, :W-wi+1] + v, dp[i-1, wi:W+1])
"""

for i in range(1, N+1):
    w, v = map(int, input().split())

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

print(dp[-1][-1])