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

a = [0] * (w + 1)

for _ in range(n):

    b, c = [int(i) for i in input().split()]

    for i in reversed(list(range(w + 1))):

        if i + b >= w + 1:

            continue

        d = i + b

        a[d] = max(a[d], a[i] + c)

print((a[-1]))

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

dp = [0] * (w + 1)

for _ in range(n):

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

    for i in reversed(list(range(w - u + 1))):

        dp[i + u] = max(dp[i + u], dp[i] + v)



print((max(dp)))

n, w = [int(i) for i in input().split()]
a = [0] * (w + 1)
for _ in range(n):
    b, c = [int(i) for i in input().split()]
    for i in reversed(list(range(w + 1))):
        if i + b >= w + 1:
            continue
        d = i + b
        a[d] = max(a[d], a[i] + c)
print((a[-1]))

n, w = [int(i) for i in input().split()]
dp = [0] * (w + 1)
for _ in range(n):
    u, v = [int(i) for i in input().split()]
    for i in reversed(list(range(w - u + 1))):
        dp[i + u] = max(dp[i + u], dp[i] + v)
print((max(dp)))

-a = [0] * (w + 1) +dp = [0] * (w + 1) -    b, c = [int(i) for i in input().split()] -    for i in reversed(list(range(w + 1))): -        if i + b >= w + 1: -            continue -        d = i + b -        a[d] = max(a[d], a[i] + c) -print((a[-1])) +    u, v = [int(i) for i in input().split()] +    for i in reversed(list(range(w - u + 1))): +        dp[i + u] = max(dp[i + u], dp[i] + v) +print((max(dp)))