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

w = [0]*n

v = [0]*n

for i in range(n): w[i],v[i] = list(map(int,input().split()))

x = w[0]

for i in range(n): w[i] -= x

dp = [[[0]*(4*n+1) for _ in range(n+1)] for _ in range(n+1)]



for i in range(n):

    for j in range(i+1):

        for k in range(4*n+1):

            if (j+1)*x+k <= W and k-w[i] >= 0:

                dp[i+1][j+1][k] = max(dp[i+1][j+1][k],dp[i][j][k-w[i]]+v[i])

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



"""

for i in range(n+1):

    print(i,"///////////////////////////////////////////////")

    for j in range(n+1):

        print(dp[i][j])

"""

print((max(max(dp[n][j]) for j in range(n+1))))
n,W = list(map(int,input().split()))

lst = [[0]*(n+1) for _ in range(4)]

for i in range(n):

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

    if i == 0: x = w

    lst[w-x].append(v)

for i in range(4):

    lst[i].sort(reverse=True)

    for j in range(n): lst[i][j+1] += lst[i][j]

ans = 0

for a in range(n+1):

    for b in range(n+1-a):

        for c in range(n+1-a-b):

            if x*a+(x+1)*b+(x+2)*c > W: continue

            d = max((W-x*a-(x+1)*b-(x+2)*c)//(x+3),0)

            sumv = 0

            for i,j in enumerate((a,b,c,d)):

                if j == 0: continue

                sumv += lst[i][j-1]

            ans = max(sumv,ans)

print(ans)
n, W = list(map(int, input().split()))
w = [0] * n
v = [0] * n
for i in range(n):
    w[i], v[i] = list(map(int, input().split()))
x = w[0]
for i in range(n):
    w[i] -= x
dp = [[[0] * (4 * n + 1) for _ in range(n + 1)] for _ in range(n + 1)]
for i in range(n):
    for j in range(i + 1):
        for k in range(4 * n + 1):
            if (j + 1) * x + k <= W and k - w[i] >= 0:
                dp[i + 1][j + 1][k] = max(
                    dp[i + 1][j + 1][k], dp[i][j][k - w[i]] + v[i]
                )
            dp[i + 1][j][k] = max(dp[i + 1][j][k], dp[i][j][k])
"""
for i in range(n+1):
    print(i,"///////////////////////////////////////////////")
    for j in range(n+1):
        print(dp[i][j])
"""
print((max(max(dp[n][j]) for j in range(n + 1))))

n, W = list(map(int, input().split()))
lst = [[0] * (n + 1) for _ in range(4)]
for i in range(n):
    w, v = list(map(int, input().split()))
    if i == 0:
        x = w
    lst[w - x].append(v)
for i in range(4):
    lst[i].sort(reverse=True)
    for j in range(n):
        lst[i][j + 1] += lst[i][j]
ans = 0
for a in range(n + 1):
    for b in range(n + 1 - a):
        for c in range(n + 1 - a - b):
            if x * a + (x + 1) * b + (x + 2) * c > W:
                continue
            d = max((W - x * a - (x + 1) * b - (x + 2) * c) // (x + 3), 0)
            sumv = 0
            for i, j in enumerate((a, b, c, d)):
                if j == 0:
                    continue
                sumv += lst[i][j - 1]
            ans = max(sumv, ans)
print(ans)

-w = [0] * n -v = [0] * n +lst = [[0] * (n + 1) for _ in range(4)] -    w[i], v[i] = list(map(int, input().split())) -x = w[0] -for i in range(n): -    w[i] -= x -dp = [[[0] * (4 * n + 1) for _ in range(n + 1)] for _ in range(n + 1)] -for i in range(n): -    for j in range(i + 1): -        for k in range(4 * n + 1): -            if (j + 1) * x + k <= W and k - w[i] >= 0: -                dp[i + 1][j + 1][k] = max( -                    dp[i + 1][j + 1][k], dp[i][j][k - w[i]] + v[i] -                ) -            dp[i + 1][j][k] = max(dp[i + 1][j][k], dp[i][j][k]) -""" -for i in range(n+1): -    print(i,"///////////////////////////////////////////////") -    for j in range(n+1): -        print(dp[i][j]) -""" -print((max(max(dp[n][j]) for j in range(n + 1)))) +    w, v = list(map(int, input().split())) +    if i == 0: +        x = w +    lst[w - x].append(v) +for i in range(4): +    lst[i].sort(reverse=True) +    for j in range(n): +        lst[i][j + 1] += lst[i][j] +ans = 0 +for a in range(n + 1): +    for b in range(n + 1 - a): +        for c in range(n + 1 - a - b): +            if x * a + (x + 1) * b + (x + 2) * c > W: +                continue +            d = max((W - x * a - (x + 1) * b - (x + 2) * c) // (x + 3), 0) +            sumv = 0 +            for i, j in enumerate((a, b, c, d)): +                if j == 0: +                    continue +                sumv += lst[i][j - 1] +            ans = max(sumv, ans) +print(ans)