qyliang/CodeNanoFix huggingface dataset:
Buggy code:
s = input().split()
N = int(s[0])
M = int(s[1])

AB = {}
for i in range(N):
  data = input().split()
  AB[int(data[0])] = int(data[1])

money = 0
num = 0
for A,B in sorted(AB.items()):
  if num+B < M:
    money += A*B
  	num += B
  else:
    money += A*(M-num)
    break
  
print(money)

Fixed code:
s = input().split()
N = int(s[0])
M = int(s[1])
 
AB = {}
for i in range(N):
  data = input().split()
  if int(data[0]) in AB.keys():
    AB[int(data[0])] += int(data[1])
  else:
    AB[int(data[0])] = int(data[1])
AB = sorted(AB.items())
money = 0
num = 0
for A,B in AB:
  if num+B < M:
    money += A*B
    num += B
  elif num+B == M:
    money += A*B
    break
  elif num+B > M:
    money += A*(M-num)
    break
print(int(money))
Buggy code:
n,m=map(int,input().split())
potion=[]
for i in range(N):
    potion_R = list(map(int,input().split())
    potion.append(potion_R)
potion.sort()
ans=0
number=m
for i in potion:
    if i[1]<=number:
        number-= i[1]
        ans+= i[0]*i[1]
    else:
        ans+= i[0]*number
        break
print(ans)

Fixed code:
n,m=map(int,input().split())
potion=[]
for i in range(n):
    potion_R = list(map(int,input().split()))
    potion.append(potion_R)
potion.sort()
ans=0
number=m
for i in potion:
    if i[1]<=number:
        number-= i[1]
        ans+= i[0]*i[1]
    else:
        ans+= i[0]*number
        break
print(ans)
Buggy code:
n,m = map(int,input().split())
l = []
for i in range(n):
    pair = list(map(int,input().split()))
    l.append(pair)
else:
    l.sort()

res = 0
for i in range(n):
    m -= l[i][1]
    res += l[i][0]*l[i][1]
    if m < 0:
        res += m*l[i][0]
        print(res)
        break


Fixed code:
n,m = map(int,input().split())
l = []
for i in range(n):
    pair = list(map(int,input().split()))
    l.append(pair)
else:
    l.sort()

res = 0
for i in range(n):
    m -= l[i][1]
    res += l[i][0]*l[i][1]
    if m <= 0:
        res += l[i][0]*m
        print(res)
        break
Buggy code:
n,m=map(int,input().split())

X=[]

for i in range(n):
    X.append(list(map(int,input().split())))

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

cnt=0
ans=0
for i in range(n):
    ad=Y[i][1]
    temp=cnt
    cnt+=ad
    if cnt+ad>m:
        ad=m-temp
        ans+=Y[i][0]*ad
        break
    ans+=Y[i][0]*ad

print(ans)

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

X=[]

for i in range(n):
    X.append(list(map(int,input().split())))

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

cnt=0
ans=0
for i in range(n):
    cnt+=Y[i][1]
    if cnt>m:
        ad=m-(cnt-Y[i][1])
        ans+=Y[i][0]*ad
        break
    ans+=Y[i][0]*Y[i][1]

print(ans)
Buggy code:
N, M = list(map(int, input().split()))
data = [list(map(int, input().split())) for _ in range(N)]
data.sort()

honsu=0
cost=0
for i in range(N):
  honsu+=data[i][1]
  cost+=data[i][0]*data[i][1]
 
  if honsu>M:
    ans=cost-((honsu-M)*data[i][0])
print(ans)

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

honsu=0
cost=0
for i in range(N):
  honsu+=data[i][1]
  cost+=data[i][0]*data[i][1]
 
  if honsu>M:
    cost=cost-((honsu-M)*data[i][0])
    print(cost)
    exit()
print(cost)
Buggy code:
N, M = map(int, input().split())
A = [list(map(int, input().split())) for i in range(N)]
A.sort()
sumcost = 0
k = 0
t = 0
while M-k>0:
    buy = min(M-k, A[t][0])
    sumcost += A[t][0]*buy
    k += buy
    t += 1


print(sumcost)

Fixed code:
N, M = map(int, input().split())
A = [list(map(int, input().split())) for i in range(N)]
A.sort()
sumcost = 0
k = 0
t = 0
while M-k>0:
    buy = min(M-k, A[t][1])
    sumcost += A[t][0]*buy
    k += buy
    t += 1


print(sumcost)
Buggy code:
# https://atcoder.jp/contests/abc121/tasks/abc121_c

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

shop = []
for _ in range(n):
    a, b = map(int, input().split())
    shop.append((a, b))

shop.sort(key=lambda x: x[1])

c = 0
ans = 0
i = 0
while c < m and i < n:
    a, b = shop[i]
    if c + b >= m:
        ans += (m - c) * a
        c += (m - c)
    else:
        ans += b * a
        c += b
    i += 1
print(ans)

Fixed code:
# https://atcoder.jp/contests/abc121/tasks/abc121_c

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

shop = []
for _ in range(n):
    a, b = map(int, input().split())
    shop.append((a, b))

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

c = 0
ans = 0
i = 0
while c < m and i < n:
    a, b = shop[i]
    if c + b >= m:
        ans += (m - c) * a
        c += (m - c)
    else:
        ans += b * a
        c += b
    i += 1
print(ans)
Buggy code:
n,m=[int(i) for i in input().split(' ')]
class P:
  def __init__(self, a, b)
  	self.a = a
    self.b = b

p = []
for i in range(n):
  a,b=[int(i) for i in input().split(' ')]
  p.append(P(a, b))

  
mon = 0
p.sort(key=lambda x: x.a)
for e in p:
  if m <= e.b:
    mon += e.q * m
    m = 0
  else:
    m -= e.b
    mon += e.a * e.b

print(mon)

Fixed code:
n,m=[int(i) for i in input().split(' ')]
class P:
  def __init__(self, a, b):
    self.a = a
    self.b = b

p = []
for i in range(n):
  a,b=[int(i) for i in input().split(' ')]
  p.append(P(a, b))

  
mon = 0
p.sort(key=lambda x: x.a)
for e in p:
  if m <= e.b:
    mon += e.a * m
    m = 0
  else:
    m -= e.b
    mon += e.a * e.b

print(mon)
Buggy code:
N,M=map(int,input().split())
AB=[[int(x) for x in input().split()] for i in range(N)]
AB.sort(key=lambda x: x[0])
out = 0
count = M
for i in range(M):
    if AB[i][1]<count+1:
        count-=AB[i][1]
        out+=AB[i][0]*AB[i][1]
    else:
        out+=count*AB[i][0]
        break
print(out)

Fixed code:
N,M=map(int,input().split())
AB=[[int(x) for x in input().split()] for i in range(N)]
AB.sort(key=lambda x: x[0])
out = 0
count = M
for i in range(N):
    if AB[i][1]<count+1:
        count-=AB[i][1]
        out+=AB[i][0]*AB[i][1]
    else:
        out+=count*AB[i][0]
        break
print(out)
Buggy code:
n,m  = map(int,input().split()) 
z = []
for i in range(n):
  a,b = list(map(int,input().split()))
  z.append((a,b))  
z = sorted(z)
sum = 0
for a,b in z:
  if b <= m:
    sum += a * b
    m -= b
  else:
    sum += a * m
print(sum)

Fixed code:
n,m  = map(int,input().split()) 
z = []
for i in range(n):
  a,b = list(map(int,input().split()))
  z.append((a,b))  
z = sorted(z)
sum = 0
for a,b in z:
  if b <= m:
    sum += a * b
    m -= b
  else:
    sum += a * m
    break
print(sum)
Buggy code:
n, m = map(int, input().split())
a = []
for i in range(n):
    a.append(list(map(int, input().split())))

a = sorted(a, key=lambda x: x[0])
print(a)
purchase_price = 0


for price, count in a:
    if count < m:
        purchase_price += price * count
        m -= count

    else:
        purchase_price += price * m
        m = 0

print(purchase_price)


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

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


for price, count in a:
    if count < m:
        purchase_price += price * count
        m -= count

    else:
        purchase_price += price * m
        m = 0

print(purchase_price)
Buggy code:
n, m = [int(i) for i in input().split()]
ab = [[int(i) for i in input().split()] for j in range(n)]
ab = sorted(ab, key=lambda x:x[0])

sm = 0
i = 0
for i in ab:
    if m > i[1]:
        sm += i[0] * i[1]
        m -= i[1]
    else:
        sm += i[0] * m
        break
print(ab)

Fixed code:
n, m = [int(i) for i in input().split()]
ab = [[int(i) for i in input().split()] for j in range(n)]
ab = sorted(ab, key=lambda x:x[0])

sm = 0
i = 0
for i in ab:
    if m > i[1]:
        sm += i[0] * i[1]
        m -= i[1]
    else:
        sm += i[0] * m
        break
print(sm)
Buggy code:
N, M = map(int, input().split())
AB = []
for i in range(N):
    a, b = map(int, input().split())
    AB.append([a,b])

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

ans = 0
for i in range(N):
    a = sortedAB[i][0]
    b = sortedAB[i][1]
    if M == 0:
        exit()
    if b <= M:
        M -= b
        ans += a*b
    else:
        ans += a*M


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

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

ans = 0
for i in range(N):
    a = sortedAB[i][0]
    b = sortedAB[i][1]
    if M == 0:
        print(ans)
        exit()
    if b <= M:
        ans += a*b
        M -= b
    else:
        ans += a*M
        M = 0

print(ans)
Buggy code:
#!/usr/bin/env python3
N, M = map(int, input().split())
AB = [list(map(int, input().split())), for i in range(N)]

AB.sort()

ans = 0
for i, j in AB
	ans += i * min(M, j)
	M -= min(M, j)

print(ans)


Fixed code:
#!/usr/bin/env python3
N, M = map(int, input().split())
AB = [list(map(int, input().split())) for i in range(N)]

AB.sort()

ans = 0
for i, j in AB:
	ans += i * min(M, j)
	M -= min(M, j)

print(ans)
Buggy code:
import numpy as np

N,M = map(int,input().split())
data = []
for i in range(N):
    b = list(map(int,input().split())) # data = [[cost,max_num],...]
    data.append(b)
# print(data)

# N=2 
# M=5
# data = [[4, 9], [2, 4]]
# data.sort()
npsorted = np.sort(np.array(data),axis=0)

num_drink=0
cost=0
shop_index=0
while (shop_index < N and num_drink < M):
    num_drink += npsorted[shop_index][1]
    cost += npsorted[shop_index][0]*npsorted[shop_index][1]
    shop_index += 1

# num_drink >= M by buying npsorted[shop_index-1][0]yen drink from shop_index
excess = num_drink - M
ans = cost - npsorted[shop_index-1][0] * excess
print(ans)
# print(data)

Fixed code:
import numpy as np

N,M = map(int,input().split())
data = []
for i in range(N):
    b = list(map(int,input().split())) # data = [[cost,max_num],...]
    data.append(b)
# print(data)

# N=2 
# M=5
# data = [[4, 9], [2, 4]]
# data.sort()
# npsorted = np.sort(np.array(data),axis=0)
data.sort()

num_drink=0
cost=0
shop_index=0
while (shop_index < N and num_drink < M):
    num_drink += data[shop_index][1]
    cost += data[shop_index][0]*data[shop_index][1]
    shop_index += 1

# num_drink >= M by buying data[shop_index-1][0]yen drink from shop_index
excess = num_drink - M
ans = cost - data[shop_index-1][0] * excess
print(ans)
# print(data)
Buggy code:
from collections import OrderedDict
if __name__ == "__main__":
    NM = list(map(int, input().split()))
    n = NM[0]
    m = NM[1]
    mydict = {}
    for i in range(n):
        money_can = list(map(int, input().split()))
        money = money_can[0]
        can = money_can[1]
        if(money not in mydict.keys()):
            mydict[money] = []
        mydict[money].append(can)
    buynow = 0
    moneynow = 0

    mydict = OrderedDict(sorted(mydict.items()))
    for i in mydict.keys():
        if(buynow >= m):
            break
        for canNO in mydcit[i]:
            if(buynow >= m):
                break
            if(can + buynow <= m):
                moneynow += can*i
                buynow += can
            else:
                need = m - buynow
                moneynow += need*i
                buynow += need
        else:
            continue
    print(moneynow)

    

Fixed code:
from collections import OrderedDict
if __name__ == "__main__":
    NM = list(map(int, input().split()))
    n = NM[0]
    m = NM[1]
    mydict = {}
    for i in range(n):
        money_can = list(map(int, input().split()))
        money = money_can[0]
        can = money_can[1]
        if(money not in mydict.keys()):
            mydict[money] = []
        mydict[money].append(can)
    buynow = 0
    moneynow = 0

    mydict = OrderedDict(sorted(mydict.items()))
    for i in mydict.keys():
        if(buynow >= m):
            break
        for canNO in mydict[i]:
            if(buynow >= m):
                break
            if(canNO + buynow < m):
                moneynow += canNO*i
                buynow += canNO
            else:
                need = m - buynow
                moneynow += need*i
                buynow += need
        else:
            continue
    print(moneynow)
Buggy code:
N, M = list(map(int, input().split()))

# Insert all the data into dictionary
stores = []
for _ in range(N):
  a, b = list(map(int, input().split()))
  stores.append([a,b])

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

m = 0
money = 0

for store in stores:
  money += min(store[1], M - m) * store[0]
  m += min(store[1], M - m)
  if m == M:
    break
print(money)

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

# Insert all the data into dictionary
stores = []
for _ in range(N):
  a, b = list(map(int, input().split()))
  stores.append([a,b])

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

m = 0
money = 0

for store in stores:
  money += min(store[1], M - m) * store[0]
  m += min(store[1], M - m)
  if m == M:
    break
print(money)
Buggy code:
print(AB)

N, M = [int(x) for x in input().split()]
AB = [[int(x) for x in input().split()] for _ in range(N)]
AB.sort(key=lambda x: x[0])

s = 0
for ab in AB:
    if ab[1] > M:
        s += M*ab[0]
        break
    else:
        s += ab[0]*ab[1]
        M -= ab[1]

print(s)


Fixed code:
N, M = [int(x) for x in input().split()]
AB = [[int(x) for x in input().split()] for _ in range(N)]
AB.sort(key=lambda x: x[0])

s = 0
for ab in AB:
    if ab[1] > M:
        s += M*ab[0]
        break
    else:
        s += ab[0]*ab[1]
        M -= ab[1]

print(s)
Buggy code:
from functools import reduce
N, M = map(int,input().split())
ary1 =[]
for x in range(N):
  ary1.append(list(map(int,input().split())))

ary2 = sorted(ary1)
print(ary2)
count = 0
total_sum = 0
for i in range(N):
  if count + ary2[i][1] <= M:
    total_sum += ary2[i][0] * ary2[i][1]
    count += ary2[i][1]
  elif count > M :
    break
  else:
    zan = M - count
    total_sum += ary2[i][0] * zan
    count += zan

print(total_sum)


Fixed code:
from functools import reduce
N, M = map(int,input().split())
ary1 =[]
for x in range(N):
  ary1.append(list(map(int,input().split())))

ary2 = sorted(ary1)
count = 0
total_sum = 0
for i in range(N):
  if count + ary2[i][1] <= M:
    total_sum += ary2[i][0] * ary2[i][1]
    count += ary2[i][1]
  elif count > M :
    break
  else:
    zan = M - count
    total_sum += ary2[i][0] * zan
    count += zan

print(total_sum)
Buggy code:
N_ken, M_hon = map(int, input().split())
ab = []
yen = 0
hon = 0

for i in range(N_ken):
    tmp = list(map(int, input().split()))
    ab.append(tmp)

ab.sort()

for a, b in ab:
    tmp = min(M_hon - hon, b)
    yen += tmp * a
    hon += b
    
    
    if (hon == M_hon):
        break

print(yen)

Fixed code:
N_ken, M_hon = map(int, input().split())
ab = []
yen = 0
hon = 0

for i in range(N_ken):
    tmp = list(map(int, input().split()))
    ab.append(tmp)

ab.sort()

for a, b in ab:
    tmp = min(M_hon - hon, b)
    yen += tmp * a
    hon += tmp
    
    if (hon == M_hon):
        break

print(yen)
Buggy code:
N,M = map(int,input().split())
Shop_List = [list(map(int,input().split())) for i in range(N)]
Shop_List = sorted(Shop_List, key=lambda x:x[0])
Number_Counter = 0
Yen_Counter = 0
for i in range(N):
    if Number_Counter + Shop_List[i][1] <= M:
        Number_Counter += Shop_List[i][1]
        Yen_Counter = Shop_List[i][0]*Shop_List[i][1]
    elif Number_Counter + Shop_List[i][1] > M:
        Yen_Counter += (M-Number_Counter)*Shop_List[i][0]
        Number_Counter = M
    elif Number_Counter == M:
        break

print(Yen_Counter)


Fixed code:
N,M = map(int,input().split())
Shop_List = [list(map(int,input().split())) for i in range(N)]
Shop_List = sorted(Shop_List, key=lambda x:x[0])
Number_Counter = 0
Yen_Counter = 0
for i in range(N):
    if Number_Counter + Shop_List[i][1] <= M:
        Number_Counter += Shop_List[i][1]
        Yen_Counter += Shop_List[i][0]*Shop_List[i][1]
    elif Number_Counter + Shop_List[i][1] > M:
        Yen_Counter += (M-Number_Counter)*Shop_List[i][0]
        Number_Counter = M
    elif Number_Counter == M:
        break

print(Yen_Counter)
Buggy code:
N,M = map(int,input().split())
AB = []
for _ in range(N):
    AB.append([int(i) for i in input().split()])
AB_sort = sorted(AB,key=lambda x : x[0])
money = 0
for ab in AB_sort:
    if M >= ab[0]:
        money += ab[0] * ab[1]
        M -= ab[1]
    else:
        money += M * ab[1]
        break
print(money)

Fixed code:
N,M = map(int,input().split())
AB = []
for _ in range(N):
    AB.append([int(i) for i in input().split()])
AB_sort = sorted(AB,key=lambda x : x[0])
money = 0
for ab in AB_sort:
    if M >= ab[1]:
        money += ab[0] * ab[1]
        M -= ab[1]
    else:
        money += M * ab[0]
        break
print(money)
Buggy code:
N, M = map(int, input().split())
S = []
for i in range(N):
  a, b = map(int, input().split())
  S.append([a, b])

S.sort(key=lambda x: x[0])
price = 0
count = 0
for s in S:
  if count + s[1] < M:
    price += s[0] * s[1]
    count += s[1]
  else:
    price += s[0] * (M - s[1])
    break

print(price)

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

S.sort(key=lambda x: x[0])
price = 0
count = 0
for s in S:
  if count + s[1] < M:
    price += s[0] * s[1]
    count += s[1]
  else:
    price += s[0] * (M - count)
    break

print(price)
Buggy code:
n,m=map(int,input().split())
a=[list(map(int,input().split())) for i in range(n)]
a.sort()
dr=0
i=0
pr=0
while(dr<m):
  if dr+a[i][1]>=m:
    dr+=m-dr
    pr+=(m-dr)*a[i][0]
  else:
    dr+=a[i][1]
    pr+=a[i][0]*a[i][1]
  i+=1
print(pr)

Fixed code:
n,m=map(int,input().split())
a=[list(map(int,input().split())) for i in range(n)]
a.sort()
dr=0
i=0
pr=0
while(dr<m):
  if dr+a[i][1]>=m:
    pr+=(m-dr)*a[i][0]
    dr+=m-dr
  else:
    dr+=a[i][1]
    pr+=a[i][0]*a[i][1]
  i+=1
print(pr)
Buggy code:
N, M = map(int, input().split())
AB = [list(map(int, input().split())) for i in range(N)]
AB.sort(key = lambda x: x[0])

total = 0
i = 0

while True:
    total += AB[i][1]
    if total < m:
        i += 1
    else:
        break

ans = 0
for j in range(i):
    ans += AB[j][0]*AB[j][1]
ans += (m - sum(AB[p][1] for p in range(0,i))) * AB[i][0]

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

total = 0
i = 0

while True:
    total += AB[i][1]
    if total < M:
        i += 1
    else:
        break

ans = 0
for j in range(i):
    ans += AB[j][0]*AB[j][1]
ans += (M - sum(AB[p][1] for p in range(0,i))) * AB[i][0]
print(ans)
Buggy code:
n,m = map(int,input().split())
AB = [list(map(int,input().split())) for _ in range(n)]


from operator import itemgetter
def main():
    AB.sort(key = itemgetter(0))
    cnt = 0
    ans = 0
    for a,b in AB:
        if b + cnt < m:
            cnt += b 
            ans += b*a
        else:
            ans += (m - cnt)*a
    print(ans)
    return



if __name__ == "__main__":
    main()

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


from operator import itemgetter
def main():
    AB.sort(key = itemgetter(0))
    cnt = 0
    ans = 0
    for a,b in AB:
        if b + cnt < m:
            cnt += b 
            ans += b*a
        else:
            ans += (m - cnt)*a
            print(ans)
            return



if __name__ == "__main__":
    main()
Buggy code:
N, M= map(int, input().split())
A = []
for i in range(N):
    a = list(map(int, input().split()))
    A.append(a)
A = sorted(A)
count = 0
cost = 0
i = 0
while count < M:
    cost += A[i][0] * min(A[i][1],M-count)
    count += min(A[i][1],M-count)
        
print(cost)

Fixed code:
N, M= map(int, input().split())
A = []
for i in range(N):
    a = list(map(int, input().split()))
    A.append(a)
A = sorted(A)
count = 0
cost = 0
i = 0
while count < M:
    cost += A[i][0] * min(A[i][1],M-count)
    count += min(A[i][1],M-count)
    i += 1    
print(cost)
Buggy code:
N, M = map(int, input().split())
A = []
B = []
for _ in range(N):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)
C = zip(A,B)
C = sorted(C)
A, B = zip(*C)
index = 0
count = 0

for i in range(N):
      if(count<=M):
        index = i
        sum += A[i]*B[i]
        count += B[i]
sum +=A[index]*(M-count)
print(sum)

Fixed code:
N, M = map(int, input().split())
A = []
B = []
for _ in range(N):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)
C = zip(A,B)
C = sorted(C)
A, B = zip(*C)
index = 0
count = 0
sum = 0
for i in range(N):
      if(count<=M):
        index = i
        sum += A[i]*B[i]
        count += B[i]
sum +=A[index]*(M-count)
print(sum)
Buggy code:
var = list(map(int, input().split()))
N = var[0]
M = var[1]

A = [0] * N
B = [0] * N
for i in range(N):
    A[i], B[i] = map(int, input().split())
C = zip(A,B)
C = sorted(C)
A, B = zip(*C)

index = 0
count = 0
for i in range(N):
      if(count<=M):
        index = i
      count += B[0]
count = 0
sum = 0
for i in range (index):
    sum+=A[i]*B[i]
    count+=B[i]
sum +=A[index]*(M-count)
print(sum)

Fixed code:
var = list(map(int, input().split()))
N = var[0]
M = var[1]
 
A = [0] * N
B = [0] * N
for i in range(N):
    A[i], B[i] = map(int, input().split())
C = zip(A,B)
C = sorted(C)
A, B = zip(*C)
 
index = 0
count = 0
for i in range(N):
      if(count<=M):
        index = i
      count += B[i]
count = 0
sum = 0
for i in range (index):
    sum+=A[i]*B[i]
    count+=B[i]
sum +=A[index]*(M-count)
print(sum)
Buggy code:
N,M = (int(i) for i in input().split())
dic = {}
drink = M
money = 0
for i in range(N):
  a,b = (int(i) for i in input().split())
  dic[a] += b
c = sorted(dic.keys())
print(c)
for j in c:
  if drink > dic[j]:
    money += j * dic[j]
    drink -= dic[j]
  else:
    money += j * drink
    break
print(money)

Fixed code:
N,M = (int(i) for i in input().split())
dic = {}
drink = M
money = 0
for i in range(N):
  a,b = (int(i) for i in input().split())
  if a not in dic:
    dic[a] = b
  else:
    dic[a] += b
c = sorted(dic.keys())
for j in c:
  if drink > dic[j]:
    money += j * dic[j]
    drink -= dic[j]
  else:
    money += j * drink
    break
print(money)
Buggy code:
N,M = map(int,input().split())
A = [0] * N
B = [0] * N
C = [[0,0] for i in range(N)]
check = 0
money = 0
a = 0
k = 0

for i in range(N):

    A[i],B[i] = map(int,input().split())
    C[i] = [A[i],B[i]]

C.sort()

while a == 0:

    if check + C[k][1] <= M:

        check += C[k][1]
        money += C[k][0]*C[k][1]
        k += 1

    else:

        money += C[k][0] * (M-check)
        a += 1

print(money)



Fixed code:
N,M = map(int,input().split())
A = [0] * N
B = [0] * N
C = [[0,0] for i in range(N)]
check = 0
money = 0
a = 0
k = 0

for i in range(N):

    A[i],B[i] = map(int,input().split())
    C[i] = [A[i],B[i]]

C.sort()

while a == 0:

    if check + C[k][1] < M:

        check += C[k][1]
        money += C[k][0]*C[k][1]
        k += 1

        
    else:

        money += C[k][0] * (M-check)
        a += 1

print(money)
Buggy code:
# 2150 start

import numpy

N,M=map(int, input().split())
price = numpy.empty((N,3))
sumcan = 0
sumprice = 0
lastshop = 0

for i in range(N):
    shop_data = input().split()
    A = int(shop_data[0])
    B = int(shop_data[1])
    price[i,0]= A * B
    price[i,1] = A
    price[i,2] = B

price = price[price[:,1].argsort(),:]

for j in range(M):
    sumcan = sumcan + price[j,2]
    if sumcan < M:
        sumprice = sumprice + price[j,0]
    elif sumcan >= M:
        sumcan = sumcan - price[j,2]
        lastshop = j
        break

sumprice = sumprice + (M - sumcan)*price[lastshop,1]

print(sumprice)









Fixed code:
# 2150 start

import numpy

N,M=map(int, input().split())
price = numpy.empty((N,3))
sumcan = 0
sumprice = 0
lastshop = 0

for i in range(N):
    shop_data = input().split()
    A = int(shop_data[0])
    B = int(shop_data[1])
    price[i,0]= A * B
    price[i,1] = A
    price[i,2] = B

price = price[price[:,1].argsort(),:]

for j in range(M):
    sumcan = sumcan + price[j,2]
    if sumcan < M:
        sumprice = sumprice + price[j,0]
    elif sumcan >= M:
        sumcan = sumcan - price[j,2]
        lastshop = j
        break

sumprice = sumprice + (M - sumcan)*price[lastshop,1]

print(int(sumprice))