import numpy as np



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



items = [tuple(map(int, input().split(' '))) for _ in range(N)]



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



for i in range(N):

    weight = items[i][0]

    value = items[i][1]

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

    dp[i + 1][weight:] = np.maximum(dp[i][weight:], value + dp[i][:-weight])



print((dp[N][W]))

import numpy as np



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

items = [tuple(map(int, input().split(' '))) for _ in range(N)]

dp = np.zeros(shape=W + 1, dtype=np.int64)



for weight, value in items:

    dp[weight:] = np.maximum(dp[weight:], dp[:-weight] + value)



print((dp[-1]))

import numpy as np

N, W = list(map(int, input().split(" ")))
items = [tuple(map(int, input().split(" "))) for _ in range(N)]
dp = np.zeros(shape=(N + 1, W + 1), dtype=int)
for i in range(N):
    weight = items[i][0]
    value = items[i][1]
    dp[i + 1][:weight] = dp[i][:weight]
    dp[i + 1][weight:] = np.maximum(dp[i][weight:], value + dp[i][:-weight])
print((dp[N][W]))

import numpy as np

N, W = list(map(int, input().split(" ")))
items = [tuple(map(int, input().split(" "))) for _ in range(N)]
dp = np.zeros(shape=W + 1, dtype=np.int64)
for weight, value in items:
    dp[weight:] = np.maximum(dp[weight:], dp[:-weight] + value)
print((dp[-1]))

-dp = np.zeros(shape=(N + 1, W + 1), dtype=int) -for i in range(N): -    weight = items[i][0] -    value = items[i][1] -    dp[i + 1][:weight] = dp[i][:weight] -    dp[i + 1][weight:] = np.maximum(dp[i][weight:], value + dp[i][:-weight]) -print((dp[N][W])) +dp = np.zeros(shape=W + 1, dtype=np.int64) +for weight, value in items: +    dp[weight:] = np.maximum(dp[weight:], dp[:-weight] + value) +print((dp[-1]))