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

AB = sorted([list(map(int,input().split())) for i in range(n)])

res = 0

for a,b in AB:

    m -= b

    if m >= 0:

        res += a*b

    else:

        m += b

        res += a*m

        break

print(res)
n,m = list(map(int,input().split()))

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

AB.sort()

res = 0

for a,b in AB:

    m -= b

    if m >= 0:

        res += a*b

    else:

        m += b

        res += a*m

        break

print(res)
n, m = list(map(int, input().split()))
AB = sorted([list(map(int, input().split())) for i in range(n)])
res = 0
for a, b in AB:
    m -= b
    if m >= 0:
        res += a * b
    else:
        m += b
        res += a * m
        break
print(res)

n, m = list(map(int, input().split()))
AB = [list(map(int, input().split())) for i in range(n)]
AB.sort()
res = 0
for a, b in AB:
    m -= b
    if m >= 0:
        res += a * b
    else:
        m += b
        res += a * m
        break
print(res)

-AB = sorted([list(map(int, input().split())) for i in range(n)]) +AB = [list(map(int, input().split())) for i in range(n)] +AB.sort()