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

data = tuple(tuple(map(int, input().split())) for _ in range(N))

table = [dict() for _ in range(N + 1)]

table[0][0] = 0

for n in range(N):

    weight, value = data[n]

    for w, now in list(table[n].items()):

        table[n + 1][w] = max(table[n + 1].get(w, 0), now)

        if w + weight <= W:

            table[n + 1][w + weight] = max(table[n + 1].get(w + weight, 0), now + value)

print((max(table[N].values())))
N, W = list(map(int, input().split()))

data = tuple(tuple(map(int, input().split())) for _ in range(N))

d = {0: 0}

for n in range(N):

    weight, value = data[n]

    for w, now in list(d.copy().items()):

        if w + weight <= W:

            d[w + weight] = max(d.get(w + weight, 0), now + value)

print((max(d.values())))
N, W = list(map(int, input().split()))
data = tuple(tuple(map(int, input().split())) for _ in range(N))
table = [dict() for _ in range(N + 1)]
table[0][0] = 0
for n in range(N):
    weight, value = data[n]
    for w, now in list(table[n].items()):
        table[n + 1][w] = max(table[n + 1].get(w, 0), now)
        if w + weight <= W:
            table[n + 1][w + weight] = max(table[n + 1].get(w + weight, 0), now + value)
print((max(table[N].values())))

N, W = list(map(int, input().split()))
data = tuple(tuple(map(int, input().split())) for _ in range(N))
d = {0: 0}
for n in range(N):
    weight, value = data[n]
    for w, now in list(d.copy().items()):
        if w + weight <= W:
            d[w + weight] = max(d.get(w + weight, 0), now + value)
print((max(d.values())))

-table = [dict() for _ in range(N + 1)] -table[0][0] = 0 +d = {0: 0} -    for w, now in list(table[n].items()): -        table[n + 1][w] = max(table[n + 1].get(w, 0), now) +    for w, now in list(d.copy().items()): -            table[n + 1][w + weight] = max(table[n + 1].get(w + weight, 0), now + value) -print((max(table[N].values()))) +            d[w + weight] = max(d.get(w + weight, 0), now + value) +print((max(d.values())))