Buggy python submission (verdict: Time Limit Exceeded):
n,m = map(int,input().split())
a,b = [0 for _ in range(n)],[0 for _ in range(n)]

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

bought = 0
ans = 0

if len(a) == 1:
    print(a[0]*m)
    exit()

while(bought <= m):
    remain = m - bought
    amin = min(a)
    bmin = b[a.index(amin)]
    if bmin <= remain:
        ans += amin*bmin
        bought += bmin
        b.remove(bmin)
        a.remove(amin)
    else:
        ans += amin*remain
        break
print(ans)

Fixed submission:
n,m = map(int,input().split())
a = []
for i in range(n):
    a.append(list(map(int,input().split())))
a.sort(key = lambda a:a[0])
bought = 0
price = 0
for i in range(n):
    remain = m - bought
    if a[i][1] < remain:
        bought += a[i][1]
        price += a[i][0] * a[i][1]
    else:
        price += a[i][0]*remain
        print(price)
        exit()

Buggy python submission (verdict: Time Limit Exceeded):
n,m = map(int,input().split())
a,b = [0 for _ in range(n)],[0 for _ in range(n)]

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

bought = 0
ans = 0

if len(a) == 1:
    print(a[0]*m)
    exit()
    
while(bought <= m):
    remain = m - bought
    if b[a.index(min(a))] <= remain:
        ans += min(a)*b[a.index(min(a))]
        bought += b[a.index(min(a))]
        b.remove(b[a.index(min(a))])
        a.remove(min(a))
    else:
        ans += min(a)*remain
        break
print(ans)

Fixed submission:
n,m = map(int,input().split())
a = []
for i in range(n):
    a.append(list(map(int,input().split())))
a.sort(key = lambda a:a[0])
bought = 0
price = 0
for i in range(n):
    remain = m - bought
    if a[i][1] < remain:
        bought += a[i][1]
        price += a[i][0] * a[i][1]
    else:
        price += a[i][0]*remain
        print(price)
        exit()

Buggy python submission (verdict: Time Limit Exceeded):
n,m = map(int,input().split())
a,b = [0 for _ in range(n)],[0 for _ in range(n)]

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

bought = 0
ans = 0
if len(a) == 1:
    print(a[0]*m)
    exit()
while(bought <= m):
    remain = m - bought
    if b[a.index(min(a))] <= remain:
        ans += min(a)*b[a.index(min(a))]
        bought += b[a.index(min(a))]
        b.remove(b[a.index(min(a))])
        a.remove(min(a))
    else:
        ans += min(a)*remain
        break
print(ans)

Fixed submission:
n,m = map(int,input().split())
a = []
for i in range(n):
    a.append(list(map(int,input().split())))
a.sort(key = lambda a:a[0])
bought = 0
price = 0
for i in range(n):
    remain = m - bought
    if a[i][1] < remain:
        bought += a[i][1]
        price += a[i][0] * a[i][1]
    else:
        price += a[i][0]*remain
        print(price)
        exit()

Buggy python submission (verdict: Runtime Error):
n,m = map(int,input().split())
a,b = [0 for _ in range(n)],[0 for _ in range(n)]

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

bought = 0
ans = 0
while(bought <= m):
    remain = m - bought
    if b[a.index(min(a))] <= remain:
        ans += min(a)*b[a.index(min(a))]
        bought += b[a.index(min(a))]
        b.remove(b[a.index(min(a))])
        a.remove(min(a))
    else:
        ans += min(a)*remain
        break
print(ans)

Fixed submission:
n,m = map(int,input().split())
a = []
for i in range(n):
    a.append(list(map(int,input().split())))
a.sort(key = lambda a:a[0])
bought = 0
price = 0
for i in range(n):
    remain = m - bought
    if a[i][1] < remain:
        bought += a[i][1]
        price += a[i][0] * a[i][1]
    else:
        price += a[i][0]*remain
        print(price)
        exit()