qyliang/CodeNanoFix huggingface dataset:
Buggy code:
N,m = map(int,input().split())
A = []
B = []
for i in range(N):
    a,b = map(int,input().split())
    A.append([a,b])

A = sorted(A)
print(A)
money = 0
for n in range(N):
    if m > A[n][1]:
        m -= A[n][1]
        money += A[n][1] * A[n][0]
    elif m <= A[n][1]:
        money += m * A[n][0]
        break

print(money)


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

A = sorted(A)
money = 0
for n in range(N):
    if m > A[n][1]:
        m -= A[n][1]
        money += A[n][1] * A[n][0]
    elif m <= A[n][1]:
        money += m * A[n][0]
        break

print(money)
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])

ans = 0
cnt = 0
for a, b in AB:
  if cnt+b <= M:
    cnt += b
    ans += a*b
    continue
  ans += a * (M - cnt)
print(ans)  
    
  

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])

ans = 0
cnt = 0
for a, b in AB:
  if cnt+b <= M:
    cnt += b
    ans += a*b
    continue
  ans += a * (M - cnt)
  break
print(ans)
Buggy code:
n,m = map(int,input().split())
ab = []
for i in range(n):
	ab.append(list(map(int,input().split())))
    
sab = sorted(ab,key=lambda x:x[0])
cost = 0
for i in sab:
	if m - i[1] > 0:
		m -= i[1]
		cost += i[0] * i[1]
	else:
		for j in range(m):
			cost += i[0]
print(cost)

Fixed code:
n,m = map(int,input().split())
ab = []
for i in range(n):
	ab.append(list(map(int,input().split())))
    
sab = sorted(ab,key=lambda x:x[0])
cost = 0
for i in sab:
	if m - i[1] > 0:
		m -= i[1]
		cost += i[0] * i[1]
	else:
		for j in range(m):
			cost += i[0]
		break
print(cost)
Buggy code:
N, M = map(int, input().split())
AB = []
p = 0

for n in range(N):
  AB.append(list(map(int, input().split())))
  print(AB)
  AB.sort()
  for s, b in AB:
    print('M',M)
    p += s * min(M, b)
    M -= min(M, b)
print(p)

Fixed code:
N, M = map(int, input().split())
AB = []
p = 0
for n in range(N):
    AB.append(list(map(int, input().split())))
AB.sort()
for s, b in AB:
    p += s * min(M, b)
    M -= min(M, b)
print(p)
Buggy code:
N, M = map(int, input().split())

AB = []
for i in range(N):
    AB.append(list(map(int, input().split())))
AB.sort(key=lambda x: x[0])
count = 0
ans = 0
for ab in AB:
    if M > count+ab[1]:
        count += ab[1]
        ans += ab[0]*ab[1]
        print(count, ans)
    else:
        ans += ab[0] * (M-count)
        print(count, ans)
        break
print(ans)

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

AB = []
for i in range(N):
    AB.append(list(map(int, input().split())))
AB.sort(key=lambda x: x[0])
count = 0
ans = 0
for ab in AB:
    if M > count+ab[1]:
        count += ab[1]
        ans += ab[0]*ab[1]
    else:
        ans += ab[0] * (M-count)
        break
print(ans)
Buggy code:
n, m = [int(i) for i in input().split()]
dat = [[int(i) for i in input().split()] for i in range(n)]
sort(dat)
sum = 0
_m = 0
for i in dat:
    _m += dat[1]
    if _m > m:
        print(sum + dat[0]*(m - _m))
        break
    sum += dat[0] * dat[1]


Fixed code:
n, m = [int(i) for i in input().split()]
dat = [[int(i) for i in input().split()] for i in range(n)]
dat.sort()
sum = 0
_m = 0
for i in dat:
    if _m + i[1] >= m:
        print(sum + i[0]*(m - _m))
        break
    _m += i[1]
    sum += i[0] * i[1]
Buggy code:
n,m=map(int,input().split())
a=[]
for i in range(n):
  a.append(list(map(int,input().split())))
a.sort()  
i=0
cost=0
while m>0:
  if a[i][1]<m:
    cost+=a[i][0]*a[i][1]
    M-=a[i][1]
    i+=1
  else:
    cost+=a[i][0]*m
    print(cost)
    break

Fixed code:
n,m=map(int,input().split())
a=[]
for i in range(n):
  a.append(list(map(int,input().split())))
a.sort()  
i=0
cost=0
while m>0:
  if a[i][1]<m:
    cost+=a[i][0]*a[i][1]
    m-=a[i][1]
    i+=1
  else:
    cost+=a[i][0]*m
    break
print(cost)
Buggy code:
    def get_input_row():
      return [int(i) for i in input().split(" ")]
     
    inp = get_input_row()
    N = inp[0]
    M = inp[1]
    item_dict = {}
    num = 0
    for i in range(N):
      a, b = get_input_row()
      if a in item_dict:
        item_dict[a] += b
      else:
      	item_dict[a] = b
    sorted_list = [k for k in item_dict.keys()]
    sorted_list.sort()
    money = 0
    for price in sorted_list:
      if M > item_dict[price]:
        M -= item_dict[price]
        money += price * item_dict[price]
      else:
        money += price * M
        break
    print(money)

Fixed code:
def get_input_row():
  return [int(i) for i in input().split(" ")]
     
inp = get_input_row()
N = inp[0]
M = inp[1]
item_dict = {}
num = 0
for i in range(N):
  a, b = get_input_row()
  if a in item_dict:
    item_dict[a] += b
  else:
    item_dict[a] = b

sorted_list = [k for k in item_dict.keys()]
sorted_list.sort()
money = 0
for price in sorted_list:
  if M > item_dict[price]:
    M -= item_dict[price]
    money += price * item_dict[price]
  else:
    money += price * M
    break
print(money)
Buggy code:
N,M = map(int,input().split())
ab = []
for n in range(N):
    a,b = map(int,input().split())
    ab.append((a,b))
ab.sort()
coin = 0
cnt = 0
for n in range(N):
    cnt += ab[n][1]
    if cnt >= M:
        coin += (cnt - M) * ab[n][0]
        print(coin)
        break
    coin += ab[n][1] * ab[n][0]

Fixed code:
N,M = map(int,input().split())
ab = []
for n in range(N):
    a,b = map(int,input().split())
    ab.append((a,b))
ab.sort()
coin = 0
cnt = 0
for n in range(N):
    cnt += ab[n][1]
    coin += ab[n][1] * ab[n][0]
    if cnt >= M:
        coin -= (cnt - M) * ab[n][0]
        print(coin)
        exit()
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()
print(AB)
cnt = ans = 0
for i in range(N):
  buy = AB[i][1]
  if cnt + AB[i][1] >= M:
    buy = M - cnt
  cnt += buy
  ans += buy * AB[i][0]
  print(buy,cnt,ans)
  if cnt >= M:
    break
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()
#print(AB)
cnt = ans = 0
for i in range(N):
  buy = AB[i][1]
  if cnt + AB[i][1] >= M:
    buy = M - cnt
  cnt += buy
  ans += buy * AB[i][0]
#  print(buy,cnt,ans)
  if cnt >= M:
    break
print(ans)
Buggy code:
import sys

N, M = map(int, input().split())
lst = []
for i in range(N):
    lst += [list(map(int, input().split()))]
lst.sort()    
print (lst)
count = M
yen = 0

for i in range(N):
    yen += lst[i][0] * min(count, lst[i][1])  
    count -= min(count, lst[i][1])
#    print (count)
    if count <= 0:
        print (yen)
        sys.exit()

Fixed code:
import sys

N, M = map(int, input().split())
lst = []
for i in range(N):
    lst += [list(map(int, input().split()))]
lst.sort()    
#print (lst)
count = M
yen = 0

for i in range(N):
    yen += lst[i][0] * min(count, lst[i][1])  
    count -= min(count, lst[i][1])
#    print (count)
    if count <= 0:
        print (yen)
        sys.exit()
Buggy code:
N,M = map(int,input().split())
a = []

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

a.sort()

num = 0
ans = 0
for i in range(N):
  ans = 0
  num = 0
  while i <= N - 1:
    ans += a[i][0] * a[i][1]
    num += a[i][1]
    if num > M:
        ans -= a[i][0] * (num - M)
        break
print(ans)  


Fixed code:
N,M = map(int,input().split())
a = []

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

a = sorted(a)

i = 0
num = 0
ans = 0
while i <= N - 1:
  ans += a[i][0] * a[i][1]
  num += a[i][1]
  if num > M:
    ans -= a[i][0] * (num - M)
    break
  i += 1
print(ans)
Buggy code:
N, M = map(int, input().split())
A = []
for i in range(N):
	A.append(list(map(int, input().split())))
A.sort()
count = 0
nedan = 0
for s in range(N):
	count += A[s][1]
	if(count < M):
		nedan += A[s][0]*A[s][1]
	elif(count > M):
		nedan += A[s][0]*A[s][1]
		nedan -= A[s][0]*(count - M)
		print(nedan)
		exit()

Fixed code:
N, M = map(int, input().split())
A = []
for i in range(N):
	A.append(list(map(int, input().split())))
A.sort()
count = 0
nedan = 0
for s in range(N):
	count += A[s][1]
	if(count < M):
		nedan += A[s][0]*A[s][1]
	elif(count >= M):
		nedan += A[s][0]*A[s][1]
		nedan -= A[s][0]*(count - M)
		print(nedan)
		exit()
Buggy code:
from itertools import accumulate

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

sB = [sAB[i][1] for i in range(N)]
cum_num = list(accumulate(sB))

num = 0
ans = 0
index_ = -1
for a, b in sAB:
    index_ += 1
    num += b
    if num >= M:
        break
    ans += a*b

ans += sAB[index_][0]*(M-cum_num[index_-1])

print(ans)





Fixed code:
from itertools import accumulate

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

sB = [sAB[i][1] for i in range(N)]
cum_num = list(accumulate(sB))

num = 0
ans = 0
index_ = -1
for a, b in sAB:
    index_ += 1
    num += b
    if num >= M:
        break
    ans += a*b

if index_ == 0:
    ans += sAB[0][0]*M
else:
    ans += sAB[index_][0]*(M-cum_num[index_-1])

print(ans)
Buggy code:
N,M = map(int, input().split())
A = []
quantity = 0
price = 0

for i in range(N):
    a = list(map(int, input().split()))
    A.append(a)
print(A)
A = sorted(A)
for i in range(M):
    quantity += A[i][1]
    if quantity <= M:
        price += A[i][0]*A[i][1]
    else:
       price += A[i][0]*(M-(quantity-A[i][1]))
       break
print(price)

Fixed code:
N,M = map(int, input().split())
A = []
quantity = 0
price = 0

for i in range(N):
    a = list(map(int, input().split()))
    A.append(a)
A = sorted(A)
for i in range(M):
    quantity += A[i][1]
    if quantity < M:
        price += A[i][0]*A[i][1]
    else:
       price += A[i][0]*(M-(quantity-A[i][1]))
       break
print(price)
Buggy code:
N, M = map(int, input())
X = [list(map(int, input().split())) for _ in range(N)]

ans = 0
res = M
for v in X:
    ans += v[0] * min(v[1], res)
    res -= v[1]
    if res <= 0:
        break
        
print(res)

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

ans = 0
res = M
for v in X:
    ans += v[0] * min(v[1], res)
    res -= v[1]
    if res <= 0:
        break
        
print(ans)
Buggy code:
#! /usr/bin/env python3
# -*- coding: utf-8 -*-
N,M = [int(x) for x in input().split()]
ABdict = {}
for _ in range (N):
    A,B = [int(x) for x in input().split()]
    if A in ABdict.keys():
        ABdict[A] += B
    else:
        ABdict[A] = B

print(ABdict)
dct = sorted(ABdict.items())
ls = []
ans = 0
for i in dct:
    if M >= 0:
        ans += min(M,i[1])*i[0]    
        M -= i[1]  

print(ans)


Fixed code:
#! /usr/bin/env python3
# -*- coding: utf-8 -*-
N,M = [int(x) for x in input().split()]
ABdict = {}
for _ in range (N):
    A,B = [int(x) for x in input().split()]
    if A in ABdict.keys():
        ABdict[A] += B
    else:
        ABdict[A] = B

dct = sorted(ABdict.items())
ls = []
ans = 0
for i in dct:
    if M >= 0:
        ans += min(M,i[1])*i[0]    
        M -= i[1]  

print(ans)
Buggy code:
# coding: UTF-8
import sys
#sys.setrecursionlimit(n)
import heapq
import re
import bisect
import random
import math
import itertools
from collections import defaultdict, deque
from copy import deepcopy
from decimal import *

a, b = map(int, input().split())
d = defaultdict(int)
array = []
for i in range(a):
    x, y = map(int, input().split())
    d[x] = y
    array.append(x)
array.sort()


count = 0
for i in array:
        break
    if b <= d[i]:
        count += min(b, 0) * i
        break
    else:
        t = d[i]
        b -= t
        count += t * i
print(count)

Fixed code:
# coding: UTF-8
import sys
#sys.setrecursionlimit(n)
import heapq
import re
import bisect
import random
import math
import itertools
from collections import defaultdict, deque
from copy import deepcopy
from decimal import *

a, b = map(int, input().split())
d = []
for i in range(a):
    x, y = map(int, input().split())
    d.append((x, y))
d.sort()
count = 0
for i in range(a):
    if b <= d[i][1]:
        count += b * d[i][0]
        break
    else:
        b -= d[i][1]
        count += d[i][0] * d[i][1]
print(count)
Buggy code:
# coding: utf-8
# Your code here!

N,M = map(int,input().split())
A = []

ans = 0
for _ in range(N):
    A.append(list(map(int,input().split())))

A = sorted(A, key=lambda x: x[0])
print(A)
for a in A:
    if a[1] >= M:
        ans += a[0]*M
        break
    else:
        ans += a[0]*a[1]
        M -= a[1]
        
print(ans)

Fixed code:
# coding: utf-8
# Your code here!

N,M = map(int,input().split())
A = []

ans = 0
for _ in range(N):
    A.append(list(map(int,input().split())))

A = sorted(A, key=lambda x: x[0])
# print(A)
for a in A:
    if a[1] >= M:
        ans += a[0]*M
        break
    else:
        ans += a[0]*a[1]
        M -= a[1]
        
print(ans)
Buggy code:
n,m=map(int, input().split())
l=[]
for i in range(n):
	a=list(map(int, input().split()))
	l.append(a)
l=sorted(l)


p=0
v=m
for i in range(n):
	if l[i][1]<=v:
		p+=l[i][0]*l[i][1]
		v=v-l[i][1]
	else:
		p+=v*l[i][0]
		print(p)
		exit()
	

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


p=0
v=m
for i in range(n):
	if l[i][1]<=v:
		p+=l[i][0]*l[i][1]
		v=v-l[i][1]
		if v==0:
			print(p)
			exit()
	else:
		p+=v*l[i][0]
		print(p)
		exit()
Buggy code:
n,m = map(int,input().split())
d = []
for i in range(n):
    a,b = map(int,input().split())
    d.append([a,b])
 
d.sort(key=lambda x:x[0])

sum_ = 0
cnt = 0
for ab in d:
    if cnt + ab[1] > M:
        sum_ += ab[0] * (M-cnt)
        break
    else:
        cnt += ab[1]
        sum_ += ab[0]*ab[1]
print(sum_)


Fixed code:
n,M = map(int,input().split())
d = []
for i in range(n):
    a,b = map(int,input().split())
    d.append([a,b])
 
d.sort(key=lambda x:x[0])

sum_ = 0
cnt = 0
for ab in d:
    if cnt + ab[1] > M:
        sum_ += ab[0] * (M-cnt)
        break
    else:
        cnt += ab[1]
        sum_ += ab[0]*ab[1]
print(sum_)
Buggy code:
N,M=map(int,input().split())
A=[[]]
for i in range(N):
    A.append(list(map(int,input().split())))
A.sort(key=lambda x:(x[0],x[1]))
C=[A[0][0]*A[0][1]]
D=A[0][1]
for i in range(N-1):
    C.append(C[i]+A[i+1][0]*A[i+1][1])
    D.append(D[i]+A[i+1][1])
for i in range(N):
    if M<D[i]:
        print(C[i]-(D[i]-M)*A[i][0])

Fixed code:
N,M=map(int,input().split())
A=[]
for i in range(N):
    A.append(list(map(int,input().split())))
A.sort(key=lambda x:(x[0],x[1]))
C=[A[0][0]*A[0][1]]
D=[A[0][1]]
for i in range(N-1):
    C.append(C[i]+A[i+1][0]*A[i+1][1])
    D.append(D[i]+A[i+1][1])
for i in range(N):
    if M<D[i]:
        print(C[i]-(D[i]-M)*A[i][0])
        break
if M==D[N-1]:
    print(C[N-1])
Buggy code:
import numpy as np

N,M = map(int,input().split())
A = []
for i in range(N):
    A.append([int(x) for x in input().split()])

AB = np.array(A)

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

yen = 0
cnt = 0
i = 0
while(1):
    cnt_ = cnt + AB[i,1]
    if(cnt_ >= M):
        yen += (M - cnt)*AB[i,0]
        break
    yen += AB[i,0]*AB[i,1]
    print(cnt_,yen)
    cnt = cnt_
    i += 1


print(yen)

Fixed code:
import numpy as np

N,M = map(int,input().split())
A = []
for i in range(N):
    A.append([int(x) for x in input().split()])

AB = np.array(A)

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

yen = 0
cnt = 0
i = 0
while(1):
    cnt_ = cnt + AB[i,1]
    if(cnt_ >= M):
        yen += (M - cnt)*AB[i,0]
        break
    yen += AB[i,0]*AB[i,1]
    cnt = cnt_
    i += 1


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

sortAB = sorted(AB)

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

print(ans)

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

sortAB = sorted(AB)

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

print(ans)
Buggy code:
n,m=map(int,input().split())

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

print(a)
pay=0
i=0
while m>0:
    p=min(m,a[i][1])
    m-=p
    pay+=p*a[i][0]
    i+=1
print(pay)




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

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

#print(a)
pay=0
i=0
while m>0:
    p=min(m,a[i][1])
    m-=p
    pay+=p*a[i][0]
    i+=1
print(pay)
Buggy code:
n,m=map(int,input().split())
AB=[]
for i in range(n):
    a,b=map(int,input().split())
    AB.append((b,a))

AB.sort()

cnt=0
ans=0
for b,a in AB:
    if cnt==k:
        print(ans)
        break
    temp=min(k-cnt,a)
    ans+=b*temp
    cnt+=temp

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

AB.sort()

cnt=0
ans=0
for a,b in AB:

    temp=min(m-cnt,b)
    ans+=a*temp
    cnt+=temp
    if cnt==m:
        print(ans)
        break
Buggy code:
n,m=map(int,input().split())
array=[]
cost=0
for i in range(n):
    a,b=map(int,input().split())
    array.append([a,b])
array.sort()
for i in array:
    if m<i[1]:
        cost+=i[0]*m
    else:
        cost+=i[0]*i[1]
        m-=i[1]
        
print(cost)

Fixed code:
n,m=map(int,input().split())
array=[]
cost=0
for i in range(n):
    a,b=map(int,input().split())
    array.append([a,b])
array.sort()
for i in array:
    if m<=i[1]:
        cost+=i[0]*m
        break
    else:
        cost+=i[0]*i[1]
        m-=i[1]
        
print(cost)
Buggy code:
from operator import itemgetter
N, M = map(int, input().split())
AB = sorted([list(map(int, input().split())) for i in range(N)], key=itemgetter(0))
ans, tmp = 0, 0
print(AB)
for ab in AB:
    if ab[1] + tmp < M:
        tmp += ab[1]
        ans += ab[0] * ab[1]
        print(tmp, ans)
    else:
        ans += (M - tmp) * ab[0]
        break
print(ans)

Fixed code:
from operator import itemgetter
N, M = map(int, input().split())
AB = sorted([list(map(int, input().split())) for i in range(N)], key=itemgetter(0))
ans, tmp = 0, 0
for ab in AB:
    if ab[1] + tmp < M:
        tmp += ab[1]
        ans += ab[0] * ab[1]
    else:
        ans += (M - tmp) * ab[0]
        break
print(ans)
Buggy code:
n,m = map(int,input().split())
l = [map(int, input().split()) for i in range(n)]
ans = 0
for a,b in l:
  if b >= m:
    ans += a * (b-m)
    break
  else:
    ans += a*b
    m -= b
print(ans)

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

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

cnt = 0
price = 0
i = 0
while cnt < m:
    price += ab[i][0] * ab[i][1]
    cnt += ab[i][1]
    if cnt > m:
        price -= ab[i][0] * (m - cnt)
        break
    i += 1

print(price)

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

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

cnt = 0
price = 0
i = 0
while cnt < m:
    price += ab[i][0] * ab[i][1]
    cnt += ab[i][1]
    if cnt > m:
        price -= ab[i][0] * (cnt - m)
        break
    i += 1

print(price)
Buggy code:
from sys import exit

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

shops = {}

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

shops = sorted(shops.items())
print(shops)
ans = 0

for k in shops:
    if M - k[1] <= 0:
        ans += k[0] * M
        print(ans)
        exit()
    else:
        ans += k[0] * k[1]
        M -= k[1]


Fixed code:
from sys import exit

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

shops = {}

for _ in range(N):
    A, B = map(int, input().split())
    if A in shops.keys():
        shops[A] += B
    else:
        shops[A] = B

shops = sorted(shops.items())
ans = 0

for k in shops:
    if M - k[1] <= 0:
        ans += k[0] * M
        break
    else:
        ans += k[0] * k[1]
        M -= k[1]

print(ans)
Buggy code:
n,m=map(int,input().split())
l=[]
for i in range(n):
  a,s=map(int,input().split())
  l.append([a,s])
l=sorted(l)
p=0
c=0
for i in l:
  if c+l[i][1]>m:
    p+=l[i][0]*(m-c)
    break
  else:
    p+=l[i][0]*l[i][1]
    c+=l[i][1]
print(p)

Fixed code:
n,m=map(int,input().split())
l=[]
for i in range(n):
  a,s=map(int,input().split())
  l.append([a,s])
l=sorted(l)
p=0
c=0
for i in range(len(l)):
  if c+l[i][1]>m:
    p+=l[i][0]*(m-c)
    break
  else:
    p+=l[i][0]*l[i][1]
    c+=l[i][1]
print(p)
Buggy code:
# coding: utf-8
import sys
import itertools


def sr(): return sys.stdin.readline().rstrip()


def ir(): return int(sr())


def lr(): return list(map(int, sr().split()))


N, M = lr()
d_list = []
for i in range(N):
    a, b = lr()
    d_list.append([a, b, i])

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

cnt = 0
ans = 0
for d in d_list:
    if (M - cnt) > d[1]:
        cnt += d[1]
        ans += d[1] * d[0]
    elif (M - cnt) > 0:
        ans += (M - cnt) * d[0]
    else:
        break

print(ans)


Fixed code:
# coding: utf-8
import sys
import itertools


def sr(): return sys.stdin.readline().rstrip()


def ir(): return int(sr())


def lr(): return list(map(int, sr().split()))


N, M = lr()
d_list = []
for i in range(N):
    a, b = lr()
    d_list.append([a, b, i])

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

cnt = 0
ans = 0
for d in d_list:
    if (M - cnt) > d[1]:
        ans += d[1] * d[0]
        cnt += d[1]
    elif (M - cnt) > 0:
        ans += (M - cnt) * d[0]
        cnt += (M - cnt)
    else:
        break

print(ans)
Buggy code:
n,m=map(int,input().split())
ab=[list(map(int,input().split())) for i in range(n)]
ab.sort()
t=[[0]*2 for i in range(n)]
for i in range(n):
  t[i]=[t[i-1][0]+ab[i][0]*ab[i][1],t[i-1][1]+ab[i][1]]
  if t[i][1]>m:
    t[i][0]-=ab[i][0]*(t[i][1]-m)
    print(t[i][0])
    break


Fixed code:
n,m=map(int,input().split())
ab=[list(map(int,input().split())) for i in range(n)]
ab.sort()
t=[[0]*2 for i in range(n)]
for i in range(n):
  t[i]=[t[i-1][0]+ab[i][0]*ab[i][1],t[i-1][1]+ab[i][1]]
  if t[i][1]>=m:
    t[i][0]-=ab[i][0]*(t[i][1]-m)
    print(t[i][0])
    break
Buggy code:
import numpy as np

N, M = [int(i) for i in input().split()]
A = []
B = []
for n in range(0, N):
  a, b = [int(i) for i in input().split()]
  A.append(a)
  B.append(b)

A = np.array(A)
B = np.array(B)
B = B[np.argsort(A)]
A = A[np.argsort(A)]

m = 0
cost = 0
for n in range(0, N):
  if m >= M:
    break
  m = m + B[n]
  cost = cost + A[n] * B[n]
if m != 0:
  cost = cost - A[n] * (m - M)

print(cost)


Fixed code:
import numpy as np

N, M = [int(i) for i in input().split()]
A = []
B = []
for n in range(0, N):
  a, b = [int(i) for i in input().split()]
  A.append(a)
  B.append(b)

A = np.array(A)
B = np.array(B)
B = B[np.argsort(A)]
A = A[np.argsort(A)]

m = 0
n = 0
cost = 0
while True:
  if m >= M:
    break
  m = m + B[n]
  cost = cost + A[n] * B[n]
  n = n + 1
if m != 0:
  cost = cost - A[n - 1] * (m - M)

print(cost)
Buggy code:
n, m = map(int, input().split())
shop = []
for i in range(n):
  shop.append(list(map(int, input().split())))
shop.sort()
bought = 0
cost = 0
for i in range(n):
  bought += min(m, b[i])
  cost += min(m, b[i]) * a[i]
  m -= min(m, b[i])
print(cost)

Fixed code:
n, m = map(int, input().split())
shop = []
for i in range(n):
  shop.append(list(map(int, input().split())))
shop.sort()
bought = 0
cost = 0
for i in range(n):
  bought += min(m, shop[i][1])
  cost += min(m, shop[i][1]) * shop[i][0]
  m -= min(m, shop[i][1])
print(cost)