qyliang/CodeNanoFix huggingface dataset:
Buggy code:
# -*- coding: utf-8 -*-

import sys

def parse_input(lines_as_string = None):

    lines = []
    if lines_as_string is None:
        lines.append(input())
        tokens = lines[0].split(" ")
        n = int(tokens[0])
        m = int(tokens[1])
        for i in range(n):
            lines.append(input())
    else:
        lines = [e for e in lines_as_string.split("\n")][1:-1]
        print("lines=%s" % lines)
        tokens = lines[0].split(" ")
        n = int(tokens[0])
        m = int(tokens[1])

    a = []
    b = []
    for i in range(n):
        tokens = lines[i+1].split(" ")
        a.append(int(tokens[0]))
        b.append(int(tokens[1]))

    return (n, m, a, b)

def solve(n, m, a, b):

    
    s_a = sorted([(i, e) for i, e in enumerate(a)], key=lambda e: e[1])
    print("s_a=%s" % s_a)

    current = m
    total = 0
    tmp = 0
    for i, e in s_a:
        if current > b[i]:
            tmp = e * b[i]
            current = current - b[i]
        else:
            tmp = e * current
            current = 0

        total = total + tmp

#        print("i=%d, total=%d" % (i, total))
        if current == 0:
            break

    return total

def main():

    print("%d" % solve(*parse_input()))

if __name__ == '__main__':

    main()


Fixed code:
# -*- coding: utf-8 -*-

import sys

def parse_input(lines_as_string = None):

    lines = []
    if lines_as_string is None:
        lines.append(input())
        tokens = lines[0].split(" ")
        n = int(tokens[0])
        m = int(tokens[1])
        for i in range(n):
            lines.append(input())
    else:
        lines = [e for e in lines_as_string.split("\n")][1:-1]
        print("lines=%s" % lines)
        tokens = lines[0].split(" ")
        n = int(tokens[0])
        m = int(tokens[1])

    a = []
    b = []
    for i in range(n):
        tokens = lines[i+1].split(" ")
        a.append(int(tokens[0]))
        b.append(int(tokens[1]))

    return (n, m, a, b)

def solve(n, m, a, b):

    
    s_a = sorted([(i, e) for i, e in enumerate(a)], key=lambda e: e[1])
#    print("s_a=%s" % s_a)

    current = m
    total = 0
    tmp = 0
    for i, e in s_a:
        if current > b[i]:
            tmp = e * b[i]
            current = current - b[i]
        else:
            tmp = e * current
            current = 0

        total = total + tmp

#        print("i=%d, total=%d" % (i, total))
        if current == 0:
            break

    return total

def main():

    print("%d" % solve(*parse_input()))

if __name__ == '__main__':

    main()
Buggy code:
n,m=map(int,input().split())
AB=[list(map(int,input().split())) for _ in range(n)]
AB.sort()
print(AB)
cnt=0
i=-1
ans=0
while cnt<m:
    i+=1
    ans+=AB[i][0]*AB[i][1]
    cnt+=AB[i][1]
    #print(ans,cnt)
ans-=AB[i][0]*AB[i][1]
cnt-=AB[i][1]
#print(ans,cnt)
while cnt<m:
    ans+=AB[i][0]
    cnt+=1
print(ans)


Fixed code:
n,m=map(int,input().split())
AB=[list(map(int,input().split())) for _ in range(n)]
AB.sort()
#print(AB)
cnt=0
i=-1
ans=0
while cnt<m:
    i+=1
    ans+=AB[i][0]*AB[i][1]
    cnt+=AB[i][1]
    #print(ans,cnt)
ans-=AB[i][0]*AB[i][1]
cnt-=AB[i][1]
#print(ans,cnt)
while cnt<m:
    ans+=AB[i][0]
    cnt+=1
print(ans)
Buggy code:
# -*- coding: utf-8 -*-
N, M = map(int, input().split())
t = [tuple(map(int, input().split())) for i in range(N)] 
t = sorted(t, key = lambda tt: tt[1])
n = 0
ans = 0
for a,b in t:
    if n+b < M:
        ans += a*b
        n += b
    else:
        ans += (M-n)*a
        break
print(ans)



Fixed code:
# -*- coding: utf-8 -*-
N, M = map(int, input().split())
t = [tuple(map(int, input().split())) for i in range(N)] 
t = sorted(t, key = lambda tt: tt[0])
n = 0
ans = 0
for a,b in t:
    if n+b < M:
        ans += a*b
        n += b
    else:
        ans += (M-n)*a
        break
print(ans)
Buggy code:
n, m = map(int, input().split())

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

sorted_shop = sorted(shop, key=lambda x: x[1])

count = m
money = 0
for shop in sorted_shop:
	if count == 0:
		break
	if count >= shop[1]:
		count = count - shop[1]
		money += shop[0] * shop[1]
	else:
		money += shop[0] * count
		count = 0

print(money)

Fixed code:
n, m = map(int, input().split())

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

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

count = m
money = 0
for shop in sorted_shop:
	if count == 0:
		break
	if count >= shop[1]:
		count = count - shop[1]
		money += shop[0] * shop[1]
	else:
		money += shop[0] * count
		count = 0

print(money)
Buggy code:
N, M=map(int, input().split())
info=[]
for _ in range(N):
  a, b=map(int, input().split())
  info.append([a,b])

info.sort(key=lambda x:x[1])
ans=0
for a, b in info:
  if M>=b:
    ans+=a*b
    M-=b
  elif M<b and M>0:
    ans+=a*M
    break
  else:
    break
print(ans)

Fixed code:
N, M=map(int, input().split())
info=[]
for _ in range(N):
  a, b=map(int, input().split())
  info.append([a,b])

info.sort(key=lambda x:x[0])
ans=0
for a, b in info:
  if M>=b:
    ans+=a*b
    M-=b
  elif M<b and M>0:
    ans+=a*M
    break
  else:
    break
print(ans)
Buggy code:
N, M = map(int, input().split())
AB = sorted([list(map(int, input().split())) for _ in range(N)])

res = M
n = 0
cnt = 0

if N == 1:
    cnt = res * AB[0][1]
else:
    while(AB[n][1] <= res):
        cnt += AB[n][0] * AB[n][1]
        res -= AB[n][1]
        n += 1

    cnt += res * AB[n][0]

print(cnt)


Fixed code:
N, M = map(int, input().split())
AB = sorted([list(map(int, input().split())) for _ in range(N)])

res = M
n = 0
cnt = 0


while(AB[n][1] < res):
    cnt += AB[n][0] * AB[n][1]
    res -= AB[n][1]
    n += 1

cnt += res * AB[n][0]

print(cnt)
Buggy code:
N, M = map(int,input().split())
AB = sorted([list(map(int,input().split())) for _ in range(N)])

money = 0
for a, b in AB:
  if(M-b >= 0):
    money += a*b
    M -= b
  else:
    money += a*M
    M -= M-b
print(money)

Fixed code:
N, M = map(int,input().split())
AB = sorted([list(map(int,input().split())) for _ in range(N)])

money = 0
for a, b in AB:
  if M <= 0:
    break
  if M-b >= 0:
    money += a*b
    M -= b
  else:
    money += a*M
    M -= M
print(money)
Buggy code:
N, M = map(int, input().split())
AB = {}
for n in range(N):
    a, b = list(int(x) for x in input().split())
    AB[a] = b
yen = 0
AB = sorted(AB.items())
for a, b in AB:
    if b <= M:
        yen += a*b
        M -= b
    else:
        yen += a*M
print(yen)


Fixed code:
N, M = map(int, input().split())
AB = {}
for n in range(N):
    a, b = list(int(x) for x in input().split())
    if a in AB:
        AB[a] += b
    else:
        AB[a] = b
yen = 0
AB = sorted(AB.items())
for a, b in AB:
    if b <= M:
        yen += a*b 
        M -= b
    else:
        yen += a*M
        M = 0
print(yen)
Buggy code:
N, M = list(map(int, input().split()))
sh_li = []
for i in range(N):
    a, b = list(map(int, input().split()))
    sh_li.append([a, b])
sh_li.sort(key=lambda x:x[0],reverse=False)

def calc(li, m):
    total = 0
    for sh in li:
        print(sh)
        if sh[1] < m:
            total += sh[0] * sh[1]
            m -= sh[1]
        else:
            total += sh[0] * m
            return total

print(calc(sh_li, M))

Fixed code:
N, M = list(map(int, input().split()))
sh_li = []
for i in range(N):
    a, b = list(map(int, input().split()))
    sh_li.append([a, b])
sh_li.sort(key=lambda x:x[0],reverse=False)

def calc(li, m):
    total = 0
    for sh in li:
        if sh[1] < m:
            total += sh[0] * sh[1]
            m -= sh[1]
        else:
            total += sh[0] * m
            return total

print(calc(sh_li, M))
Buggy code:
N,M = map(int,input().split())
AB =[list(map(int,input().split())) for i in range(N)]

AB = sorted(AB)
total=0
for i in range(N):
    if AB[i][1]>M:
        total = total + AB[i][0]*M
    else:
        total = total + AB[i][0]*AB[i][1]
        M = M - AB[i][1]
print(total)

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

AB = sorted(AB)
total=0
for i in range(N):
    if AB[i][1]>M:
        total = total + AB[i][0]*M
        break
    else:
        total = total + AB[i][0]*AB[i][1]
        M = M - AB[i][1]

print(total)
Buggy code:
N,M = map(int,input().split())
AB = sorted([list(map(int,input().split())) for i in range(N)])
res = 0
for a,b in range(N):
    M -= b
    res += a*b
    if M < 0:
        res += a*M
        break
print(res)

Fixed code:
N,M = 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
    res += a*b
    if M < 0:
        res += a*M
        break
print(res)
Buggy code:
from sys import stdin
import heapq
hq = []  

NM = input()
NM = NM.split()
N = int(NM[0])
M = int(NM[1])

hq = []
AB = {}
for i in range(N):
  temp = input()
  temp = temp.split()
  AB[int(temp[0])] = int(temp[1])
  heapq.heappush(hq, (int(temp[0]), int(temp[1])))

print(hq)
cost = 0
amount = 0
for i in range(N):
  if amount + hq[i][1] < M:
    amount += hq[i][1]
    cost += hq[i][0]*hq[i][1]
  else:
    temp = M - amount
    cost += hq[i][0]*temp
    break
    
print(cost)


Fixed code:
from sys import stdin
import heapq
hq = []  

NM = input()
NM = NM.split()
N = int(NM[0])
M = int(NM[1])

hq = []
AB = {}
for i in range(N):
  temp = input()
  temp = temp.split()
  AB[int(temp[0])] = int(temp[1])
  heapq.heappush(hq, (int(temp[0]), int(temp[1])))

cost = 0
amount = 0
for i in range(N):
  temp = heapq.heappop(hq)
  if amount + temp[1] < M:
    amount += temp[1]
    cost += temp[0]*temp[1]
  else:
    temp1 = M - amount
    cost += temp[0]*temp1
    break
    
print(cost)
Buggy code:
n,m = map(int,input().split())
AB = [(int(i) for i in input().split()) for j 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)


Fixed code:
n,m = 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)
Buggy code:
N, M = (int(i) for i in input().split())  
e = [[int(i) for i in input().split()] for i in range(N)]

result = 0
for x in e:
    if M > x[1]:
        M -= x[1]
        result += x[0] * x[1]
    else:
        result += x[0] * M
        break

print(result)


Fixed code:
N, M = (int(i) for i in input().split())  
e = sorted([[int(i) for i in input().split()] for i in range(N)])

result = 0
for x in e:
    if M > x[1]:
        M -= x[1]
        result += x[0] * x[1]
    else:
        result += x[0] * M
        break

print(result)
Buggy code:
M, N = map(int, input().split())
COST, STOCK = range(2)
energy_drinks = sorted((tuple(map(int, input().split())) for _ in range(N)), key=lambda tuple_: tuple_[COST])

cost = 0
for energy_drink in energy_drinks:
    buy = min(energy_drink[STOCK], N)
    N -= buy
    cost += buy * energy_drink[COST]
print(cost)


Fixed code:
M, N = map(int, input().split())
COST, STOCK = range(2)
energy_drinks = sorted((tuple(map(int, input().split())) for _ in range(M)), key=lambda tuple_: tuple_[COST])

cost = 0
for energy_drink in energy_drinks:
    buy = min(energy_drink[STOCK], N)
    N -= buy
    cost += buy * energy_drink[COST]
print(cost)
Buggy code:
a,b=map(int,input().split())
e=[]
for i in range(a):
    c,d=map(int, input().split())
    e+=[[c,d]]
e.sort()
print(e)
a=i=j=0
while i < b:
    a+=(e[j][0]*e[j][1])
    i+=e[j][1]
    j+=1
print(a-((i-b)*e[j-1][0]))

Fixed code:
a,b=map(int,input().split())
e=[]
for i in range(a):
    c,d=map(int, input().split())
    e+=[[c,d]]
e.sort()
a=i=j=0
while i < b:
    a+=(e[j][0]*e[j][1])
    i+=e[j][1]
    j+=1
print(a-((i-b)*e[j-1][0]))
Buggy code:
n, m  = map(int, input().split())
arr = []
for i in range(n):
    a, b = map(int, input().split())
    arr.append([a, b])
a.sort()
ans = 0
idx = 0
while True:
    if m <= 0:
        break
    ans += arr[idx][0] * min(arr[idx][1], m)
    m -= min(arr[idx][1], m)
    idx += 1
print(ans)


Fixed code:
n, m  = map(int, input().split())
arr = []
for i in range(n):
    a, b = map(int, input().split())
    arr.append([a, b])
arr.sort()
ans = 0
idx = 0
while True:
    if m <= 0:
        break
    ans += arr[idx][0] * min(arr[idx][1], m)
    m -= min(arr[idx][1], m)
    idx += 1
print(ans)
Buggy code:
n,m=map(int,input().split())
ab = [list(map(int,input().split())) for i in range(n)]
acsd=sorted(ab,key=lambda a:a[0])
print(n,m);print(acsd)
yen_tot=0
n_b=m
def count_p(store,n_v):
    yen,num=store
    return yen*min(n_v,num),max(n_v-num,0)
for s in acsd:
    cost,rem=count_p(s,n_b)
    yen_tot+=cost
    n_b=rem
    if rem==0: break
print(yen_tot)


Fixed code:
n,m=map(int,input().split())
ab = [list(map(int,input().split())) for i in range(n)]
acsd=sorted(ab,key=lambda a:a[0])
yen_tot=0
n_b=m
def count_p(store,n_v):
    yen,num=store
    return yen*min(n_v,num),max(n_v-num,0)
for s in acsd:
    cost,rem=count_p(s,n_b)
    yen_tot+=cost
    n_b=rem
    if rem==0: break
print(yen_tot)
Buggy code:
import numpy as np

n, m = map(int, input().split())
a = np.zeros(n)
b = np.zeros(n)
for i in range(n):
  a[i], b[i] = map(int, input().split())
idx = np.argsort(a)
a = a[idx]
b = b[idx]
price = 0
for i in range(n):
  if m < b[i]:
    price += m * a[i]
  else:
    price += b[i] * a[i]
    m -= b[i]
print(int(price))


Fixed code:
import numpy as np

n, m = map(int, input().split())
a = np.zeros(n)
b = np.zeros(n)
for i in range(n):
  a[i], b[i] = map(int, input().split())
idx = np.argsort(a)
a = a[idx]
b = b[idx]
price = 0
for i in range(n):
  if m <= b[i]:
    price += m * a[i]
    m = 0
  else:
    price += b[i] * a[i]
    m -= b[i]
  if m == 0:
    break
print(int(price))
Buggy code:
N,M=map(int,input().split())
k=M
s=0
A=[list(map(int,input().split())) for i in range(N)]
A=sorted(A,key=lambda x:x[0])
for i in range(N):
  while k>0:
    if k>A[i][1]:
      k=k-A[i][1]
      s+=A[i][0]*A[i][1]
    else:
      k=0
      s+=A[i][0]*k
print(s)
  

Fixed code:
N,M=map(int,input().split())
k=M
s=0
A=[list(map(int,input().split())) for i in range(N)]
A=sorted(A,key=lambda x:x[0])
while k>0:
  for i in range(N):
    if k>A[i][1]:
      s+=A[i][0]*A[i][1]
      k=k-A[i][1]
    else:
      s+=A[i][0]*k
      k=0
print(s)
Buggy code:
N,M = list(map(int, input().split()))
lis=[]
for i in range(N):
    a,b = list(map(int, input().split()))
    lis.append([a,b])

lis.sort()

count=0
money=0
ind=0
while count+lis[ind][1]<M:
    count+=lis[ind][1]
    money+=lis[ind][0]*lis[ind][1]
    ind+=1
    print(ind)
    

money+=(M-count)*lis[ind][0]
print(money)

Fixed code:
N,M = list(map(int, input().split()))
lis=[]
for i in range(N):
    a,b = list(map(int, input().split()))
    lis.append([a,b])

lis.sort()

count=0
money=0
ind=0
while count+lis[ind][1]<M:
    count+=lis[ind][1]
    money+=lis[ind][0]*lis[ind][1]
    ind+=1
    #print(ind)
    

money+=(M-count)*lis[ind][0]
print(int(money))
Buggy code:
N,M = map(int,input().split())
a = [list(map(int,input().split())) for i in range(N)]
a.sort(key=lambda x:x[0])
print(a)
ans = 0
nokori = M
for j in range(N):
	ans += a[j][0]*min(a[j][1],nokori)
	nokori -= a[j][1]
	if nokori <= 0:
		print(ans)
		exit()



Fixed code:
N,M = map(int,input().split())
a = [list(map(int,input().split())) for i in range(N)]
a.sort(key=lambda x:x[0])
ans = 0
nokori = M
for j in range(N):
	ans += a[j][0]*min(a[j][1],nokori)
	nokori -= a[j][1]
	if nokori <= 0:
		print(ans)
		exit()
Buggy code:
from operator import itemgetter

n, m = map(int, input().split())
store = [] 
cart, price = 0, 0

for _ in range(n):
    temporary_dict = {}
    a, b = map(int, input().split())
    temporary_dict["value"] = a
    temporary_dict["stock"] = b
    store.append(temporary_dict)

store.sort(key=itemgetter("value", "stock"))

for i in range(n):
    test_value = store[i]["value"]
    test_stock = store[i]["stock"]
    if test_stock < m:
        m -= test_stock
        price += test_value*test_stock
    else:
        price += test_value*m

print(price)

Fixed code:
from operator import itemgetter

n, m = map(int, input().split())
store = [] 
cart, price = 0, 0

for _ in range(n):
    temporary_dict = {}
    a, b = map(int, input().split())
    temporary_dict["value"] = a
    temporary_dict["stock"] = b
    store.append(temporary_dict)

store.sort(key=itemgetter("value", "stock"))

for i in range(n):
    test_value = store[i]["value"]
    test_stock = store[i]["stock"]
    if test_stock < m:
        m -= test_stock
        price += test_value*test_stock
    else:
        price += test_value*m
        break

print(price)
Buggy code:
n,m=map(int,input().split())
edr=[]
for i in range(n):
  edr.append(list(map(int,input().split())))
edr.sort(key =lambda x:x[0])
cnt=0
ans=0
for i in range(n):
  cnt+=0
  ans+=edr[i][0]*edr[i][1]
  if cnt>=m:
    ans-=(cnt-m)*edr[i][0]
    break
print(ans)

Fixed code:
n,m=map(int,input().split())
edr=[]
for i in range(n):
  edr.append(list(map(int,input().split())))
edr.sort(key =lambda x:x[0])
cnt=0
ans=0
for i in range(n):
  cnt+=edr[i][1]
  ans+=edr[i][0]*edr[i][1]
  if cnt>=m:
    ans-=(cnt-m)*edr[i][0]
    break
print(ans)
Buggy code:
n,m = map(int,input().split())
plist = []
for _ in range(n):
    plist.append([int(x) for x in input().split()])

plist.sort()
print(plist)

cost=0
i = 0

while i < len(plist):
    tmp = plist[i]
    if tmp[1] < m:
        m -= tmp[1]
        cost += tmp[0] * tmp[1]
        i += 1
        continue
    else:
        cost += tmp[0] * m
        break
print(cost)


Fixed code:
n,m = map(int,input().split())
plist = []
for _ in range(n):
    plist.append([int(x) for x in input().split()])

plist.sort()

cost=0
i = 0

while i < len(plist):
    tmp = plist[i]
    if tmp[1] < m:
        m -= tmp[1]
        cost += tmp[0] * tmp[1]
        i += 1
        continue
    else:
        cost += tmp[0] * m
        break
print(cost)
Buggy code:
#import pysnooper
#import os,re,sys,operator,math,heapq,string
#from collections import Counter,deque
#from operator import itemgetter
#from itertools import accumulate,combinations,groupby,combinations_with_replacement
from sys import stdin,setrecursionlimit
#from copy import deepcopy

setrecursionlimit(10**6)
input=stdin.readline

n,m=map(int,input().split())
a=sorted([list(map(int,input().split())) for _ in range(n)])
print(a)
cnt,can=0,0
for i in range(n):
    if can+a[i][1]<m:
        cnt+=a[i][0]*a[i][1]
        can+=a[i][1]
    else:
        cnt+=a[i][0]*(m-can)
        break
    #print(cnt)
print(cnt)

Fixed code:
#import pysnooper
#import os,re,sys,operator,math,heapq,string
#from collections import Counter,deque
#from operator import itemgetter
#from itertools import accumulate,combinations,groupby,combinations_with_replacement
from sys import stdin,setrecursionlimit
#from copy import deepcopy

setrecursionlimit(10**6)
input=stdin.readline

n,m=map(int,input().split())
a=sorted([list(map(int,input().split())) for _ in range(n)])
#print(a)
cnt,can=0,0
for i in range(n):
    if can+a[i][1]<m:
        cnt+=a[i][0]*a[i][1]
        can+=a[i][1]
    else:
        cnt+=a[i][0]*(m-can)
        break
    #print(cnt)
print(cnt)
Buggy code:
N,M = map(int,input().split())
AB = [list(map(int,input().split())) for _ in range(N)]
AB.sort(key=lambda x:x[0])
answer = 0
for ab in AB:
    if M - ab[1] <= 0:
        answer += M * ab[0]
    else:
        answer += ab[0] * ab[1]
        M -= ab[1]
print(answer)



Fixed code:
N,M = map(int,input().split())
AB = [list(map(int,input().split())) for _ in range(N)]
AB.sort(key=lambda x:x[0])
answer = 0
for ab in AB:
    if M - ab[1] <= 0:
        answer += M * ab[0]
        break
    else:
        answer += ab[0] * ab[1]
        M -= ab[1]
print(answer)
Buggy code:
ii = lambda: int(input())
mi = lambda: map(int, input().split())
li = lambda: list(mi())

n, m = mi()
a = [li() for i in range(n)]
a.sort(reverse=True)
rem = m
sm = 0
while a:
    rate, cnt = a.pop()
    take = min(rem, cnt)
    sm += take * rate
    rem -= take
print(sm)
=

Fixed code:
ii = lambda: int(input())
mi = lambda: map(int, input().split())
li = lambda: list(mi())

n, m = mi()
a = [li() for i in range(n)]
a.sort(reverse=True)
rem = m
sm = 0
while a:
    rate, cnt = a.pop()
    take = min(rem, cnt)
    sm += take * rate
    rem -= take
print(sm)
Buggy code:
import numpy as np

N,M =[int(i) for i in input().split()]

AB = np.ones([N,2])


for i in range(N):
    AB[i,0],AB[i,1] = [int(i) for i in input().split()]
    
count=0
price=0

AB_new = np.sort(AB,axis=0)

for i in range(N):
    if count<=M:
        count+=AB_new[i,1]
        if count<=M:
            price+=AB_new[i,0]*AB_new[i,1]
        if count>M:
            price+=AB_new[i,0]*(M-count+AB_new[i,1])
    else:
        break

        
print(int(price))

Fixed code:
import numpy as np

N,M =[int(i) for i in input().split()]

AB = np.ones([N,2])


for i in range(N):
    AB[i,0],AB[i,1] = [int(i) for i in input().split()]
    
count=0
price=0

AB_new = AB[np.argsort(AB[:,0])]

for i in range(N):

    if count<=M: 
        count+=AB_new[i,1]
        if count<=M:
            price+=AB_new[i,0]*AB_new[i,1]
        elif count>M:
            price+=AB_new[i,0]*(M-count+AB_new[i,1])
    else:
        break

        
print(int(price))
Buggy code:
N,M = map(int,input().split())
AB = [tuple(int(i) for i in input().split()) for j in range(N)]
AB.sort()
ans = 0
for i in range(N):
	a,b = AB[i]
	if M-b > 0:
		ans += a*b
		M -= b
    else:
		ans += M*b
		break
print(ans)

Fixed code:
N,M = map(int,input().split())
AB = [tuple(int(i) for i in input().split()) for j in range(N)]
AB.sort()
ans = 0
for i in range(N):
    a,b = AB[i]
    if M -b > 0:
        ans += a*b
        M -= b
    else:
        ans += M*a
        break
print(ans)
Buggy code:
n,m = map(int,input().split())
ab = [list(map(int,input().split())) for i in range(n)]

c = sorted(ab, key= lambda x:x[0])
s = [0]
for i in range(n):
    s.append(s[i] + c[i][1])
    if s[i] <= m <= s[i+1]:
        stop = i

ans=0
for i in range(stop):
    ans += c[i][0]*c[i][1]
    print(ans)
while s[stop] < m:
    ans += c[stop][0]
    s[stop] += 1
print(ans)


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

c = sorted(ab, key= lambda x:x[0])
s = [0]
for i in range(n):
    s.append(s[i] + c[i][1])
    if s[i] <= m <= s[i+1]:
        stop = i

ans=0
for i in range(stop):
    ans += c[i][0]*c[i][1]
while s[stop] < m:
    ans += c[stop][0]
    s[stop] += 1
print(ans)
Buggy code:
import sys
from collections import deque
from operator import itemgetter
input = sys.stdin.readline
N, M = map(int, input().split())

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

A = sorted(A, key=itemgetter(1))

m=0
cost=0

for i in range(N):
    if m >= M:
        break
    buy = min(M - m, A[i][1])
    cost += A[i][0] * buy
    m += buy

print(cost)

Fixed code:
import sys
from collections import deque
from operator import itemgetter
input = sys.stdin.readline
N, M = map(int, input().split())

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

A = sorted(A, key=itemgetter(0))

m=0
cost=0

for i in range(N):
    if m >= M:
        break
    buy = min(M - m, A[i][1])
    cost += A[i][0] * buy
    m += buy

print(cost)
Buggy code:
n,m=map(int,input().split());d,ans=[],0
for i in range(n):d.append(list(map(int,input().split())))
d.sort()
for i in range(n):
  if d[i][1]<=m:
    ans+=i*d[i][1]
    m-=d[i][1]
  else:
    ans+=d[i][0]*m
    m=0
  if m<=0:break
print(ans)

Fixed code:
n,m=map(int,input().split());d,ans=[],0
for i in range(n):d.append(list(map(int,input().split())))
d.sort()
for i in range(n):
  if d[i][1]<=m:
    ans+=d[i][0]*d[i][1]
    m-=d[i][1]
  else:
    ans+=d[i][0]*m
    m=0
  if m<=0:break
print(ans)
Buggy code:
n, m = map(int, input().split())
AB = [[] for _ in range(n)]
for i in range(n):
  AB[i] = list(map(int, input().split()))
  
AB.sort(key=lambda x: x[0])

c = 0
ans = 0
for i,j in AB:
  c += j
  if c < m:
    ans += i*j
  else:
    ans += i*(m-(c-j))

print(ans)


Fixed code:
n, m = map(int, input().split())
AB = [[] for _ in range(n)]
for i in range(n):
  AB[i] = list(map(int, input().split()))
  
AB.sort(key=lambda x: x[0])

c = 0
ans = 0
for i,j in AB:
  c += j
  if c < m:
    ans += i*j
  else:
    ans += i*(m-(c-j))
    break

print(ans)