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



dp = [[[-1]*4*n for j in range(n+1)] for i in range(n+1)]

dp[0][0][0] = 0

w1 = None

for i in range(n):

    ws, vs = list(map(int, input().split()))

    if i == 0:

        w1 = ws

    ws -= w1

    for j in range(i+2):

        for k in range(4*n):

            if j-1 >= 0 and k-ws >= 0 and dp[i][j-1][k-ws] >= 0:

                dp[i+1][j][k] = max(dp[i][j][k], dp[i][j-1][k-ws]+vs)

            else:

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



ans = 0

for j in range(n+1):

    for k in range(4*n):

        if w1*j + k <= w:

            ans = max(ans, dp[-1][j][k])

print(ans)

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

w4 = [[] for i in range(4)]

w1 = None

for i in range(n):

    ws, vs = list(map(int,input().split()))

    if i == 0:

        w1 = ws

    ws -= w1

    w4[ws].append(vs)



for i in range(4):

    w4[i].sort(reverse=True)

    tmp = [0]

    for j in w4[i]:

        tmp.append(tmp[-1]+j)

    w4[i] = tmp

ans = 0

for i in range(len(w4[0])):

    for j in range(len(w4[1])):

        for k in range(len(w4[2])):

            for l in range(len(w4[3])):

                if w >= w1*(i+j+k+l) + j + 2*k + 3*l:

                    ans = max(ans, w4[0][i]+w4[1][j]+w4[2][k]+w4[3][l])

print(ans)
n, w = list(map(int, input().split()))
dp = [[[-1] * 4 * n for j in range(n + 1)] for i in range(n + 1)]
dp[0][0][0] = 0
w1 = None
for i in range(n):
    ws, vs = list(map(int, input().split()))
    if i == 0:
        w1 = ws
    ws -= w1
    for j in range(i + 2):
        for k in range(4 * n):
            if j - 1 >= 0 and k - ws >= 0 and dp[i][j - 1][k - ws] >= 0:
                dp[i + 1][j][k] = max(dp[i][j][k], dp[i][j - 1][k - ws] + vs)
            else:
                dp[i + 1][j][k] = dp[i][j][k]
ans = 0
for j in range(n + 1):
    for k in range(4 * n):
        if w1 * j + k <= w:
            ans = max(ans, dp[-1][j][k])
print(ans)

n, w = list(map(int, input().split()))
w4 = [[] for i in range(4)]
w1 = None
for i in range(n):
    ws, vs = list(map(int, input().split()))
    if i == 0:
        w1 = ws
    ws -= w1
    w4[ws].append(vs)
for i in range(4):
    w4[i].sort(reverse=True)
    tmp = [0]
    for j in w4[i]:
        tmp.append(tmp[-1] + j)
    w4[i] = tmp
ans = 0
for i in range(len(w4[0])):
    for j in range(len(w4[1])):
        for k in range(len(w4[2])):
            for l in range(len(w4[3])):
                if w >= w1 * (i + j + k + l) + j + 2 * k + 3 * l:
                    ans = max(ans, w4[0][i] + w4[1][j] + w4[2][k] + w4[3][l])
print(ans)

-dp = [[[-1] * 4 * n for j in range(n + 1)] for i in range(n + 1)] -dp[0][0][0] = 0 +w4 = [[] for i in range(4)] -    for j in range(i + 2): -        for k in range(4 * n): -            if j - 1 >= 0 and k - ws >= 0 and dp[i][j - 1][k - ws] >= 0: -                dp[i + 1][j][k] = max(dp[i][j][k], dp[i][j - 1][k - ws] + vs) -            else: -                dp[i + 1][j][k] = dp[i][j][k] +    w4[ws].append(vs) +for i in range(4): +    w4[i].sort(reverse=True) +    tmp = [0] +    for j in w4[i]: +        tmp.append(tmp[-1] + j) +    w4[i] = tmp -for j in range(n + 1): -    for k in range(4 * n): -        if w1 * j + k <= w: -            ans = max(ans, dp[-1][j][k]) +for i in range(len(w4[0])): +    for j in range(len(w4[1])): +        for k in range(len(w4[2])): +            for l in range(len(w4[3])): +                if w >= w1 * (i + j + k + l) + j + 2 * k + 3 * l: +                    ans = max(ans, w4[0][i] + w4[1][j] + w4[2][k] + w4[3][l])