qyliang/CodeNanoFix huggingface dataset:
Buggy code:
N,M = map(int,input().split())
sets = []
for _ in range(N):
    sets.append(list(map(int,input().split())))
    
def mergesort(sets):
    if len(sets) == 1:
        return [sets[0]]
    else:
        leng = len(sets)
        sets1 = mergesort(sets[:leng//2])
        sets2 = mergesort(sets[leng//2:])
        return merge(sets1,sets2)

def merge(set1,set2):
    i=0
    j=0
    result = []
    for _ in range(len(set1)+len(set2)):
        if i<len(set1) and j<len(set2):
            if set1[i][0] >= set2[j][0]:
                result.append(set2[j])
                j += 1
            elif set2[j][0] > set1[i][0]:
                result.append(set1[i])
                i += 1
        elif i == len(set1):
            result.append(set2[j])
            j += 1
        elif j == len(set2):
            result.append(set1[i])
            i += 1
    return result

def minimummoney(m,sets):
    sets = mergesort(sets)
    rest = m
    cost = 0
    for i in range(len(sets)):
        if rest > sets[i][1]:
            cost += sets[i][0]*sets[i][1]
            rest -= sets[i][1]
            continue
        if 0 < rest and rest < sets[i][1]:
            cost += rest * sets[i][0]
        break
    return cost

print(minimummoney(M,sets))

Fixed code:
N,M = map(int,input().split())
sets = []
for _ in range(N):
    sets.append(list(map(int,input().split())))
    
def mergesort(sets):
    if len(sets) == 1:
        return [sets[0]]
    else:
        leng = len(sets)
        sets1 = mergesort(sets[:leng//2])
        sets2 = mergesort(sets[leng//2:])
        return merge(sets1,sets2)

def merge(set1,set2):
    i=0
    j=0
    result = []
    for _ in range(len(set1)+len(set2)):
        if i<len(set1) and j<len(set2):
            if set1[i][0] >= set2[j][0]:
                result.append(set2[j])
                j += 1
            elif set2[j][0] > set1[i][0]:
                result.append(set1[i])
                i += 1
        elif i == len(set1):
            result.append(set2[j])
            j += 1
        elif j == len(set2):
            result.append(set1[i])
            i += 1
    return result

def minimummoney(m,sets):
    sets = mergesort(sets)
    rest = m
    cost = 0
    for i in range(len(sets)):
        if rest > sets[i][1]:
            cost += sets[i][0]*sets[i][1]
            rest -= sets[i][1]
            continue
        if 0 < rest and rest <= sets[i][1]:
            cost += rest * sets[i][0]
        break
    return cost

print(minimummoney(M,sets))
Buggy code:
N,M = map(int,input().split())

A = [ list(map(int,input().split())) for _ in range(N) ]
A.sort()
ans = 0
for M == 0:
  if M >= A[0][1]:
    ans += A[0][0] * A[0][1]
    M -= A[0][1]
    del A[0]
  else:
    ans += A[0][0] * M
    M = 0
print(ans)

Fixed code:
N,M = map(int,input().split())
 
A = [ list(map(int,input().split())) for _ in range(N) ]
A.sort()
ans = 0
while M > 0:
  if M >= A[0][1]:
    ans += A[0][0] * A[0][1]
    M -= A[0][1]
    del A[0]
  else:
    ans += A[0][0] * M
    M = 0
print(ans)
Buggy code:
#python 2.7
n,m=map(int,input().split())
ab=[list(map(int,input().split()))]
ab=sorted(ab,key=lambda x:x[0])
res=ans=0
for i in range(n):
  if res+ab[i][1]>=m:
    ans+=(ab[i][0])*(m-res)
    break
  else:
    ans+=(ab[i][0])*ab[i][1]
    res+=ab[i][1]
print(ans)

Fixed code:
#python 2.7
n,m=map(int,input().split())
ab=[list(map(int,input().split())) for i in range(n)]
ab=sorted(ab,key=lambda x:x[0])
res=ans=0
for i in range(n):
  if res+ab[i][1]>=m:
    ans+=(ab[i][0])*(m-res)
    break
  else:
    ans+=(ab[i][0])*ab[i][1]
    res+=ab[i][1]
print(ans)
Buggy code:
N, M = map(int, input().split())
shops = sorted([list(map(int, input().split())) for i in range(n)])
drink = 0
cost = 0

for i in range(N):
    cost += shops[i][0]*shops[i][1]
    drink += shops[i][1]
    if drink >= m:
        cost -= (drink -m) * shops[i][0]
        break
        
print(cost)


Fixed code:
N, M = map(int, input().split())
shops = sorted([list(map(int, input().split())) for i in range(N)])
drink = 0
cost = 0

for i in range(N):
    cost += shops[i][0]*shops[i][1]
    drink += shops[i][1]
    if drink >= M:
        cost -= (drink -M) * shops[i][0]
        break
        
print(cost)
Buggy code:
n, m = map(int, input().split())
l = [list(map(int, input().split())) for i in range(n)]
ll = sorted(l)
count, total, i = 0, 0, 0
while count < m:
    count += ll[i][1]
    total += ll[i][0]*ll[i][1]
    i += 1
if i == n:
    total += ll[i-1][0]*(m-count)
    print(total)
    exit()
total += ll[i][0]*(m-count)
print(total)

Fixed code:
n, m = map(int, input().split())
l = [list(map(int, input().split())) for i in range(n)]
ll = sorted(l)
count = 0
total = 0
for i in range(n):
    if count < m:
        count += ll[i][1]
        total += ll[i][0]*ll[i][1]
    else:
        c = count-m
        total -= ll[i-1][0]*c
        print(total)
        exit()
    if i == n-1:
        c = count-m
        total -= ll[i][0]*c
        print(total)
        exit()
Buggy code:
n, m = map(int, input().split())
a = [0] * (n + 1)
b = [0] * (n + 1)
price = [0] * (n + 1)
ans = 0

shop = [tuple(map(int, input().split())) for _ in range(n)]
shop.sort()

for i in range(1, n + 1):
    a_i, b_i = shop[i - 1]
    a[i] = a[i - 1]
    b[i] = b[i - 1]
    price[i] = a_i
    a[i] += a_i * b_i
    b[i] += b_i

for i in range(1, n + 1):
    if m <= b[i]:
        m = m - b[i - 1]
        print(m)
        ans = a[i - 1] + price[i] * m
        break
print(ans)


Fixed code:
n, m = map(int, input().split())
a = [0] * (n + 1)
b = [0] * (n + 1)
price = [0] * (n + 1)
ans = 0

shop = [tuple(map(int, input().split())) for _ in range(n)]
shop.sort()

for i in range(1, n + 1):
    a_i, b_i = shop[i - 1]
    a[i] = a[i - 1]
    b[i] = b[i - 1]
    price[i] = a_i
    a[i] += a_i * b_i
    b[i] += b_i

for i in range(1, n + 1):
    if m <= b[i]:
        m = m - b[i - 1]
        ans = a[i - 1] + price[i] * m
        break
print(ans)
Buggy code:
import numpy as np

N,M = map(int,input().split())
AB = [[int(x) for x in input().split()] for _ in range(N)]

AB.sort()

cnt = 0
yen = 0

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

Fixed code:
import numpy as np

N,M = map(int,input().split())
AB = [[int(x) for x in input().split()] for _ in range(N)]

AB.sort()

cnt = 0
yen = 0

for a,b in AB:
  if cnt + b <= M:
    cnt += b
    yen += a * b
    continue
  yen += a * (M - cnt)
  break

answer = yen
print(answer)
Buggy code:
N, M = map(int, input().split())
buffer = []
count = 0
money = 0

for i in range(N):
    buffer.append(list(map(int, input().split())))
buffer.sort()
for i in range(N):
    if(count + buffer[i][1] < M):
        count += buffer[i][1]
        money += buffer[i][0] * buffer[i][1]
    else:
        money += buffer[i][0] * (M - count)

print(money)    

Fixed code:
N, M = map(int, input().split())
buffer = []
count = 0
money = 0

for i in range(N):
    buffer.append(list(map(int, input().split())))
buffer.sort()
for i in range(N):
    if(count + buffer[i][1] < M):
        count += buffer[i][1]
        money += buffer[i][0] * buffer[i][1]
    else:
        money += buffer[i][0] * (M - count)
        break

print(money)
Buggy code:
n, m = map(int, input().split())
list = []
for i in range(n) :
    a, b = map(int, input().split())
    list.append([a, b])
list.sort(key=lambda x:x[0])
count = 0 ; ans = 0
for i in range(n) :
    if list[i][1] < m - count :
        ans += list[i][0] * list[i][1]
        count += list[i][1]
    elif list[i][1] > m - count :
        ans += list[i][0] * (m - count)
        break
print(ans)


Fixed code:
n, m = map(int, input().split())
list = []
for i in range(n) :
    a, b = map(int, input().split())
    list.append([a, b])
list.sort(key=lambda x:x[0])
count = 0 ; ans = 0
for i in range(n) :
    if list[i][1] < m - count :
        ans += list[i][0] * list[i][1]
        count += list[i][1]
    elif list[i][1] >= m - count :
        ans += list[i][0] * (m - count)
        break
print(ans)
Buggy code:
n,m=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

Fixed code:
n,m=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)
Buggy code:
N, M = map(int, input().split())
drink = []
cost = 0
count = 0
d_count = 0
rest = 0
 
 
for _ in range(N):
    drink.append(list(map(int, input().split())))
    drink.sorted()
 
for i in range(N):
    cost += drink[i][0] * drink[i][1]
    d_count += drink[i][1]
    count += 1
    if d_count > M:
      break
      
cost -= drink[count-1][0] * drink[count-1][1]
d_count -= drink[count-1][1]
rest = M - d_count
cost += rest * drink[count-1][0]
print(cost)

Fixed code:
N, M = map(int, input().split())
drink = []
cost = 0
d_count = 0


for _ in range(N):
    drink.append(list(map(int, input().split())))
    
drink = sorted(drink)

for i in range(N):
    cost += drink[i][0] * drink[i][1]
    d_count += drink[i][1] 
    if d_count > M:
      cost -= drink[i][0] * (d_count - M)
      break
      

print(cost)
Buggy code:
from operator import itemgetter

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


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

if N ==1:
    Z = M*a[0]
    print(Z)
else:
    a.sort(key = itemgetter(0))
    X = 0 
    D = 0
    var=0
    while M>D:
        D+=a[var][1]
        X+=a[var][0]*a[var][1]
        var+=1
        
    X += a[var-1][0]*(M-D)
    print(X)


Fixed code:
from operator import itemgetter

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


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

if N ==1:
    Z = M*a[0][0]
    print(Z)
else:
    a.sort(key = itemgetter(0))
    X = 0 
    D = 0
    var=0
    while M>D:
        D+=a[var][1]
        X+=a[var][0]*a[var][1]
        var+=1
        
    X += a[var-1][0]*(M-D)
    print(X)
Buggy code:
N,M = map(int,input().split())
X =[]
for i in range(N):
    a,b = map(int,input().split())
    X.append([a,b])
X.sort(key=lambda x: x[0])
count = 0
ans = 0
for i in X:
    if M - count > i[1]:
        count += i[1]
        ans += i[0] * i[1]
        print(ans,count)
    else:
        x = M - count
        ans += i[0] * x
        break
print(ans)

Fixed code:
N,M = map(int,input().split())
X =[]
for i in range(N):
    a,b = map(int,input().split())
    X.append([a,b])
X.sort(key=lambda x: x[0])
count = 0
ans = 0
for i in X:
    if M - count > i[1]:
        count += i[1]
        ans += i[0] * i[1]
        #print(ans,count)
    else:
        x = M - count
        ans += i[0] * x
        break
print(ans)
Buggy code:
N, M = [int(x) for x in input().split()]
V = [tuple(map(int, innput().split())) for i in range(N)]
V.sort()

money = 0
count = 0

for a, b in V:
  if count + b < M:
    count += b
    money += a * b
  else:
    money += (M - b) * a
    break
print(money)

Fixed code:
N, M = [int(x) for x in input().split()]
V = [tuple(map(int, input().split())) for i in range(N)]
V.sort()

money = 0
count = 0

for a, b in V:
  if count + b < M:
    count += b
    money += a * b
  else:
    money += (M - count) * a
    break
print(money)
Buggy code:
import numpy as np

N, M = map(int, input().split())
num_dict = dict()
A_list = []

for n in range(N):
  A, B = map(int, input().split())
  num_dict[A] = B
  A_list.append(A)

A_list.sort()
b_accum = 0
all_pay = 0

for a in A_list:
  if M <= b_accum:
    break

  if b_accum + num_dict[a] <= M:
    all_pay += num_dict[a] * a
    b_accum += num_dict[a]
    
    if M == b_accum:
		
  
  else:
    all_pay += (M - b_accum) * a 
    b_accum += num_dict[a]
    
print(all_pay)

 

Fixed code:
import numpy as np

N, M = map(int, input().split())
num_dict = dict()
A_list = []
B_list = []

for n in range(N):
  A, B = map(int, input().split())
  num_dict.setdefault(A, 0)
  num_dict[A] += B
  A_list.append(A)

A_list = list(set(A_list))
A_list.sort()
b_accum = 0
all_pay = 0

for a in A_list:
  if M <= b_accum:
    break

  if b_accum + num_dict[a] <= M:
    all_pay += num_dict[a] * a
    b_accum += num_dict[a]    
  
  else:
    all_pay += (M - b_accum) * a 
    b_accum += num_dict[a]
    break
    
print(all_pay)
Buggy code:
N, M = 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
    nob = min(M-sum_drinks, nos) #number of drinks which he can buy at the shop
    ans += nob*PNs[i][0] #add money he spent at the shop
    sum_drinks += nob
    if s>=M: break

print(ans)


Fixed code:
N, M = 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)
Buggy code:
import sys
input = sys.stdin.readline
n,m = map(int,input().split())
l = []
for i in range(n):
  a,b = map(int,input().split())
  l.append([a,b])
i = 0
count = 0
money = 0
while count < m:
  count += l[i][1]
  money = l[i][0]*l[i][1]
  i += 1
i -= 1
if count > m:
  money - (m-count)*l[i][1]
print(money)

Fixed code:
import sys
input = sys.stdin.readline
n,m = map(int,input().split())
l = []
for i in range(n):
  a,b = map(int,input().split())
  l.append([a,b])
l.sort()
i = 0
count = 0
money = 0
while count < m:
  count += l[i][1]
  money += l[i][0]*l[i][1]
  i += 1
i -= 1
if count > m:
  money -= (count-m)*l[i][0]
print(money)
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())
x=np.argsort(a)
ans=0
i=0
while m>0:
    ans+=a[x[i]]*min(b[x[i]],m)
    i+=1
    m-=b[x[i]]
print(round(ans))
    

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())
x=np.argsort(a)
ans=0
i=0
while m>0:
    ans+=a[x[i]]*min(b[x[i]],m)
    m-=b[x[i]]
    i+=1
print(int(ans))
Buggy code:
n,m = map(int,input().split())

store = []

for i in range(n):
  price,stock = map(int,input().split())
  store.append([price,stock])

store.sort()

total_cost = 0
for i in range(n):
  if m > 0:
    buy = min([m,store[1][i]])
    total_cost += buy * store[0][i]
    m -= buy
  else:
    break

print(total_cost)

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

store = []

for i in range(n):
  price,stock = map(int,input().split())
  store.append([price,stock])

store.sort()

total_cost = 0
for i in range(n):
  if m > 0:
    buy = min([m,store[i][1]])
    total_cost += buy * store[i][0]
    m -= buy
  else:
    break

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


Fixed code:
a = list(map(int, input().split()))
N = a[0]
M = a[1]
price = 0
b = [list(map(int, input().split())) for i in range(N)]
lst = sorted(b)
for i in lst:
    if M <= i[1]:
        price = price + i[0] * M
        print(price)
        break
    else:
        M = M - i[1]
        price = price + i[0] * i[1]
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])

count = 0
money = 0
while True:
    count += ab[0][1]
    if count <= m:
        money += ab[0][0] * ab[0][1]
        del ab[0]
    else:
        money += ab[0][0] * (m - count + ab[0][1])
        break

print(money)

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

count = 0
money = 0
while True:
    count += ab[0][1]
    if count < m:
        money += ab[0][0] * ab[0][1]
        del ab[0]
    else:
        money += ab[0][0] * (m - count + ab[0][1])
        break

print(money)
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])
A = []
B = []
for i in range(N):
    A.append(AB[i][0])
    B.append(AB[i][1])

ans = 0
for i in range(N):
    if M - A[i]>0:
        ans += A[i]*B[i]
        M -= B[i]
    else:
        while M > 0:
            ans += A[i]
            M -= 1

print(ans)

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])
A = []
B = []
for i in range(N):
    A.append(AB[i][0])
    B.append(AB[i][1])

ans = 0
for i in range(N):
    if M - B[i]>0:
        ans += A[i] * B[i]
        M -= B[i]
    else:
        while M > 0:
            ans += A[i]
            M -= 1

print(ans)
Buggy code:
n,m = map(int,input().split())
drink=[]
for _ in range(n):
  a,b = map(int,input().split())
  drink.append(a,b)
drink.sort(reverse=1)

ans = 0
while m<0:
  a,b = drink.pop(-1)
  ans += a*min(m, b)
  m -= b
print(ans)

Fixed code:
n,m = map(int,input().split())
drink=[]
for _ in range(n):
  a,b = map(int,input().split())
  drink.append((a,b))
drink.sort(reverse=1)

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

drink.sort()
#print(drink)
money=0
number=0
for i in range(n):
    if number+drink[i][0]<m:
        money+=drink[i][0]*drink[i][1]
        number+=drink[i][1]
    elif m<number+drink[i][0]:
        money+=drink[i][0]*(m-number)
        number+=m-number
        break
    if m==number:
        break
print(money)


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

drink.sort()
#print(drink)
money=0
number=0
for i in range(n):
    if number+drink[i][1]<=m:
        money+=drink[i][0]*drink[i][1]
        number+=drink[i][1]
    elif m<number+drink[i][1]:
        money+=drink[i][0]*(m-number)
        number+=m-number
        break
    if m==number:
        break
print(money)
Buggy code:
N,M = map(int,input().split())
A = sorted([list(map(int,input().split())) for _ in range(N)],key=lambda x:x[0])
cnt = 0
cost = 0
i = 0
while True:
    a,b = A[i]
    if cnt+b<=M:
        cnt += b
        cost += a*b
    else:break
    i += 1
if cnt<M:
    a,b = A[i]
    cost += (M-cnt)*a
print(cost)

Fixed code:
N,M = map(int,input().split())
A = sorted([list(map(int,input().split())) for _ in range(N)],key=lambda x:x[0])
cnt = 0
cost = 0
for i in range(N):
    a,b = A[i]
    if cnt+b<=M:
        cnt += b
        cost += a*b
    else:
        d = M-cnt
        cost += a*d
        break
print(cost)
Buggy code:
N,M = map(int,input().split())
A = sorted([list(map(int,input().split())) for _ in range(N)],key=lambda x:x[0])
cnt = 0
for i in range(N):
    if cnt+A[i][1]>M:
        ind = i-1
        break
    cnt += A[i][1]
yen = 0
for i in range(ind+1):
    yen += A[i][0]*A[i][1]
yen += A[ind+1][0]*(M-cnt)
print(yen)

Fixed code:
N,M = map(int,input().split())
A = sorted([list(map(int,input().split())) for _ in range(N)],key=lambda x:x[0])
cnt = 0
ind = N-1
for i in range(N):
    if cnt+A[i][1]>M:
        ind = i-1
        break
    cnt += A[i][1]
yen = 0
for i in range(ind+1):
    yen += A[i][0]*A[i][1]
if ind+1<N:
    yen += A[ind+1][0]*(M-cnt)
print(yen)
Buggy code:
from operator import itemgetter

N, M = map(int,input().split())
shops = []
for i in range(N):
  shops.append(list(map(int,input().split())))
shops.sort(key=itemgetter(1))
daikin = 0
can = 0
j = 0
while can < M:
  daikin += (shops[j][0]*shops[j][1])
  can += shops[j][1]
  j += 1
if can > M:
  daikin -= (can - M)*shops[j-1][0]
print(daikin)

Fixed code:
from operator import itemgetter

N, M = map(int,input().split())
shops = []
for i in range(N):
  shops.append(list(map(int,input().split())))
shops.sort(key=itemgetter(0))
daikin = 0
can = 0
j = 0
while can < M:
  daikin += (shops[j][0]*shops[j][1])
  can += shops[j][1]
  j += 1
if can > M:
  daikin -= (can - M)*shops[j-1][0]
print(daikin)
Buggy code:
import heapq

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

heapq.heapify(L)
# heapq.heapify(sorted(L, key=lambda x: x[0]))
print(L)
drink = 0
yen = 0
while drink < M:
    a, b = heapq.heappop(L)
    if drink + b <= M:
        yen += a * b
        drink += b
    else:
        yen += a * (M - drink)
        break
print(yen)


Fixed code:
import heapq

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

heapq.heapify(L)
# heapq.heapify(sorted(L, key=lambda x: x[0]))
# print(L)
drink = 0
yen = 0
while drink < M:
    a, b = heapq.heappop(L)
    if drink + b <= M:
        yen += a * b
        drink += b
    else:
        yen += a * (M - drink)
        break
print(yen)
Buggy code:
n, m = map(int,input().split())
drink = []
for i in range(n):
  drink.append(list(map(int,input().split())))
sorteddrink = sorted(drink, key = lambda x:x[0])

count = 0
cost = 0
index = 0

while True:
  if count + sorteddrink[index][1] > m:
    break
  cost += sorteddrink[index][0] * sorteddrink[index][1]
  count += sorteddrink[index][1]
  index += 1
  
cost += sorteddrink[index][0] * (m - count)
print(cost)

Fixed code:
n, m = map(int,input().split())
drink = []
for i in range(n):
  drink.append(list(map(int,input().split())))
sorteddrink = sorted(drink, key = lambda x:x[0])

count = 0
cost = 0
index = 0

while True:
  if index > n - 1:
    break
  if count + sorteddrink[index][1] > m:
    break
  cost += sorteddrink[index][0] * sorteddrink[index][1]
  count += sorteddrink[index][1]
  index += 1

if index <= n - 1:
  cost += sorteddrink[index][0] * (m - count)
print(cost)
Buggy code:
import numpy as np
N, M = map(int, input().split())
AB = np.empty((N, 2), dtype=np.int64)
for n in range(N):
    AB[n, :] = list(map(int, input().split()))
AB = AB[AB[:, 0].argsort(), :]
print(AB)
n = 0
ans = 0
while M > 0:
    if M > AB[n, 1]:
        ans += AB[n, 0] * AB[n, 1]
        M -= AB[n, 1]
    else:
        ans += AB[n, 0] * M
        M = 0
    n += 1
print(ans)

Fixed code:
import numpy as np
N, M = map(int, input().split())
AB = np.empty((N, 2), dtype=np.int64)
for n in range(N):
    AB[n, :] = list(map(int, input().split()))
AB = AB[AB[:, 0].argsort(), :]
n = 0
ans = 0
while M > 0:
    if M > AB[n, 1]:
        ans += AB[n, 0] * AB[n, 1]
        M -= AB[n, 1]
    else:
        ans += AB[n, 0] * M
        M = 0
    n += 1
print(ans)
Buggy code:
N,M=map(int,input().split())
L=[]

ans=0

for i in range(N):
    a,b=map(int,input().split())

    L.append([a,b])

L= sorted(L)



for i in range(N):

    ans = L[i][0]*L[i][1]
    M -= L[i][1]


    if M <= L[i+1][1]:

        ans += M * L[i+1][0]

        print(ans)

        exit()

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

for i in range(N):
    a,b=map(int,input().split())

    L.append([a,b])

L= sorted(L)

for i in range(N):

    if M < L[i][1]:
        ans=L[i][0]*M

        print(ans)
        exit()
        
    else:
        ans += L[i][0]*L[i][1]
        M -= L[i][1]

        if M==0:

            print(ans)
            exit()

        elif M <= L[i+1][1]:

            ans += M * L[i+1][0]
            print(ans)
            exit()
Buggy code:
N,M=map(int,input().split())
l=[]
for i in range(N):
  A,B=map(int,input().split())
  l.append([A,B])
l.sort(key=lambda x:x[1])
i=0
ans=0
while M>l[i][1]:
  M-=l[i][1]
  i+=1
  ans+=l[i][0]+l[i][1]
ans+=l[i][0]*M
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])
l.sort(key=lambda x:x[0])
i=0
ans=0
while M>l[i][1]:
  M-=l[i][1]
  ans+=l[i][0]*l[i][1]
  i+=1
ans+=l[i][0]*M
print(ans)