n, W = list(map(int, input().split()))

ws = [0]*n

vs = [0]*n



for i in range(n):

  w, v = list(map(int, input().split()))

  ws[i] = w

  vs[i] = v

  

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

for i in range(n):

  for j in range(W+1):

    if j - ws[i] >= 0:

      dp[i+1][j] = max(dp[i+1][j], dp[i][j-ws[i]]+vs[i])

    dp[i+1][j] = max(dp[i+1][j], dp[i][j])

    

print((dp[-1][W]))
import numpy as np



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



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



for i in range(N):

  w, v = list(map(int, input().split()))

  dp[i+1][:w] = dp[i][:w]

  dp[i+1][w:] = np.maximum(dp[i][w:], dp[i][:-w]+v)

  

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

import numpy as np

N, W = list(map(int, input().split()))
dp = np.zeros((N + 1, W + 1), dtype="uint64")
for i in range(N):
    w, v = list(map(int, input().split()))
    dp[i + 1][:w] = dp[i][:w]
    dp[i + 1][w:] = np.maximum(dp[i][w:], dp[i][:-w] + v)
print((np.max(dp[N, :])))

-n, W = list(map(int, input().split())) -ws = [0] * n -vs = [0] * n -for i in range(n): +import numpy as np + +N, W = list(map(int, input().split())) +dp = np.zeros((N + 1, W + 1), dtype="uint64") +for i in range(N): -    ws[i] = w -    vs[i] = v -dp = [[0] * (W + 1) for _ in range(n + 1)] -for i in range(n): -    for j in range(W + 1): -        if j - ws[i] >= 0: -            dp[i + 1][j] = max(dp[i + 1][j], dp[i][j - ws[i]] + vs[i]) -        dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]) -print((dp[-1][W])) +    dp[i + 1][:w] = dp[i][:w] +    dp[i + 1][w:] = np.maximum(dp[i][w:], dp[i][:-w] + v) +print((np.max(dp[N, :])))