qyliang/CodeNanoFix huggingface dataset:
Buggy code:
import numpy as np
#N,M=2,5
#AB=np.array([[4,9],[2,4]])
N,M=map(int,input().split())
AB=np.zeros((N,2))
for i in range(N):
    AB[i,0],AB[i,1]=map(int,input().split())
AB = AB[np.argsort(AB[:, 0])]
print(AB)
numd=0
ans=0
for i in range(len(AB)):
    if numd==M:
        break
    else:
        if AB[i][1] < M-numd:
            ans+=AB[i][0]*AB[i][1]
            numd+=AB[i][1]
        else:
            ans+=AB[i][0]*(M-numd)
            numd+=M-numd
print(int(ans))

Fixed code:
import numpy as np
#N,M=2,5
#AB=np.array([[4,9],[2,4]])
N,M=map(int,input().split())
AB=np.zeros((N,2))
for i in range(N):
    AB[i,0],AB[i,1]=map(int,input().split())
AB = AB[np.argsort(AB[:, 0])]
numd=0
ans=0
for i in range(len(AB)):
    if numd==M:
        break
    else:
        if AB[i][1] < M-numd:
            ans+=AB[i][0]*AB[i][1]
            numd+=AB[i][1]
        else:
            ans+=AB[i][0]*(M-numd)
            numd+=M-numd
print(int(ans))
Buggy code:
#coding: utf-8
import numpy as np
N, M = map(int, input().split())
AB = np.array([list(map(int, input().split())) for _ in range(N)])
money = 0
col_num = 0
AB = AB[np.argsort(AB[:, col_num])]
print(AB)
if M <= AB[np.argmin(AB[:, 0]), 1]:
    money += AB[0, 0] * M
else:
    i = 0
    while M >= 0:
        money += AB[i, 0] * AB[i, 1]
        M -= AB[i, 1]
        if M < 0:
          money += AB[i, 0] * M
        i += 1
print(money)

Fixed code:
#coding: utf-8
import numpy as np
N, M = map(int, input().split())
AB = np.array([list(map(int, input().split())) for _ in range(N)])
money = 0
col_num = 0
AB = AB[np.argsort(AB[:, col_num])]
if M <= AB[np.argmin(AB[:, 0]), 1]:
    money += AB[0, 0] * M
else:
    i = 0
    while M > 0:
        money += AB[i, 0] * AB[i, 1]
        M -= AB[i, 1]
        if M <= 0:
          money += AB[i, 0] * M
        i += 1
print(money)
Buggy code:
N, M = map(int, input().split())
A_B = []
for i in range(N):
    A_B.append(list(map(int, input().split())))
A_B.sort()
print(A_B)
sum = 0
money = 0
i = 0
while sum <= M:
    money += A_B[i][0] * A_B[i][1]
    sum += A_B[i][1]
    print(sum)
    i += 1
money -= A_B[i-1][0] * (sum - M)
print(money)


Fixed code:
N, M = map(int, input().split())
A_B = []
for i in range(N):
    A_B.append(list(map(int, input().split())))
A_B.sort()
sum = 0
money = 0
i = 0
while sum <= M and i < N:
    money += A_B[i][0] * A_B[i][1]
    sum += A_B[i][1]
    i += 1
money -= A_B[i-1][0] * (sum - M)
print(money)
Buggy code:
n,m=map(int,input().split())
ab=[list(map(int,input().split())) for i in range(n)]

ab_sorted = sorted(ab, key=lambda x:(x[0], -x[1]))
print(ab_sorted)

num = 0
amount_of_money = 0
for i in range(n):
  buy = min(ab_sorted[i][1], m-num)
  num += buy
  amount_of_money += ab_sorted[i][0] * buy
    
  if num >= m:
    print(amount_of_money)


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

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

num = 0
amount_of_money = 0
for i in range(n):
  buy = min(ab_sorted[i][1], m-num)
  num += buy
  amount_of_money += ab_sorted[i][0] * buy
    
  if num >= m:
    print(amount_of_money)
    exit(0)
Buggy code:
import numpy as np
from operator import itemgetter
N,M=(int(x) for x in input().split())
A=[]
for i in range(N):
  D=[int(x) for x in input().split()]
  A=A+[D]
print(A)    
result=A.sort(key=itemgetter(0))
print(A)
count=M
sum=0
for i in range(N):
  if count-A[i][1]>0:
    count=count-A[i][1]
    sum=sum+A[i][0]*A[i][1]
  else:
    sum=sum+count*A[i][0]
    break
print(sum)    

Fixed code:
import numpy as np
from operator import itemgetter
N,M=(int(x) for x in input().split())
A=[]
 
for i in range(N):
  D=[int(x) for x in input().split()]
  A+=[D]    
result=A.sort(key=itemgetter(0))
count=M
sum=0
for i in range(N):
  if count-A[i][1]>0:
    count=count-A[i][1]
    sum+=A[i][0]*A[i][1]
  else:
    sum+=count*A[i][0]
    break
print(sum)
Buggy code:
N, M = [int(i) for i in input().split()]
shops = []

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

shops.sort()

print(shops)
result = 0
rest_count = M
for shop in shops:
    if rest_count > shop[1]:
        result += shop[0] * shop[1]
        rest_count -= shop[1]
    else:
        result += shop[0] * rest_count
        break

print(result)

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

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

shops.sort()

result = 0
rest_count = M
for shop in shops:
    if rest_count > shop[1]:
        result += shop[0] * shop[1]
        rest_count -= shop[1]
    else:
        result += shop[0] * rest_count
        break

print(result)
Buggy code:
n,m = map(int,input().split()）
ab = [list(map(int,input().split())) for _ in range(n)]
ab = sorted(ab, key=lambda ab:ab[0])

ans = 0
total = 0
for i in range(n):
  num = m-toal
  if ab[i][1]<=num:
    total += ab[i][1]
    ans += ab[i][0]*ab[i][1]
  else:
    total += num
    ans += num*ab[i][1]
    break
print(ans)


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

ans = 0
total = 0
for i in range(n):
  num = m - total
  if ab[i][1]<num:
    total += ab[i][1]
    ans += ab[i][0]*ab[i][1]
  else:
    total += num
    ans += num*ab[i][0]
    break
print(ans)
Buggy code:
N,M = (int(i) for i in input().split())
AB = []

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

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

count = 0
ans = 0

for A,B in AB:
  if count + B > M:
    ans += A*(M-count)
    break
  else:
    ans += A*B
    count += B


print(ans)


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

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

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

count = 0
ans = 0

for A,B in AB:
  if count + B > M:
    ans += A*(M-count)
    break
  else:
    ans += A*B
    count += B


print(ans)
Buggy code:
import numpy as np

def solve():
    cnt = 0
    money = 0
    for i in range(N):
        if cnt >= M:
            break
        if cnt + AB[i][1] >= M:
            money += AB[i][0] * (M - cnt)
            cnt = M   
        else:
            money += AB[i][0]*AB[i][1]
            cnt = AB[i][1]
    print(cnt)
    print(money)

if __name__ == "__main__":
    N,M = list(map(int, input().split()))   
    AB = [list(map(int, input().split())) for _ in range(N)]
    AB.sort(key=lambda x: x[0])
#    print(AB)
    solve()


Fixed code:
import numpy as np

def solve():
    cnt = 0
    money = 0
    for i in range(N):
        if cnt >= M:
            break
        if cnt + AB[i][1] >= M:
            money += AB[i][0] * (M - cnt)
            cnt = M   
        else:
            money += AB[i][0]*AB[i][1]
            cnt += AB[i][1]
#    print(cnt)
    print(money)

if __name__ == "__main__":
    N,M = list(map(int, input().split()))   
    AB = [list(map(int, input().split())) for _ in range(N)]
    AB.sort(key=lambda x: x[0])
#    print(AB)
    solve()
Buggy code:
# coding: utf-8

import sys
input = sys.stdin.readline

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

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

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

print(ans)



Fixed code:
# coding: utf-8

# import sys
# input = sys.stdin.readline

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

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

k = 0
ans = 0
while M > 0:
    if M > AB[k][1]:
        M -= AB[k][1]
        ans += AB[k][0] * AB[k][1]
    else:
        ans += AB[k][0] * M
        break
    
    k += 1

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

A_B_AB_list = []
for i in range(N):
    A,B = map(int,input().split())
    A_B_AB = [A,B,A*B]
    A_B_AB_list.append(A_B_AB)
A_B_AB_list.sort()
B_sums = [0]*(N+1)
AB_sums = [0]*(N+1)
for i in range(N):
    B_sums[i+1] = B_sums[i] + A_B_AB_list[i][1]
    AB_sums[i+1] = AB_sums[i] + A_B_AB_list[i][2]
for i in range(1,N+1):
    if B_sums[i] > M:
        amari = M - B_sums[i-1] 
        ans = AB_sums[i-1] + amari*A_B_AB_list[i-1][0]
        print(ans)
        break

    

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

A_B_AB_list = []
for i in range(N):
    A,B = map(int,input().split())
    A_B_AB = [A,B,A*B]
    A_B_AB_list.append(A_B_AB)
A_B_AB_list.sort()
B_sums = [0]*(N+1)
AB_sums = [0]*(N+1)
for i in range(N):
    B_sums[i+1] = B_sums[i] + A_B_AB_list[i][1]
    AB_sums[i+1] = AB_sums[i] + A_B_AB_list[i][2]
for i in range(1,N+1):
    if B_sums[i] >= M:
        amari = M - B_sums[i-1] 
        ans = AB_sums[i-1] + amari*A_B_AB_list[i-1][0]
        print(ans)
        break
Buggy code:
n,m=map(int,input().split())
ab=sorted([list(map(int,input().split())) for i in range(n)])
shop,cost,rest=m,0,0
while True:
    if ab[shop][1]<rest:
        cost+=ab[shop][1]*ab[shop][0]
        rest-=ab[shop][1]
        shop+=1
    else:
        cost+=ab[shop][0]*rest
        break
print(cost)

Fixed code:
n,m = map(int,input().split())
ab = sorted([list(map(int,input().split())) for i in range(n)])
shop,cost,rest=0,0,m
while True:
    if ab[shop][1]<rest:
        cost += ab[shop][1]*ab[shop][0]
        rest -= ab[shop][1]
        shop+=1
    else:
        cost+=ab[shop][0]*rest
        break
print(cost)
Buggy code:
def main():
    N, M = map(int, input().split())
    A = [[0, 0] for _ in range(N)]
    for i in range(N):
        A[i][0], A[i][1] = map(int, input().split())
    
    cnt = 0
    money = 0
    A.sort(key=lambda x:x[0])
    for i in range(N):
        if(cnt < M):
            money += A[i][0]*A[i][1]
            cnt += A[i][1]
        else:
            break
    if(cnt == M):
        print(money)
    else:
        print(money-(cnt-M)*A[i-1][0])
    
main()

Fixed code:
def main():
    N, M = map(int, input().split())
    A = [[0, 0] for _ in range(N)]
    for i in range(N):
        A[i][0], A[i][1] = map(int, input().split())
    
    cnt = 0
    money = 0

    A.sort(key=lambda x:(x[0], x[1]))
    for i in range(N):
        money += A[i][0]*A[i][1]
        cnt += A[i][1]
        if(cnt >= M):
            break
    if(cnt == M):
        print(money)
    else:
        print(money-(cnt-M)*A[i][0])
    
main()
Buggy code:
# coding: utf-8
import os
from sys import stdin
from functools import total_ordering

__dirname = os.path.dirname(__file__)
__basename = os.path.splitext(os.path.basename(__file__))[0]
__targetname = './input/' + __basename + '.txt'
target_path = os.path.join(__dirname, __targetname)
stdin = open(target_path)

@total_ordering
class struct(object):
    def __init__(self,a,b):
        self.a=a
        self.b=b
    def __lt__	(self,other):
        return self.a < other.a
    def __eq__	(self,other):
        return self.a == other.a

def main():
    # st = struct(10,1)
    # print(st.a)
    input_line = stdin.readline().rstrip().split(' ')
    N, M = map(int, input_line)
    A = list()
    for _ in range(N):
        input_line = stdin.readline().rstrip().split(' ')
        a,b=map(int, input_line)
        st=struct(a,b)
        A.append(st)
    A.sort()
    ans=0
    time=0
    for x in A:
        # print(x.a,x.b)
        if(time>M):
            continue
        if((time+x.b)<=M):
            ans += x.a*x.b
            time += x.b
        else:
            ans += x.a*(M-time)
            time = M
    print(ans)



if __name__ == "__main__":
    main()
    

Fixed code:
# coding: utf-8
import os
from sys import stdin
from functools import total_ordering

# __dirname = os.path.dirname(__file__)
# __basename = os.path.splitext(os.path.basename(__file__))[0]
# __targetname = './input/' + __basename + '.txt'
# target_path = os.path.join(__dirname, __targetname)
# stdin = open(target_path)

@total_ordering
class struct(object):
    def __init__(self,a,b):
        self.a=a
        self.b=b
    def __lt__	(self,other):
        return self.a < other.a
    def __eq__	(self,other):
        return self.a == other.a

def main():
    # st = struct(10,1)
    # print(st.a)
    input_line = stdin.readline().rstrip().split(' ')
    N, M = map(int, input_line)
    A = list()
    for _ in range(N):
        input_line = stdin.readline().rstrip().split(' ')
        a,b=map(int, input_line)
        st=struct(a,b)
        A.append(st)
    A.sort()
    ans=0
    time=0
    for x in A:
        # print(x.a,x.b)
        if(time>M):
            continue
        if((time+x.b)<=M):
            ans += x.a*x.b
            time += x.b
        else:
            ans += x.a*(M-time)
            time = M
    print(ans)



if __name__ == "__main__":
    main()
Buggy code:
#C - Energy Drink Collector
n,m = map(int,input().split())
ab = []
for i in range(n):
    ab.append(list(map(int, input().split())))
abSorted = sorted(ab)
sumB = 0
sumMoney = 0
while sumB + abSorted[i][1] < m:
    sumB += abSorted[i][1]
    sumMoney += abSorted[i][0] * abSorted[i][1]
sumMoney += sbSorted[i][0] * (m - sumB)
print(sumMoney)


Fixed code:
#C - Energy Drink Collector
n,m = map(int,input().split())
ab = []
for i in range(n):
    ab.append(list(map(int, input().split())))
abSorted = sorted(ab)
sumB = 0
sumMoney = 0
i = 0
while sumB + abSorted[i][1] < m:
    sumB += abSorted[i][1]
    sumMoney += abSorted[i][0] * abSorted[i][1]
    i += 1
sumMoney += abSorted[i][0] * (m - sumB)
print(sumMoney)
Buggy code:
n, m = map(int, input().split())
ab = sorted([list(map(int, input().split())) for _ in range(n)], key=lambda x:x[0])

ans = 0
for i in range(n):
    print(ab[i][1], m)
    if ab[i][1] < m:
        ans += ab[i][0] * ab[i][1]
        m -= ab[i][1]
    else:
        ans += ab[i][0] * m
        break

print(ans)


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

ans = 0
for i in range(n):
    if ab[i][1] < m:
        ans += ab[i][0] * ab[i][1]
        m -= ab[i][1]
    else:
        ans += ab[i][0] * m
        break

print(ans)
Buggy 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()
print(ab)
ans = 0
for i in range(N):
    if M <= ab[i][1]:
        ans += (M * ab[i][0])
        break
    else:
        ans += (ab[i][0] * ab[i][1])
        M -= ab[i][1]

print(ans)




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()
ans = 0
for i in range(N):
    if M <= ab[i][1]:
        ans += (M * ab[i][0])
        break
    else:
        ans += (ab[i][0] * ab[i][1])
        M -= ab[i][1]

print(ans)
Buggy code:
n, m = map(int, input().split())
a = []
for _ in range(n):
    a.append(list(map(int, input().split())))
a.sort()
pm = s = 0
m_minus_1 = m - 1
for item in a:
    pm += item[1]
    if tmp > m_minus_1:
        print(s + item[0] * (m - pm + item[1]))
        break
    else:
        s += item[0] * item[1]


Fixed code:
n, m = map(int, input().split())
a = []
for _ in range(n):
    a.append(list(map(int, input().split())))
a.sort()
pm = s = 0
for item in a:
    if pm + item[1] >= m:
        print(s + item[0] * (m - pm))
        break
    else:
        pm += item[1]
        s += item[0] * item[1]
Buggy code:
#C
n,m = map(int, input().split())
ab = [[int(i) for i in input().split()] for i in range(n)]

ab.sort(key=lambda x:x[0])
cost = 0
for i in range(m):
    value = ab[i][0]
    num = ab[i][1]
    if num> m:
        cost += value*m
        break
    else:
        cost += value*num
        m -= num
print(cost)

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

ab.sort(key=lambda x:x[0])
cost = 0
for i in range(n):
    value = ab[i][0]
    num = ab[i][1]
    if num> m:
        cost += value*m
        break
    else:
        cost += value*num
        m -= num
print(cost)
Buggy code:
n,m=map(int,input().split())
AB=[]
for i in range(n):
  a,b=map(int,input().split())
  AB.append([a,b])
AB=sorted(AB)
i=0
amount=0
cost=0
while True:
  if amount+AB[i][1]<=m:
    amount+=AB[i][1]
    cost+=AB[i][0]*AB[i][1]
    i+=1
  else:
    cost+=(m-amount)*AB[i][0]
    print(cost)
    break

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=sorted(AB)
i=0
amount=0
cost=0
while True:
  if amount+AB[i][1]<m:
    amount+=AB[i][1]
    cost+=AB[i][0]*AB[i][1]
    i+=1
  else:
    cost+=(m-amount)*AB[i][0]
    print(cost)
    break
Buggy code:
n,m=map(int,input().split())
A=[]
for i in range(n):
  a,b=map(int,input().split())
  A.append([a,b])

A=sorted(A,key=lambda x:x[0])
ko=0
pri=0
i=0
while ko<=m:
  pri+=A[i][0]*A[i][1]
  ko+=A[i][1]
  i+=1
print(pri-(ko-m)*A[i-1][0])

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

A=sorted(A,key=lambda x:x[0])
ko=0
pri=0
i=0
while ko<=m:
  pri+=A[i][0]*A[i][1]
  ko+=A[i][1]
  i+=1
  if ko==m:
    print(pri)
    exit()
print(pri-(ko-m)*A[i-1][0])
Buggy code:
class Shop():
    def __init__(self, a, b):
        self.a = a
        self.b = b

N, M = [ int(x) for x in input().split(' ')]
shops = []
for i in range(N):
    a, b = [int(x) for x in input().split(' ')]
    shops.append(Shop(a, b))

shops.sort(key=lambda x: x.a)

cost = 0
bought = 0
for i in range(N):
    shop = shops[i]
    print(i, cost, bought, shop.a, shop.b)
    if (shop.b <= M - bought):
        cost += shop.a * shop.b
        bought += shop.b
    else:
        cost += shop.a * (M - bought)
        bought += (M - bought)
    if (bought == M):
        break

print(cost)


Fixed code:
class Shop():
    def __init__(self, a, b):
        self.a = a
        self.b = b

N, M = [ int(x) for x in input().split(' ')]
shops = []
for i in range(N):
    a, b = [int(x) for x in input().split(' ')]
    shops.append(Shop(a, b))

shops.sort(key=lambda x: x.a)

cost = 0
bought = 0
for i in range(N):
    shop = shops[i]
    if (shop.b <= M - bought):
        cost += shop.a * shop.b
        bought += shop.b
    else:
        cost += shop.a * (M - bought)
        bought += (M - bought)
    if (bought == M):
        break

print(cost)
Buggy code:
from operator import itemgetter

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

e = [[int(i) for i in input().split()] for i in range(n)] 

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

money = 0
mcount = m

for i in e:
    mcount -= i[1]
    if mcount >= 0:
        money += i[0] * i[1]
    else :
        money += i[0] * (i[1] + mcount) 
        print(money)
        break


Fixed code:
from operator import itemgetter

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

e = [[int(i) for i in input().split()] for i in range(n)] 

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

money = 0
mcount = m
isend = True

for i in e:
    mcount -= i[1]
    if mcount >= 0:
        money += i[0] * i[1]
    else :
        money += i[0] * (i[1] + mcount) 
        print(money)
        isend = False
        break

if isend == True:
    print(money)
Buggy code:
n,m=[int(i) for i in input().split()]

mise={}
for i in range(n):
    a,b=[int(j) for j in input().split()]
    if a in mise:
        mise[a]+=b
    else:
        mise[a]=b
nedan=list(mise.keys())
nedan.sort()
i=0
ans=0
while m:
    honnsuu=mise[nedan[i]]
    kauno=min(honnsuu,m)
    ans+=kauno*nedan[i]
    i+=1
    m=m-kauno
print(mise)    
print(nedan)
print(ans)

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

mise={}
for i in range(n):
    a,b=[int(j) for j in input().split()]
    if a in mise:
        mise[a]+=b
    else:
        mise[a]=b
nedan=list(mise.keys())
nedan.sort()
i=0
ans=0
while m:
    honnsuu=mise[nedan[i]]
    kauno=min(honnsuu,m)
    ans+=kauno*nedan[i]
    i+=1
    m=m-kauno

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

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

AB.sort()
count = 0
ans = 0
for i,j in AB:
  if count+j >= M:
    ans += (M-count)*i
    break
  else:
    count += j
    ans += j*i
  print(ans)

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

AB.sort()
count = 0
ans = 0
for i,j in AB:
  if count+j >= M:
    ans += (M-count)*i
    break
  else:
    count += j
    ans += j*i
print(ans)
Buggy code:
from operator import itemgetter
N,M = map(int,input().split())
ls = [list(map(int,input().split())) for _ in range(N)]
ls = sorted(ls,key=itemgetter(0))
ans = 0
pon = 0
for i in range(N):
    if pon < M:
        pon += ls[i][1]
        ans += ls[i][1]*ls[i][0]
    else:
        break
if pon == M:
    print(ans)
else:
    ans -= ls[i-1][0]*(pon - M)
    print(ans)

Fixed code:
from operator import itemgetter
N,M = map(int,input().split())
ls = [list(map(int,input().split())) for _ in range(N)]
ls = sorted(ls,key=itemgetter(0))
ans = 0
pon = 0
for i in range(N):
    if pon < M:
        pon += ls[i][1]
        ans += ls[i][1]*ls[i][0]
    else:
        i = i-1
        break
if pon == M:
    print(ans)
else:
    ans -= ls[i][0]*(pon - M)
    print(ans)
Buggy code:
# coding: utf-8
from sys import stdin.readline as input
 
N, M = [int(i) for i in input().split()]
 
plices = [[int(i) for i in input().split()] for _ in range(N)]
 
plices.sort(key = lambda x:x[0])
 
m = 0
cost = 0
 
for i in range(N):
    if m >= M:
        break
    buy = min(M - m, plices[i][1])
    cost += plices[i][0] * buy
    m += buy
 
print(cost)

Fixed code:
# coding: utf-8
import sys
input = sys.stdin.readline

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

plices = [[int(i) for i in input().split()] for _ in range(N)]

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

m = 0
cost = 0

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

print(cost)
Buggy code:
N,M=map(int,input().split())
shop=[]
for _ in range(N):
    a=list(map(int,input().split()))
    shop.append(a)
shop.sort(key=lambda x: x[0])
cnt=0
p=0
i=0

while cnt<=M:
    a=shop[i][0]
    b=shop[i][1]
    cnt+=b
    p+=a*b
    i+=1
su=cnt-M

a = shop[i-1][0]
p-=a*su
print(p)


Fixed code:
N,M=map(int,input().split())
shop=[]
for _ in range(N):
    a=list(map(int,input().split()))
    shop.append(a)
shop.sort(key=lambda x: x[0])
cnt=0
p=0
i=0

while cnt<M:
    a=shop[i][0]
    b=shop[i][1]
    cnt+=b
    p+=a*b
    i+=1
su=cnt-M

a = shop[i-1][0]
p-=a*su
print(p)