import numpy as np



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



dp = np.zeros((N+1, W+1), dtype='uint64')



for i in range(N):

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

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

  dp[i+1][w:] = np.maximum(dp[i][w:], dp[i][:-w]+v)

  

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

WV = []

for i in range(n):

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

    WV.append((w, v))



INF = 10**18

dp = [[-INF]*(W+1) for _ in range(n+1)]

dp[0][0] = 0



for i in range(n):

    w, v = WV[i]

    for j in range(W+1):

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

    for j in range(W+1):

        if j+w <= W:

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

print((max(dp[-1])))

import numpy as np

N, W = list(map(int, input().split()))
dp = np.zeros((N + 1, W + 1), dtype="uint64")
for i in range(N):
    w, v = list(map(int, input().split()))
    dp[i + 1][:w] = dp[i][:w]
    dp[i + 1][w:] = np.maximum(dp[i][w:], dp[i][:-w] + v)
print((np.max(dp[N, :])))

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

-import numpy as np - -N, W = list(map(int, input().split())) -dp = np.zeros((N + 1, W + 1), dtype="uint64") -for i in range(N): +n, W = list(map(int, input().split())) +WV = [] +for i in range(n): -    dp[i + 1][:w] = dp[i][:w] -    dp[i + 1][w:] = np.maximum(dp[i][w:], dp[i][:-w] + v) -print((np.max(dp[N, :]))) +    WV.append((w, v)) +INF = 10**18 +dp = [[-INF] * (W + 1) for _ in range(n + 1)] +dp[0][0] = 0 +for i in range(n): +    w, v = WV[i] +    for j in range(W + 1): +        dp[i + 1][j] = dp[i][j] +    for j in range(W + 1): +        if j + w <= W: +            dp[i + 1][j + w] = max(dp[i + 1][j + w], dp[i][j] + v) +print((max(dp[-1])))