CodeEff/ECCO huggingface dataset:
# Original solution
N = list(map(int,input().split()))
drinks = [list(map(int,input().split())) for i in range(N[0])]

counter=0
amount=0
flag=0
for i in range(N[0]):
    v = drinks[i]
    x = drinks[i][0]
    j = i-1
    while(j >= 0 and drinks[j][0]>x):
        drinks[j+1] = drinks[j]
        j -= 1
    drinks[j+1] = v
    x = drinks[j+1][0]

for i in range(N[0]):
    if flag==1:
        break
    while(drinks[i][1]!=0):
        drinks[i][1] -=1
        counter +=1
        amount += drinks[i][0]
        if counter==N[1]:
            flag=1
            break
print(amount) 
    


# Optimized solution
N = list(map(int,input().split()))
drinks = [list(map(int,input().split())) for i in range(N[0])]
drinks.sort()

counter=0
amount=0
flag=0

for i in range(N[0]):
    if flag==1:
        break
    while(drinks[i][1]!=0):
        drinks[i][1] -=1
        counter +=1
        amount += drinks[i][0]
        if counter==N[1]:
            flag=1
            break
print(amount)
# Original solution
n, m = list(map(int, input().split()))
a = [list(map(int, input().split())) for _ in range(n)]
a.sort()
ta = 0
tc = 0
for i in range(len(a)):
    tc += min(m, a[i][1])
    ta += min(m, a[i][1]) * a[i][0]
    m -= min(m, a[i][1])
    if m == 0:
        print(ta)
        exit()


# Optimized solution
n, m = list(map(int, input().split()))
ab = sorted([list(map(int, input().split())) for _ in range(n)])
cnt = 0
t = 0
for i in ab:
    mi = min(m - cnt, i[1])
    t += i[0] * mi
    cnt += mi
    if cnt == m:
        print(t)
        exit()
# Original solution
a = 0
listA = []
N, M = list(map(int, input().split()))
for i in range(N):
    A, B = list(map(int, input().split()))
    for i in range(B):
        listA.append(A)
listA.sort()
for i in range(M):
    a += listA[i]
print(a)

# Optimized solution
a = 0
l = []
f = 0
N, M = list(map(int, input().split()))
for i in range(N):
    A, B = list(map(int, input().split()))
    l.append([A, B])
l_sorted = sorted(l, key=lambda x: x[0])
while True:
    if l_sorted[f][1] < M:
        a += l_sorted[f][1] * l_sorted[f][0]
        M -= l_sorted[f][1]
        f += 1
    else:
        a += M * l_sorted[f][0]
        break
print(a)
# Original solution
N,M = list(map(int,input().split()))

ABlist = [list(map(int,input().split())) for n in range(N)]
Alist = [ab[0] for ab in ABlist]
Blist = [ab[1] for ab in ABlist]

sum = 0
flg = False
while True:
    min_ = min(Alist)
    min_index = Alist.index(min_)
    b_num = Blist[min_index]
    for i in range(b_num):
        M -= 1
        sum += min_
        if M==0:
            flg = True
            break
    Blist.remove(b_num)
    Alist.remove(Alist[min_index])
    if flg == True:
        break
print(sum)


# Optimized solution
N,M = list(map(int,input().split()))
ABlist = [tuple(map(int,input().split())) for _ in range(N)]
ABlist.sort()
money = 0
for AB in ABlist:
    maz_num = AB[1]
    maz_pri = AB[0]
    add_m = maz_pri*maz_num
    if M > 0:
        money += add_m
        M -= maz_num
    if M == 0:
        break
    if M < 0:
        while M!=0:
            money -= maz_pri
            M += 1
        break

print(money)
# Original solution
N,M=list(map(int,input().split()))
s=[list(map(int,input().split())) for i in range(N)]
s=sorted(s,key=lambda x:x[0])

ans=0
cnt=0
for i in range(N):
    cnt+=s[i][1]
    if M >= cnt:
        ans+=s[i][0]*s[i][1]
    elif M < cnt:
        cnt-=s[i][1]
        ans+=(M-cnt)*s[i][0]
        break
print(ans)

         
        

# Optimized solution
N,M=list(map(int,input().split()))
AB=[list(map(int,input().split())) for i in range(N)]#[～円,～本]
AB=sorted(AB,key=lambda x:x[0])


ans=0
cnt=0
for i in range(N):
    cnt+=AB[i][1]
    if M>=cnt:
        ans+=AB[i][1]*AB[i][0]
    else:
        ans+=(M-(cnt-AB[i][1]))*AB[i][0]
        break
print(ans)
# Original solution
N, M = list(map(int,input().split()))
AB = [list(map(int,input().split())) for _ in range(N)]
AB = sorted(AB, key=lambda x: x[0])

ans = 0
s = 0
for i in range(N):
    t = AB[i][1]
    c = min(M-s, t)
    ans += c*AB[i][0]
    s += c
    if s>=M: break

print(ans)

# Optimized solution
N, M = list(map(int,input().split()))
PNs = [list(map(int,input().split())) for _ in range(N)]
#price_and_number_of_drinks

PNs.sort(key=lambda x: x[0])

ans = 0
sum_drinks = 0 #sum of drinks which Takahashi has bought
for i in range(N):
    nos = PNs[i][1] #number of drinks at i_th shop
    ans += nos*PNs[i][0] #add money he spent at the shop
    sum_drinks += nos
    if sum_drinks>=M:
        ans -= (sum_drinks-M)*PNs[i][0]
        break

print(ans)
# Original solution
import sys
input = sys.stdin.readline
n, m = list(map(int, input().split()))

ab = [[int(x) for x in input().split()] for _ in range(n)]

ab.sort(key=lambda x: x[0])

temp = sum(ab, [])  # 疑似Flatten
a, b = temp[0::2], temp[1::2]

count, index, remainder = 0, 0, 0

for i in range(n):
  if count + b[i] < m:  
    count += b[i]
  else:
    index = i
    remainder = m - count
    break
    
total = a[index] * remainder
total += sum([a[i] * b[i] for i in range(index)])


print(total)

# Optimized solution
# cf. https://rion778.hatenablog.com/entry/2019/03/10/004006
import sys
input = sys.stdin.readline
 
N, M = [int(i) for i in input().split()]
 
plices = [[int(i) for i in input().split()] for _ in range(N)]
 
plices.sort(key = lambda x:x[0])
 
m = 0
cost = 0
 
for i in range(N):
    if m < M:
      buy = min(M - m, plices[i][1])
      cost += plices[i][0] * buy
      m += buy
    else:
      break

print(cost)
# Original solution
# -*- coding: utf-8 -*-
def inpl(): return list(map(int, input().split()))

N, M = inpl()
X = sorted([inpl() for _ in range(N)], key=lambda x: x[0])

ans = 0
for a, b in X:
    cnt = min(M, b)
    ans += a*cnt
    M -= cnt

print(ans)

# Optimized solution
def inpl(): return list(map(int, input().split()))
N, M = inpl()
X = sorted([inpl() for _ in range(N)], key=lambda x: -x[0])
ans = 0
while M:
    a, b = X.pop()
    buy = min(M, b)
    ans += a*buy
    M -= buy
print(ans)
# Original solution
n, m = list(map(int, input().split()))
d = []
c = 0

for i in range(n):
    d.append(tuple(map(int, input().split())))
d.sort()

while m > 0:
    a, b = d[0]
    c += min(a * b, m * a)
    m -= b
    d = d[1:]

print(c)

# Optimized solution
n, m = list(map(int, input().split()))
d = []
c = 0
last = 0

for i in range(n):
    d.append(tuple(map(int, input().split())))
d.sort()

while m > 0:
    a, b = d[last]
    c += min(a * b, m * a)
    m -= b
    last+=1

print(c)
# Original solution
import bisect

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

ans=[]
def targetAdd(a):
    bisect.insort_left(ans, a)

for i in range(n):
    a, b = list(map(int, input().split()))
    for j in range(b):
        targetAdd(a)

print((sum(ans[:m])))


# Optimized solution
import bisect

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

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

ab = sorted(ab, key=lambda x: x[0])

def func():
    c=0
    ans=0

    for target in ab:
        for i in range(target[1]):
            ans+=target[0]
            c+=1

            if c == m:
                return ans
            

print((func()))
# Original solution
from collections import defaultdict
d=defaultdict(int)
N,M=list(map(int,input().split()))
ans=0
t=M
for i in range(N):
	a,b=list(map(int,input().split()))
	d[a]+=b
while t>0:
	for i in range(d[min(d)]):
		ans+=min(d)
		t-=1
		if t==0:break
	d.pop(min(d))
print(ans)

# Optimized solution
N,m=list(map(int,input().split()))
L=sorted([list(map(int,input().split())) for _ in range(N)])
ans=0
for i in range(N):
	ans+=L[i][0]*min(m,L[i][1])
	m-=min(m,L[i][1])
print(ans)
# Original solution
from sys import stdin
from operator import itemgetter

input = stdin.readline

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

AB = [[int(j) for j in input().split()] for i in range(N)]


def main():
    AB.sort(key=itemgetter(0))
    num = 0
    yen = 0
    for i in range(N):
        if M < num + AB[i][1]:
            yen += AB[i][0] * (M - num)
            break
        else:
            yen += AB[i][0] * AB[i][1]
            num += AB[i][1]
    print(yen)
    return


main()


# Optimized solution
from sys import stdin

N, M = list(map(int, input().split()))
*AB, = list(map(int, stdin.read().split()))


def main():
    A = AB[::2]
    B = AB[1::2]
    Z = list(zip(A, B))
    Z = sorted(Z)
    num = 0
    yen = 0
    for a, b in Z:
        if M < num + b:
            yen += a * (M - num)
            break
        else:
            yen += a * b
            num += b
    print(yen)
    return


main()
# Original solution
from sys import stdin


def main():
    N, M = list(map(int, input().split()))
    *AB, = list(map(int, stdin.read().split()))
    A = AB[::2]
    B = AB[1::2]
    Z = list(zip(A, B))
    Z = sorted(Z)
    num = 0
    yen = 0
    for a, b in Z:
        if M < num + b:
            yen += a * (M - num)
            break
        else:
            yen += a * b
            num += b
    print(yen)
    return


main()


# Optimized solution
from sys import stdin


def main():
    N, M = list(map(int, input().split()))
    *AB, = list(map(int, stdin.read().split()))
    A = AB[::2]
    B = AB[1::2]
    num = 0
    yen = 0
    for a, b in sorted(zip(A, B)):
        if M < num + b:
            yen += a * (M - num)
            break
        else:
            yen += a * b
            num += b
    print(yen)
    return


main()
# Original solution
n,m=list(map(int,input().split()))
data=sorted([tuple(map(int,input().split())) for i in range(n)])
ans=0
while True:
  if m == 0:
    print(ans)
    exit()
  elif data[0][1]<=m:
    ans+=data[0][0]*data[0][1]
    m-=data[0][1]
    data=data[1:]
  else:
    ans+=data[0][0]*m
    m=0

# Optimized solution
n,m=list(map(int,input().split()))
dataset=sorted([tuple(map(int,input().split())) for i in range(n)])
ans=0
for data in dataset:
  if m==0:
    print(ans)
    exit()
  tmp=min(data[1],m)
  ans+=tmp*data[0]
  m-=tmp
print(ans)
# Original solution
N, M = list(map(int, input().split()))
AB = [tuple(map(int, input().split())) for _ in range(N)]
AB.sort(key=lambda x: x[0])

ans = 0
bought = 0
for a, b in AB:
    m = min(M - bought, b)
    bought += m
    ans += a * m
print(ans)

# Optimized solution
N, M = list(map(int, input().split()))
AB = [tuple(map(int, input().split())) for _ in range(N)]
AB.sort(key=lambda x: x[0])

ans = bought = 0
for a, b in AB:
    m = min(M - bought, b)
    bought += m
    ans += a * m
print(ans)
# Original solution
N, M = list(map(int, input().split()))
AB = [list(map(int, input().split())) for i in range(N)]

AB.sort(key=lambda x: x[0])
ans = 0
for i in range(N):
    if M >= AB[i][1]:
        ans += AB[i][0] * AB[i][1]
        M -= AB[i][1]
    else:
        ans += AB[i][0] * M
        M = 0
    if M == 0:
        break
print(ans)


# Optimized solution
N, M = list(map(int, input().split()))
AB = [tuple(map(int, input().split())) for i in range(N)]
AB.sort()

ans = 0
for a, b in AB:
    if M > b:
        M -= b
        ans += a*b
    else:
        ans += a*M
        break

print(ans)
# Original solution
a = input().split()
a = [int(i) for i in a]
drink_nume = []
drink_price = []

for i in range(a[0]):
    b = input().split()
    b = [int(i) for i in b]
    drink_nume.append(b[1])
    drink_price.append(b[0])

count = 0

while (a[1] > 0):
    min_index = drink_price.index(min(drink_price))
    if drink_nume[min_index] > a[1]:
        count += drink_price[min_index] * a[1]
        a[1] = 0
    else:
        count += drink_price[min_index] * drink_nume[min_index]
        a[1] -= drink_nume[min_index]
    drink_nume.pop(min_index)
    drink_price.pop(min_index)

print(count)

# Optimized solution
import sys
a = input().split()
a = [int(i) for i in a]
drink = []


for i in range(a[0]):
    b = input().split()
    b = [int(i) for i in b]
    drink.append(b)

count = 0
drink = sorted(drink, key=lambda x: x[0])

while (a[1] > 0):
    if drink[0][1] > a[1]:
        count += drink[0][0] * a[1]
        a[1] = 0
    else:
        count += drink[0][0] * drink[0][1]
        a[1] -= drink[0][1]
    drink.pop(0)

print(count)
# Original solution
n,m = list(map(int, input().split()))
a = [list(map(int, input().split())) for _ in range(n)]
a.sort(key=lambda x:(x[0],x[1]))
c = 0
ans = 0
for i in range(n):
    for j in range(a[i][1]):
        if c < m:
            c += 1
            ans += a[i][0]
print(ans)

# Optimized solution
n,m = list(map(int, input().split()))
a = [list(map(int, input().split())) for _ in range(n)]
a.sort(key=lambda x:(x[0]))
c = 0
ans = 0
for i in a:
    if c + i[1] < m:
        c += i[1]
        ans += i[0]*i[1]
    else:
        for j in range(i[1]):
                c += 1
                ans += i[0]
                if c >=m:
                    break
        break
print(ans)
# Original solution
b=list(map(int,input().split()))
LL=[]
for i in range(b[0]):
    LL.append(list(map(int,input().split())))
LL.sort(key=lambda x: x[0])
x=0
z=0
y=b[1]
while y>=0 and not LL==[]:
    if y<=LL[0][1]:
        print((x+LL[0][0]*y))
        break
    else:
        y-=LL[0][1]
        x+=LL[0][1]*LL[0][0]
        LL=LL[1:]

# Optimized solution
b=list(map(int,input().split()))
LL=[]
for i in range(b[0]):
    LL.append(list(map(int,input().split())))
LL.sort()
x=0
z=0
y=b[1]
i=-1
while y>=0 and not LL==[]:
    i+=1
    if y<=LL[i][1]:
        print((x+LL[i][0]*y))
        break
    else:
        y-=LL[i][1]
        x+=LL[i][1]*LL[i][0]
# Original solution
N,M = list(map(int,input().split()))
A = []
B = []
ans = 0
for _ in range(N):
    i = list(map(int,input().split()))
    A.append(i[0])
    B.append(i[1])
while M != 0:
    ind_ = A.index(min(A))
    if M - B[ind_] > 0:
        M -= B[ind_]
        ans += A[ind_]*B[ind_]
        B[ind_] -= B[ind_]
    else:
        ans += A[ind_]*M
        break
    if B[ind_] <= 0:
        B.pop(ind_)
        A.pop(ind_)
print(ans)

# Optimized solution
N,M = list(map(int,input().split()))

AB = [list(map(int,input().split())) for i in range(N)]
AB.sort()
ans = 0
for _ in range(N):
    if AB[_][1] >= M:
        ans += AB[_][0]*M
        break
    else:
        ans += AB[_][0]*AB[_][1]
        M -= AB[_][1]
print(ans)
# Original solution
N, M = list(map(int, input().split()))

drink = []
ans = 0

for i in range(N):
    A, B = list(map(int, input().split()))
    for j in range(B):
        drink.append(A)

drink.sort()

for i in range(M):
    ans += drink[i]

print(ans)

# Optimized solution
N, M = list(map(int, input().split()))

drink = []
sum = 0
count = 0

for i in range(N):
    A, B = list(map(int, input().split()))
    drink.append([A, B])

drink.sort()


for d in drink:
    if count >= M:
            break
    for i in range(d[1]):
        sum += d[0]
        count += 1
        if count >= M:
            break

print(sum)
# Original solution
N, M = list(map(int, input().split()))

drink = []
sum = 0
count = 0

for i in range(N):
    A, B = list(map(int, input().split()))
    drink.append([A, B])

drink.sort()


for d in drink:
    if count >= M:
            break
    for i in range(d[1]):
        sum += d[0]
        count += 1
        if count >= M:
            break

print(sum) 

# Optimized solution
N, M = list(map(int, input().split()))
AB = [ list(map(int, input().split())) for i in range(N)]

AB.sort()
sum = 0

for ab in AB:
    if M <= ab[1]:
        sum += ab[0] * M
        print(sum)
        exit()
    else:
        sum += ab[0] * ab[1]
        M -= ab[1]
# Original solution
n, m = list(map(int, input().split()))
A = []
B = []
for i in range(n):
    x, y = list(map(int, input().split()))
    A.append(x)
    B.append(y)

ans = 0
while m > 0:
    idx = A.index(min(A))
    p = A.pop(idx)
    a = B.pop(idx)
    if a >= m:
        ans += p * m
        m -= a
    else:
        ans += p * a
        m -= a
print(ans)

# Optimized solution
n, m = list(map(int, input().split()))
A = []
B = []
for i in range(n):
    x, y = list(map(int, input().split()))
    A.append(x)
    B.append(y)

ans = 0
for price, amount in sorted(zip(A, B)):
    ans += price * min(m, amount)
    m -= amount
    if m <= 0:
        break
print(ans)
# Original solution
N, M = [int(nm) for nm in input().split()]
AB = []
for n in range(N):
  A, B = [int(ab) for ab in input().split()]
  AB.append([A, B])
money = 0
while M > 0:
  AB_mn = min(AB)
  Ai, Bi = AB_mn[0], AB_mn[1]
  if Bi <= M:
    money += Ai * Bi
    M -= Bi
  else:
    money += Ai * M
    M = 0
  AB.remove(AB_mn)
print(money)

# Optimized solution
N, M = [int(nm) for nm in input().split()]
AB = []
for n in range(N):
  A, B = [int(ab) for ab in input().split()]
  AB.append([A, B])
AB.sort()
money = 0
while M > 0:
  Ai, Bi = AB[0][0], AB[0][1]
  if Bi <= M:
    money += Ai * Bi
    M -= Bi
  else:
    money += Ai * M
    M = 0
  AB.remove(AB[0])
print(money)
# Original solution
N, M = list(map(int, input().split()))
drinks = sorted(tuple(map(int, input().split())) for _ in range(N))
ans = 0
for A, B in drinks:
    if M > B:
        ans += A * B
        M -= B
    else:
        ans += A * M
        break
print(ans)


# Optimized solution
import sys


def input():
    return sys.stdin.readline().strip()


N, M = list(map(int, input().split()))
drinks = sorted(tuple(map(int, input().split())) for _ in range(N))
ans = 0
for A, B in drinks:
    if M > B:
        ans += A * B
        M -= B
    else:
        ans += A * M
        break
print(ans)
# Original solution
N,M = list(map(int, input().split()))
AB_array = []
for _ in range(N):
    AB_array.append(list(map(int, input().split())))

count = 0
while True:
    select = 0
    min_val = AB_array[0][0]
    for i in range(1,len(AB_array)):
        if AB_array[i][0] < min_val:
            min_val = AB_array[i][0]
            select = i
    if M <= AB_array[select][1]:
        count += AB_array[select][0] * M
        break
    else:
        M -= AB_array[select][1]
        count += AB_array[select][0] * AB_array[select][1]
        AB_array.pop(select)

print(count)


# Optimized solution
N,M = list(map(int, input().split()))
AB_array = []
for _ in range(N):
    AB_array.append(list(map(int, input().split())))

AB_array_s = sorted(AB_array, key=lambda x: x[0])

count = 0
for i in range(len(AB_array_s)):
    A,B = AB_array_s[i]
    if M <= B:
        count += A * M
        break
    else:
        M -= B
        count += A * B

print(count)
# Original solution
N,M = list(map(int, input().split()))

AB = []

for i in range(N) : 
    tmp_AB = [int(i) for i in input().split()]
    AB.append(tmp_AB)
    
P_list = []

for i in range(N) : 
    for j in range(AB[i][1]) : 
        P_list.append(AB[i][0])

P_list_sorted = sorted(P_list)

sum = 0

for i in range(M) : 
    sum += P_list_sorted[i]
    
print(sum)

# Optimized solution
N,M = list(map(int, input().split()))
 
AB = []
 
for i in range(N) : 
    tmp_AB = [int(i) for i in input().split()]
    AB.append(tmp_AB)
    
P = sorted(AB)
 
sum = 0
cnt = 0 # Mに達したら終了

for i in range(len(P)) : 
    for j in range(P[i][1]) : 
        if cnt < M: 
            sum += P[i][0]
            cnt += 1
        else :
            break
        
    if cnt >= M : 
        break
    
print(sum)
# Original solution
n,m=list(map(int,input().split()))
l=sorted([list(map(int,input().split())) for _ in range(n)])
c=[]
for a,b in l:
    for _ in range(b):
        c.append(a)
print((sum(c[:m])))


# Optimized solution
n,m=list(map(int,input().split()))
l=sorted([list(map(int,input().split())) for _ in range(n)])
ans=0
for a,b in l:
    if b<m:
        ans+=(a*b)
        m-=b
    else:
        ans+=(a*m)
        break
print(ans)
# Original solution
n, m = (int(i) for i in input().split())  
lis = []

for i in range(n):
  k, v= (int(i) for i in input().split())  
  lis += [k] * v

lis.sort()
print((sum(lis[:m])))

# Optimized solution
n, m = (int(i) for i in input().split())  
a = [[int(i) for i in input().split()] for i in range(n)] 
dic = {}
lis = []

a.sort()
ans = 0
for x in a:
  if x[1] >= m:
    ans += x[0] * m
    break
  else:
    ans += x[0] * x[1]
    m -= x[1]

print(ans)
# Original solution
def main():
    N, M = list(map(int, input().split()))
    A, B = [], []
    for i in range(N):
        a,b = list(map(int, input().split()))
        A.append(a)
        B.append(b)
    # print(A, B)
    # 最小のコスト順に買っていけばよい
    # 同じコストのときはどうするか
    sum = 0
    count = 0
    flg = False
    for i in range(N):
        l = A.index(min(A)) # 最安値となっている要素
        for j in range(B[l]): # 買い占め
            count = count + 1
            sum = sum + A[l]
            if count == M:
                flg = True
                break
        A[l] = max(A) + 1 # 配列Aを書き換え
        if flg:
            break

    print(sum)
    # print(count)

main()

# Optimized solution
def main():
    N, M = list(map(int, input().split()))
    lis = []
    for i in range(N):
        lis.append(list(map(int, input().split())))
    # 最小のコスト順に買っていけばよい
    # 同じコストのときはどうするか
    lis.sort() # 一列目をソート，二列目を対応してくれる，同じ値のときは二列目が低い方を優先
    sum = 0
    count = 0
    flg = False
    for i in range(N):
        if (count+lis[i][1]<M) :
            sum = sum + lis[i][0]*lis[i][1]
            count = count + lis[i][1] # Bi全部
        elif (count+lis[i][1]==M):
            sum = sum + lis[i][0]*lis[i][1]
            count = count + lis[i][1] # Bi全部
            break
        else:
            for j in range(lis[i][1]):
                sum = sum + lis[i][0]
                count = count + 1
                if count==M:
                    flg = True
                    break
        if flg:
            break

    print(sum)
    # print(count)

main()
# Original solution
[N, M] = list(map(int,input().split()))
A = [0]*N
B = [0]*N
for i in range(N):
    [A_tmp, B_tmp] = list(map(int,input().split()))
    A[i] = A_tmp
    B[i] = B_tmp

tmp = M
ans = 0
while (tmp > 0):
        idx_tmp = A.index(min(A))
        # break condition
        if B[idx_tmp] >= tmp:
            ans += tmp*A[idx_tmp]
            tmp = 0
        else:
            ans += A[idx_tmp]*B[idx_tmp]
            tmp = tmp - B[idx_tmp]
            A.pop(idx_tmp)
            B.pop(idx_tmp)

print(ans)

# Optimized solution
[N, M] = list(map(int,input().split()))
AB = [list(map(int, input().split())) for i in range(N)]

AB.sort(key=lambda x:x[0])
tmp = M
ans = 0

for i in range(N):
    #break
    if tmp <= AB[i][1]:
        ans += tmp * AB[i][0]
        break
    
    ans += AB[i][0] * AB[i][1]
    tmp = tmp - AB[i][1]


print(ans)
# Original solution
N, M, = (int(i) for i in input().split())
AB = [list(map(int, input().split())) for _ in range(N)]
AB.sort(key=lambda x:x[0])

money = 0
items = 0
for i in range(N):
    if (items + AB[i][1] < M):
        money += AB[i][0] * AB[i][1]
        items += AB[i][1]
    else:
        for j in range(1,AB[i][1]+1):
            if (items+j == M):
                money += AB[i][0] * j
                items +=j

print(money)

# Optimized solution
N, M, = (int(i) for i in input().split())
AB = [list(map(int, input().split())) for _ in range(N)]
AB.sort(key=lambda x:x[0])

money = 0
items = 0
for i in range(N):
    if (items + AB[i][1] < M):
        money += AB[i][0] * AB[i][1]
        items += AB[i][1]
    else:
        j = (M - items)
        money += AB[i][0] * j
        items +=j
        # for j in range(1,AB[i][1]+1):
        #     if (items+j == M):
        #         money += AB[i][0] * j
        #         items +=j

print(money)
# Original solution
if __name__ == '__main__':
    input_list = list(map(int, input().split()))
    N = input_list[0]
    M = input_list[1]

    A = [0]*N
    B = [0]*N

    for i in range(N):
        A[i], B[i] = list(map(int, input().split()))

    for i in range(N):
        if i == 0:
            prices = [A[0]]*B[0]
        else:
            prices.extend([A[i]]*B[i])

    sorted_prices = sorted(prices)

    answer = 0

    for i in range(M):
        answer += sorted_prices[i]

    print(answer)

# Optimized solution
if __name__ == '__main__':
    input_list = list(map(int, input().split()))
    N = input_list[0]
    M = input_list[1]

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

    sorted_AB = sorted(AB, key=lambda x:x[0])

    answer = 0
    cnt = 0
    for e in sorted_AB:
        pre_cnt = cnt

        Ai = e[0]
        Bi = e[1]

        cnt = min(M, cnt+Bi)
        answer += Ai * (cnt - pre_cnt)

        if cnt == M:
            break

    print(answer)