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

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



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

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

    for j in range(W+1):

        if j < w:

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

        else:

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



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

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



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

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

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

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

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



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

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

-    for j in range(W + 1): -        if j < w: -            dp[i][j] = dp[i - 1][j] -        else: -            dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - w] + v) +    dp[i][0:w] = dp[i - 1][0:w] +    for j in range(w, W + 1): +        dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - w] + v)