from functools import cmp_to_key

n, w = [int(e) for e in input().split()]

d = [[int(e) for e in input().split()] for i in range(n)]

d.sort(key = cmp_to_key(lambda x, y: x[1] / x[0] - y[1] / y[0]))

t = {}

t[w] = 0

for i in range(n):

  keys = list(sorted(t.keys())) # sort しないと品物iを複数回ナップサックに詰める可能性がある

  tw, tv = d[i]

  updates = []

  for j in keys:

    nw = j - tw

    if nw < 0:

      continue

    nv = t[j] + tv

    if nw not in t or nv > t[nw]:

      updates.append([nw, nv])

  for u in updates:

    t[u[0]] = u[1]

print((max(t.values())))

from functools import cmp_to_key

n, w = [int(e) for e in input().split()]

d = [[int(e) for e in input().split()] for i in range(n)]

d.sort(key = cmp_to_key(lambda x, y: y[1] / y[0] - x[1] / x[0]))

t = {}

t[w] = 0

for i in range(n):

  keys = list(sorted(t.keys())) # sort しないと品物iを複数回ナップサックに詰める可能性がある

  tw, tv = d[i]

  updates = []

  for j in keys:

    nw = j - tw

    if nw < 0:

      continue

    nv = t[j] + tv

    if nw not in t or nv > t[nw]:

      updates.append([nw, nv])

  for u in updates:

    t[u[0]] = u[1]

print((max(t.values())))

from functools import cmp_to_key

n, w = [int(e) for e in input().split()]
d = [[int(e) for e in input().split()] for i in range(n)]
d.sort(key=cmp_to_key(lambda x, y: x[1] / x[0] - y[1] / y[0]))
t = {}
t[w] = 0
for i in range(n):
    keys = list(sorted(t.keys()))  # sort しないと品物iを複数回ナップサックに詰める可能性がある
    tw, tv = d[i]
    updates = []
    for j in keys:
        nw = j - tw
        if nw < 0:
            continue
        nv = t[j] + tv
        if nw not in t or nv > t[nw]:
            updates.append([nw, nv])
    for u in updates:
        t[u[0]] = u[1]
print((max(t.values())))

from functools import cmp_to_key

n, w = [int(e) for e in input().split()]
d = [[int(e) for e in input().split()] for i in range(n)]
d.sort(key=cmp_to_key(lambda x, y: y[1] / y[0] - x[1] / x[0]))
t = {}
t[w] = 0
for i in range(n):
    keys = list(sorted(t.keys()))  # sort しないと品物iを複数回ナップサックに詰める可能性がある
    tw, tv = d[i]
    updates = []
    for j in keys:
        nw = j - tw
        if nw < 0:
            continue
        nv = t[j] + tv
        if nw not in t or nv > t[nw]:
            updates.append([nw, nv])
    for u in updates:
        t[u[0]] = u[1]
print((max(t.values())))

-d.sort(key=cmp_to_key(lambda x, y: x[1] / x[0] - y[1] / y[0])) +d.sort(key=cmp_to_key(lambda x, y: y[1] / y[0] - x[1] / x[0]))