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

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



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



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

    wi, vi = wv[i - 1]

    for j in range(w + 1):

        if j < wi:

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

        else:

            dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - wi] + vi)

print((dp[n][w]))

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

e = tuple(list(map(int, input().split())) for _ in range(n))

wt, vt = list(zip(*e))



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



for i in range(n):

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

    for j in range(wt[i], w + 1):

        dp[i + 1][j] = max(dp[i][j], dp[i][j - wt[i]] + vt[i])

print((dp[n][w]))

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

n, w = list(map(int, input().split()))
e = tuple(list(map(int, input().split())) for _ in range(n))
wt, vt = list(zip(*e))
dp = tuple([0] * (w + 1) for _ in range(n + 1))
for i in range(n):
    dp[i + 1][: wt[i]] = dp[i][: wt[i]]
    for j in range(wt[i], w + 1):
        dp[i + 1][j] = max(dp[i][j], dp[i][j - wt[i]] + vt[i])
print((dp[n][w]))

-wv = [tuple(map(int, input().split())) for _ in range(n)] -dp = [[0] * (w + 1) for _ in range(n + 1)] -for i in range(1, n + 1): -    wi, vi = wv[i - 1] -    for j in range(w + 1): -        if j < wi: -            dp[i][j] = dp[i - 1][j] -        else: -            dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - wi] + vi) +e = tuple(list(map(int, input().split())) for _ in range(n)) +wt, vt = list(zip(*e)) +dp = tuple([0] * (w + 1) for _ in range(n + 1)) +for i in range(n): +    dp[i + 1][: wt[i]] = dp[i][: wt[i]] +    for j in range(wt[i], w + 1): +        dp[i + 1][j] = max(dp[i][j], dp[i][j - wt[i]] + vt[i])