N, W = [int(i) for i in input().split()]

dp = [0] * (W + 1)

v = w = 0

for _ in range(0, N):

    v, w = [int(i) for i in input().split()]

    for j in range(W, w - 1, -1):

        if dp[j] < dp[j - w] + v:

            dp[j] = dp[j - w] + v

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

dp = [0] * (W + 1)

v = w = 0

for _ in range(0, N):

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

    for j in range(W, w - 1, -1):

        if dp[j] < dp[j - w] + v:

            dp[j] = dp[j - w] + v

print((dp[W]))
N, W = [int(i) for i in input().split()]
dp = [0] * (W + 1)
v = w = 0
for _ in range(0, N):
    v, w = [int(i) for i in input().split()]
    for j in range(W, w - 1, -1):
        if dp[j] < dp[j - w] + v:
            dp[j] = dp[j - w] + v
print((dp[W]))

N, W = list(map(int, input().split()))
dp = [0] * (W + 1)
v = w = 0
for _ in range(0, N):
    v, w = list(map(int, input().split()))
    for j in range(W, w - 1, -1):
        if dp[j] < dp[j - w] + v:
            dp[j] = dp[j - w] + v
print((dp[W]))

-N, W = [int(i) for i in input().split()] +N, W = list(map(int, input().split())) -    v, w = [int(i) for i in input().split()] +    v, w = list(map(int, input().split()))