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



import numpy as np



dp = np.zeros(W + 1, dtype=int)



for i in range(N):

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

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



print((dp[-1]))
a = [int(x) for x in input().split()]

weight = a[1]

dp = [0] * weight + [0]

for x in range(a[0]):

    b = [int(x) for x in input().split()]

    for x in range(weight, b[0] - 1, -1):

        dp[x] = max(dp[x], dp[x - b[0]] + b[1])

print((dp[-1]))

N, W = list(map(int, input().split()))
import numpy as np

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

a = [int(x) for x in input().split()]
weight = a[1]
dp = [0] * weight + [0]
for x in range(a[0]):
    b = [int(x) for x in input().split()]
    for x in range(weight, b[0] - 1, -1):
        dp[x] = max(dp[x], dp[x - b[0]] + b[1])
print((dp[-1]))

-N, W = list(map(int, input().split())) -import numpy as np - -dp = np.zeros(W + 1, dtype=int) -for i in range(N): -    w, v = list(map(int, input().split())) -    np.maximum(dp[:-w] + v, dp[w:], out=dp[w:]) +a = [int(x) for x in input().split()] +weight = a[1] +dp = [0] * weight + [0] +for x in range(a[0]): +    b = [int(x) for x in input().split()] +    for x in range(weight, b[0] - 1, -1): +        dp[x] = max(dp[x], dp[x - b[0]] + b[1])