qyliang/CodeNanoFix huggingface dataset:
Buggy code:
n, m = (int(i) for i in input().split())
a = [list(map(int,input().split())) for i in range(n)]
b = sorted(a)
cnt = 0
money = 0
print(b)

while True:
	for x,y in b:
		cnt += y
		money += x * y
		print(money)
		if m < cnt:
			money -= (cnt - m)*x
			print(money)
			exit()

Fixed code:
n, m = (int(i) for i in input().split())
a = [list(map(int,input().split())) for i in range(n)]
b = sorted(a)
cnt = 0
money = 0
while True:
	for x,y in b:
		cnt += y
		money += x * y
		if m < cnt:
			money -= (cnt - m)*x
			print(money)
			exit()
Buggy code:
N,M = list(map(int, input().split()))
AB = []
for i in range(N):
    AB.append(list(map(int, input().split())))
AB = sorted(AB)

n = 0
result = 0

while True:
    if AB[n][1] <= M:
        result += AB[n][0] * AB[n][1]
        M -= AB[n][1]
        n += 1
    else:
        result += AB[n][0] * M
        break

print(result)

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

n = 0
result = 0

while M > 0:
    if AB[n][1] <= M:
        result += AB[n][0] * AB[n][1]
        M -= AB[n][1]
        n += 1
    else:
        result += AB[n][0] * M
        break

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

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


total =0
cost = 0
for a, b in sorted(data, key=lambda x:x[0]):
#     print(a, b)
    if total + b < m:
        total += b
        cost += a*b
    else:
        cost += a*(m-total)
print(cost)

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

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


total =0
cost = 0
for a, b in sorted(data, key=lambda x:x[0]):
    #print(a, b)
    if total + b < m:
        total += b
        cost += a*b
    else:
        cost += a*(m-total)
        break
print(cost)
Buggy code:
import numpy as np

N, M = map(int, input().split())
a = [input().split() for i in range(N)]
# a = [[int(i[0]), int(i[1])] for i in a]
a = np.array(a, dtype='int64')
a = a[a[:, 0].argsort(), :]
print(a)

mysum = 0
coin = 0
for c in a:
    if mysum + c[1] < M:
        mysum += c[1]
        coin += c[0] * c[1]
    else:
        d = M - mysum
        coin += d * c[0]
        break

print(coin)

Fixed code:
import numpy as np

N, M = map(int, input().split())
a = [input().split() for i in range(N)]
# a = [[int(i[0]), int(i[1])] for i in a]
a = np.array(a, dtype='int64')
a = a[a[:, 0].argsort(), :]

mysum = 0
coin = 0
for c in a:
    if mysum + c[1] < M:
        mysum += c[1]
        coin += c[0] * c[1]
    else:
        d = M - mysum
        coin += d * c[0]
        break

print(coin)
Buggy code:
def main():
    N, M = map(int, input().split())
    store = list()
    for i in range(N):
        A, B = map(int, input().split())
        store.append([A, B])
    store.sort(key = lambda x : x[0])
    cost = 0
    drink = 0
    print(store)
    for i in range(N):
        if drink < M:
            if drink + store[i][1] < M:
                drink += store[i][1]
                cost += store[i][0] * store[i][1]
            else:
                cost += store[i][0] * (M - drink)
                drink += M - drink
        else:
            break
    print(cost)
if __name__ == "__main__":
    main()

Fixed code:
def main():
    N, M = map(int, input().split())
    store = list()
    for i in range(N):
        A, B = map(int, input().split())
        store.append([A, B])
    store.sort(key = lambda x : x[0])
    cost = 0
    drink = 0
    for i in range(N):
        if drink < M:
            if drink + store[i][1] < M:
                drink += store[i][1]
                cost += store[i][0] * store[i][1]
            else:
                cost += store[i][0] * (M - drink)
                drink += M - drink
        else:
            break
    print(cost)
if __name__ == "__main__":
    main()
Buggy code:
n,m = map(int, input().split())
l = [list(map(int,input().split)) for _ in range(n)]
cnt = 0
ans = 0
l.sort(key=lambda x:x[0])
for i in range(n):
    cnt += l[i][1]
    ans += l[i][0] * l[i][1]
    if cnt > m:
        ans -= l[i][0] * l[i][1]
        ans += l[i][0]*(m-(cnt-l[i][1]))
print(ans)

Fixed code:
n,m = map(int, input().split())
l = [list(map(int,input().split())) for _ in range(n)]
cnt = 0
ans = 0
l.sort(key=lambda x:x[0])
for i in range(n):
    cnt += l[i][1]
    ans += l[i][0] * l[i][1]
    if cnt > m:
        ans -= l[i][0] * l[i][1]
        ans += l[i][0]*(m-(cnt-l[i][1]))
        break
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()
totl=0
x=0
for j,k in range(a):
  if x+j<m:
    totl+=j*k
    x+=k
  else:
    totl+=j*(x-m)
    break
print(totl)
    
    
  
  

Fixed code:
n,m=map(int,input().split())
a=[]
for i in range(n):
  a.append(list(map(int,input().split())))
a.sort()
totl=0
x=0
for j,k in a:
  if x+k<m:
    totl+=j*k
    x+=k
  else:
    totl+=j*(m-x)
    break
print(totl)
Buggy code:
# C
n, m = map(int, input().split())
ab = [0, 0] * n
for i in range(n):
    ab[i] = map(int, input().split())
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)

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())
X = []
for i in range(N):
	X.append(list(map(int, input().split())))

#Sorted by first element
X.sort(key=lambda x:x[0])
i = 0
total = 0
ans = 0

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

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

#Sorted by first element
X.sort(key=lambda x: x[0])
i = 0
total = 0
ans = 0

while i <= N-1:
	total += X[i][1]
	ans += X[i][0] * X[i][1]
	if total > M:
		ans -= X[i][0] * (total-M)
		break
	i += 1
print(ans)
Buggy code:
n, m = map(int, input().split())
a, b = [], []
for i in range(n):
    te, mp = map(int, input().split())
    a.append(te)
    b.append(mp)

e, f = [], []
for i, j in sorted(zip(a, b)):
    e.append(i)
    f.append(j)

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


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

e, f = [], []
for i, j in sorted(zip(a, b)):
    e.append(i)
    f.append(j)

ans = 0
for i in range(n):
    if m - f[i] <= 0:
        ans += e[i] * m
        print(ans)
        exit()
    else:
        ans += f[i] * e[i]
        m -= f[i]
print(ans)
Buggy code:
n,m = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n)]
ab.sort()
cost=0
amount=m
for i in range(n):
    if amount>0:
        print('am:',amount)
        if amount > ab[i][1]:
            cost+=ab[i][0]*ab[i][1]
            amount-=ab[i][1]
        else:
            cost+=ab[i][0]*amount
            break
print(cost)


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

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

Fixed code:
n, m = map(int, input().split())
ab = sorted([ list(map(int, input().split())) for _ in range(n) ])
c = 0
for a, b in ab:
  if m <= b:
    c += a*m
    print(c)
    break
  else:
    c += a*b
    m -= b
Buggy code:
N, M = map(int, input().split())
AB = [[0, 0]]*N
for i in range(N):
    AB[i][0], AB[i][1] = map(int, input().split())

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


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

AB = sorted(AB)
ans = 0
for i in AB:
    if M - i[1] >= 0:
        ans += i[0] * i[1]
        M -= i[1]
    else:
        ans += M * i[0]
        break
print(ans)
Buggy code:
n, m = map(int, input().split())
sum = 0
money = 0
list_ab = list()
for i in range(n):
    list_ab.append(list(map(int, input().split())))
list_ab = sorted(list_ab)
for i in range(n):
    print(i)
    if(list_ab[i][1] >= m - sum):
        money += list_ab[i][0] * (m - sum)
        break
    else:
        sum += list_ab[i][1]
        money += list_ab[i][0]*list_ab[i][1]
print(money)


Fixed code:
n, m = map(int, input().split())
sum = 0
money = 0
list_ab = list()
for i in range(n):
    list_ab.append(list(map(int, input().split())))
list_ab = sorted(list_ab)
for i in range(n):
    if(list_ab[i][1] >= m - sum):
        money += list_ab[i][0] * (m - sum)
        break
    else:
        sum += list_ab[i][1]
        money += list_ab[i][0]*list_ab[i][1]
print(money)
Buggy code:
from pprint import pprint
def main():
    N,M = map(int,input().split())
    store_l = []
    for i in range(N):
        store_l.append(tuple(map(int,input().split())))

    store_l = sorted(store_l,key=lambda x:x[0])
    pprint(store_l)
    ans = 0
    buynum = 0
    for price,maxnum in store_l:
        if(buynum+maxnum<=M):
            buynum += maxnum
            ans += maxnum*price
        else:
            ans += (M-buynum)*price
            break
    print(ans)

if __name__=="__main__":
    main()


Fixed code:
def main():
    N,M = map(int,input().split())
    store_l = []
    for i in range(N):
        store_l.append(tuple(map(int,input().split())))

    store_l = sorted(store_l,key=lambda x:x[0])
    ans = 0
    buynum = 0
    for price,maxnum in store_l:
        if(buynum+maxnum<=M):
            buynum += maxnum
            ans += maxnum*price
        else:
            ans += (M-buynum)*price
            break
    print(ans)

if __name__=="__main__":
    main()
Buggy code:
N,M=list(map(int,input().split(" ")))
l=[]
l=[list(map(int,input().split(" "))) for i in range(n)]
drink=0
price=0
i=0
l.sort(key=lambda x: x[0])
while drink<M:
    pri=l[i][0]
    num=l[i][1]
    i+=1
    drink+=num
    price+=pri*num
if drink>M:
    price-=(drink-m)*pri
print(price)


Fixed code:
n,m=list(map(int,input().split(" ")))
l=[]
l=[list(map(int,input().split(" "))) for i in range(n)]
drink=0
price=0
i=0
l.sort(key=lambda x: x[0])
while drink<m:
    pri=l[i][0]
    num=l[i][1]
    i+=1
    drink+=num
    price+=pri*num
if drink>m:
    price-=(drink-m)*pri
print(price)
Buggy code:
n,m = map(int,input().split())
lis = [list(map(int,input().split())) for i in range(n)]
lis.sort()
cnt = 0
mon = 0
i = 0
if n >= 2:
    while cnt <= m:
        if lis[i][1] + cnt <= m:
            cnt += lis[i][1]
            mon += lis[i][0]*lis[i][1]
            i += 1
        else:
            break
    print(mon + (m-cnt) * lis[i][0])
print(m*lis[0][0])


Fixed code:
n,m = map(int,input().split())
lis = [list(map(int,input().split())) for i in range(n)]
lis.sort()
cnt = 0
mon = 0
i = 0
if n >= 2:
    while cnt < m:
        if lis[i][1] + cnt < m:
            cnt += lis[i][1]
            mon += lis[i][0]*lis[i][1]
            i += 1
        else:
            break
    print(mon + (m-cnt) * lis[i][0])
else:
    print(m*lis[0][0])
Buggy code:
n,m = map(int,input().split())
AB = [list(map(int,input().split())) for i in range(n)]
AB.sort(reverse = True)
c = 0
ans = 0
i = 0
while c < m:
  if  c + AB[i][1] <= m:
    c += AB[i][1]
    ans += AB[i][0]*AB[i][1]
    i += 1
  else:
    ans += Ab[i][0]*(m-c)
    break

print(ans)

Fixed code:
n,m = map(int,input().split())
AB = [list(map(int,input().split())) for i in range(n)]
AB.sort()
c = 0
ans = 0
i = 0
while c < m:
  if  c + AB[i][1] <= m:
    c += AB[i][1]
    ans += AB[i][0]*AB[i][1]
    i += 1
  else:
    ans += AB[i][0]*(m-c)
    break

print(ans)
Buggy code:
n,m = map(int,input().split())
ab = [list(map(int,input().split())) for _ in range(n)]
ab = sorted(ab, key=lambda x:x[0])
print(ab)
ans = 0
d = 0
i = 0
while d < m:
  ans += ab[i][0]*min(m-d,ab[i][1])
  d += ab[i][1]
  i += 1
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 x:x[0])
ans = 0
d = 0
i = 0
while d < m:
  ans += ab[i][0]*min(m-d,ab[i][1])
  d += ab[i][1]
  i += 1
print(ans)
Buggy code:
def main():
  n, m = map(int, input().split())
  shops = sorted([list(map(int, input().split())) for i in range(n)])
  
  cost = 0
  got = 0
  for shop in shops:
    if got + shop[1] <= m:
      got += shop[1]
      cost += shop[0] * shop[1]
    else:
      cost += (m - got) * shop[0]
      break
  print(cost)
  

if __init__ == '__main__':
  main()

Fixed code:
def main():
  n, m = map(int, input().split())
  shops = sorted([list(map(int, input().split())) for i in range(n)])
  
  cost = 0
  got = 0
  for shop in shops:
    if got + shop[1] <= m:
      got += shop[1]
      cost += shop[0] * shop[1]
    else:
      cost += (m - got) * shop[0]
      break
  print(cost)
  

if __name__ == '__main__':
  main()
Buggy code:
nm, left = map(int, input().split())
shops = []
for _ in range(nm):
    shops.append([int(x) for x in input().split()])
shops.sort(key=lambda x: x[0])
#print(shops)
total_cost = 0
for cost, stock in shops:
    if stock >= left:
        print("final : " + str(total_cost + cost * left))
        exit(0)
    else:
        left = left - stock
        total_cost += cost * stock
        #print("current : " + str(total_cost))


Fixed code:
nm, left = map(int, input().split())
shops = []
for _ in range(nm):
    shops.append([int(x) for x in input().split()])
shops.sort(key=lambda x: x[0])
#print(shops)
total_cost = 0
for cost, stock in shops:
    if stock >= left:
        print(total_cost + cost * left)
        exit(0)
    else:
        left = left - stock
        total_cost += cost * stock
        #print("current : " + str(total_cost))
Buggy code:
N,M=map(int, input().split())
A,B=[],[]
for i in range(N):
    A.append(list(map(int, input().split())))
A.sort(key=lambda x:x[0])
R,S=M,0
for a in A:
    if a[1]>=R:
        print(a[0],R)
        S+=a[0]*R;R=0
    else:
        print(a[0],a[1])
        S+=a[0]*a[1];R-=a[1]
    if R==0: break
print(S)



Fixed code:
N,M=map(int, input().split())
A,B=[],[]
for i in range(N):
    A.append(list(map(int, input().split())))
A.sort(key=lambda x:x[0])
R,S=M,0
for a in A:
    if a[1]>=R:
        S+=a[0]*R;R=0
    else:
        S+=a[0]*a[1];R-=a[1]
    if R==0: break
print(S)
Buggy code:
N, M = map(int, input().split())
List = [list(map(int, input().split())) for _ in range(N)]

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

amt = 0
money = 0
i=0
while amt<=M:
    money+=List[i][0]*List[i][1]
    amt+=List[i][1]
    i+=1
    
ans = money-(amt-M)*List[i-1][0]
print(ans)

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

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

amt = 0
money = 0
i=0
while amt<M:
    money+=List[i][0]*List[i][1]
    amt+=List[i][1]
    i+=1

ans = money-(amt-M)*List[i-1][0]
print(ans)
Buggy code:
N,M = list(map(int,input().split()))
A = [tuple(map(int,input().split())) for _ in range(N)]
sortA = sorted(A,key= lambda x: x[0])
ans = 0
for i in range(N):
    if M-sortA[i][1]>0:
        ans += sortA[i][0]*sortA[i][1]
        M = M-sortA[i][1]
    else:
        ans += M*sortA[i][0]
print(ans)

Fixed code:
N,M = list(map(int,input().split()))
A = [tuple(map(int,input().split())) for _ in range(N)]
sortA = sorted(A,key= lambda x: x[0])
ans = 0
for i in range(N):
    if M-sortA[i][1]>0:
        ans += sortA[i][0]*sortA[i][1]
        M = M-sortA[i][1]
    else:
        ans += M*sortA[i][0]
        break
print(ans)
Buggy code:
import numpy as np

N, M = map(int, input().split())
AB = []
for i in range(N):
    AB.append(list(map(int, input().split())))
    
AB = np.array(AB)
AB_sorted = AB[AB[:,0].argsort(),:]

cs = np.cumsum(AB_sorted[:,1])
n_full_store = (cs <= M).sum()
money_a = np.sum(AB_sorted[:n_full_store,0] * AB_sorted[:n_full_store,1])
money_b = (M - cs[n_full_store-1]) * AB_sorted[n_full_store,0]
print(money_a + money_b)

Fixed code:
import numpy as np

N, M = map(int, input().split())
AB = []
for i in range(N):
    AB.append(list(map(int, input().split())))
    
AB = np.array(AB)
AB_sorted = AB[AB[:,0].argsort(),:]

cs = np.cumsum(AB_sorted[:,1])
n_full_store = (cs <= M).sum()
money_a = np.sum(AB_sorted[:n_full_store,0] * AB_sorted[:n_full_store,1])
if M - cs[n_full_store-1] > 0:
    money_b = (M - cs[n_full_store-1]) * AB_sorted[n_full_store,0]
elif M - cs[n_full_store-1] < 0:
               money_b = AB_sorted[0,0] * M
else:
    money_b = 0
print(money_a + money_b)
Buggy code:
n,m = map(int,input().split())
x = [list(map(int,input().split())) for i in range(n)]
x = sorted(x,key=lambda x:x[0])
t = x[0][1]
res = 0
ans = 0
for i in range(n):
    res += x[i][1]
    ans += x[i][0]*x[i][1]
    if m-res<0:
        print(ans-((res-m)*x[i][0]))
        exit()

Fixed code:
n,m = map(int,input().split())
x = [list(map(int,input().split())) for i in range(n)]
x = sorted(x,key=lambda x:x[0])
t = x[0][1]
res = 0
ans = 0
for i in range(n):
    res += x[i][1]
    ans += x[i][0]*x[i][1]
    if m-res<=0:
        print(ans-((res-m)*x[i][0]))
        exit()
Buggy code:
N, M  = map(int, input().split())
A = [lsit(map(int, input().split())) for _ in range(N)]
B = sorted(A, key = lambda x:x[0])
hon = 0
cost = 0
for i in range(N):
  hon += B[i][1]
  if hon >= M:
    cost += B[i][0]*(B[i][1]-(hon-M))
    break
  else:
    cost += B[i][0]*B[i][1]
print(cost)

Fixed code:
N, M  = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(N)]
B = sorted(A, key = lambda x:x[0])
hon = 0
cost = 0
for i in range(N):
  hon += B[i][1]
  if hon >= M:
    cost += B[i][0]*(B[i][1]-(hon-M))
    break
  else:
    cost += B[i][0]*B[i][1]
print(cost)
Buggy code:
N,M=map(int,input().split())
AB=[list(map(int,input().split())) for _ in range(N)]

AB_s=sorted(AB)

ans=0
cnt=0
for a,b in AB_s:
    ans+=a*b
    cnt+=b
    if cnt>M:
        ans-=a*(cnt-M)
        print(ans)
        exit()

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

AB_s=sorted(AB)

ans=0
cnt=0
for a,b in AB_s:
    ans+=a*b
    cnt+=b
    if cnt>=M:
        ans-=a*(cnt-M)
        print(ans)
        exit()
Buggy code:
N, M = list(map(int, input().split()))
L = [tuple(map(int, input().split())) for i in range(N)]
L.sort()
print(L)
ct = 0
cost = 0
i = 0
while ct < M:
    a = min(M-ct, L[i][1])
    ct += a
    cost += a*L[i][0]
    # print(ct,cost)
    i += 1
print(cost)


Fixed code:
N, M = list(map(int, input().split()))
L = [tuple(map(int, input().split())) for i in range(N)]
L.sort()
# print(L)
ct = 0
cost = 0
i = 0
while ct < M:
    a = min(M-ct, L[i][1])
    ct += a
    cost += a*L[i][0]
    # print(ct,cost)
    i += 1
print(cost)
Buggy code:
N,M=map(int,input().split())
A=dict()
ans=0
for i in range(N):
    a,b=map(int,input().split())
    A[a]=b
A=list(A.items())
A.sort()
for i in range(N):
    if M>=A[i][0]:
        M-=A[i][1]
        ans+=A[i][0]*A[i][1]
    else:
        ans+=A[i][0]*M
        break
print(ans)


Fixed code:
N,M=map(int,input().split())
A=dict()
ans=0
A=[list(map(int,input().split()))for i in range(N)]
A.sort()
for i in range(N):
    if M>A[i][1]:
        M-=A[i][1]
        ans+=A[i][0]*A[i][1]
    else:
        ans+=A[i][0]*M
        break
print(ans)
Buggy code:
N, M = [int(i) for i in input().split()]
cost = 0
amount =0
dic ={}
for _ in range(N):
    a,b = [int(i) for i in input().split()]
    dic[a] = b

for a,b in dic.items():
    if amount+b<=M:
        amount += b
        cost += a*b
    else:
        rest = M - amount
        cost += a*rest
        break

print(cost)


Fixed code:
N, M = [int(i) for i in input().split()]
cost = 0
amount =0
dic ={}
for _ in range(N):
    a,b = [int(i) for i in input().split()]
    if a in dic:
        dic[a] += b
    else:
        dic[a] = b

dic = sorted(dic.items())

for a,b in dic:
    if amount+b<=M:
        amount += b
        cost += a*b
    else:
        rest = M - amount
        cost += a*rest
        break

print(cost)
Buggy code:
from operator import itemgetter
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=itemgetter(1))
s=0
for j in range(n):
  s=s+l[j][0]*min(l[j][1],m)
  m=m-l[j][1]
  if m<0:
    break
print(s) 

Fixed code:
from operator import itemgetter
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=itemgetter(0))
s=0
for j in range(n):
  s=s+l[j][0]*min(l[j][1],m)
  m=m-l[j][1]
  if m<0:
    break
print(s)
Buggy code:
N, M = map(int, input().split()) 
A = [list(map(int, input().split())) for i in range(N)]
A.sort()
su = 0
mo = 0
cnt = 0
for i in range(N):
  if M < su + A[i][1]:
    break
  else:
    su += A[i][1]
    mo += A[i][0]*A[i][1]
    cnt += 1
print(mo + (M-su)*A[cnt][0])

Fixed code:
N, M = map(int, input().split())
A = [list(map(int, input().split())) for i in range(N)]
A.sort()
su = 0
mo = 0
cnt = 0
for i in range(N):
  if M <= su + A[i][1]:
    break
  else:
    su += A[i][1]
    mo += A[i][0]*A[i][1]
    cnt += 1
print(mo + (M-su)*A[cnt][0])
Buggy code:
import sys

if sys.platform =='ios':
    sys.stdin=open('input_file.txt')
   
a,b,c=map(int,input().split())
print(min((-((-b)//a)),c))

Fixed code:
import sys

if sys.platform =='ios':
    sys.stdin=open('input_file.txt')
   
a,b,c=map(int,input().split())
print(min((b//a),c))
Buggy code:
a,b,c=map(int,input().split())
if a//b > c:
  print(c)
else:
  print(a//b)

Fixed code:
a, b, c = map(int, input().split())
if b // a >= c:
  print(c)
else:
  print(b // a)
Buggy code:
A, B, C = map(int, input().split())

K = A // B

if K > C:
    print(C)
else:
    print(K)


Fixed code:
A, B, C = map(int, input().split())

K = B // A

if K > C:
    print(C)
else:
    print(K)
Buggy code:
a,b,c = map(int,input().split)
print(min(b//a,c))


Fixed code:
a,b,c=map(int, input().split())
print(min(c,b//a))
Buggy code:
a,b,c = map(int, input().split())
tmp = b/a
if tmp >= c:
    print(c)
else :
    print(tmp)

Fixed code:
a,b,c = map(int, input().split())

if b//a > c:
    print(c)
else:
    print(b//a)
Buggy code:
a, b, c = map(int, input().split())
n = int(b/a)
print(n if b <= c else c)  

Fixed code:
a,b,c = map(int,input().split())
print( c if c<=b//a else b//a )
Buggy code:
a,b,c = map(int,input().split())

if (b / a) > c:
    print(c)
else:
    print(b / a)
    


Fixed code:
a,b,c = map(int,input().split())

sound_count = b//a

if b//a > c:
  print(c)
else:
  print(b//a)
Buggy code:
a, b, c=map(int, input().split())
if a-b*c>=0:
  print(c)
else:
  print(b//a)

Fixed code:
a, b, c=map(int, input().split())
if b-a*c>=0:
  print(c)
else:
  print(b//a)
Buggy code:
A,B,C = [int(s) for s in input().split()]

print(C) if B B//A >= C else print(B//A)

Fixed code:
A,B,C = [int(s) for s in input().split()]
 
print(C) if B//A >= C else print(B//A)