import numpy as np



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

items = []

for _ in range(N):

    items.append(tuple(map(int, input().split())))

dp = np.array([[0 for j in range(W+1)] for _ in range(N+1)])

for i in range(1, N+1):

    w, v = items[i-1]

    dp[i, :w] = dp[i-1, :w]

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

print((dp[N, W]))
N, W = list(map(int, input().split()))

items = []

for _ in range(N):

    items.append(tuple(map(int, input().split())))

dp = [[0 for j in range(W+1)] for i in range(N+1)]

for i in range(1, N+1):

    w, v = items[i-1]

    for j in range(W+1):

        if j - w >= 0:

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

        else:

            dp[i][j] = dp[i-1][j]

print((max(dp[N])))

import numpy as np

N, W = list(map(int, input().split()))
items = []
for _ in range(N):
    items.append(tuple(map(int, input().split())))
dp = np.array([[0 for j in range(W + 1)] for _ in range(N + 1)])
for i in range(1, N + 1):
    w, v = items[i - 1]
    dp[i, :w] = dp[i - 1, :w]
    dp[i, w:] = np.maximum(dp[i - 1, :-w] + v, dp[i - 1, w:])
print((dp[N, W]))

N, W = list(map(int, input().split()))
items = []
for _ in range(N):
    items.append(tuple(map(int, input().split())))
dp = [[0 for j in range(W + 1)] for i in range(N + 1)]
for i in range(1, N + 1):
    w, v = items[i - 1]
    for j in range(W + 1):
        if j - w >= 0:
            dp[i][j] = max(dp[i - 1][j - w] + v, dp[i - 1][j])
        else:
            dp[i][j] = dp[i - 1][j]
print((max(dp[N])))

-import numpy as np - -dp = np.array([[0 for j in range(W + 1)] for _ in range(N + 1)]) +dp = [[0 for j in range(W + 1)] for i in range(N + 1)] -    dp[i, :w] = dp[i - 1, :w] -    dp[i, w:] = np.maximum(dp[i - 1, :-w] + v, dp[i - 1, w:]) -print((dp[N, W])) +    for j in range(W + 1): +        if j - w >= 0: +            dp[i][j] = max(dp[i - 1][j - w] + v, dp[i - 1][j]) +        else: +            dp[i][j] = dp[i - 1][j] +print((max(dp[N])))