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

wv = [list(map(int, input().split())) for _ in range(n)]

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

for i in range(n):

    w_, v_ = wv[i]

    for j in range(w+1):

        if j < w_:

            dp[i+1][j] = dp[i][j]

        else:

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

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

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

for i in range(N):

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

    for j in range(1, W+1):

        if j<w:

            dp[i+1][j] = dp[i][j]

        if w<=j:

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

print((dp[-1][-1]))
n, w = list(map(int, input().split()))
wv = [list(map(int, input().split())) for _ in range(n)]
dp = [[0] * (w + 1) for _ in range(n + 1)]
for i in range(n):
    w_, v_ = wv[i]
    for j in range(w + 1):
        if j < w_:
            dp[i + 1][j] = dp[i][j]
        else:
            dp[i + 1][j] = max(dp[i][j - w_] + v_, dp[i][j])
print((dp[n][w]))

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

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