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

stones=[None]*n

for i in range(n):

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

  stones[i]=[w,v]



import numpy as np

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



for i in range(len(stones)):

  w=stones[i][0]

  v=stones[i][1]

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



print((dp.max()))
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.max()))

n, W = list(map(int, input().split()))
stones = [None] * n
for i in range(n):
    w, v = list(map(int, input().split()))
    stones[i] = [w, v]
import numpy as np

dp = np.zeros(W + 1, dtype=int)
for i in range(len(stones)):
    w = stones[i][0]
    v = stones[i][1]
    np.maximum(dp[:-w] + v, dp[w:], dp[w:])
print((dp.max()))

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.max()))

-n, W = list(map(int, input().split())) -stones = [None] * n -for i in range(n): -    w, v = list(map(int, input().split())) -    stones[i] = [w, v] +N, W = list(map(int, input().split())) -for i in range(len(stones)): -    w = stones[i][0] -    v = stones[i][1] -    np.maximum(dp[:-w] + v, dp[w:], dp[w:]) +for i in range(N): +    w, v = list(map(int, input().split())) +    np.maximum(dp[:-w] + v, dp[w:], out=dp[w:])