Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split(" "))
stores = dict()
p = 10000000000

for i in range(N):
    if p==1 and stores[p] >= M:
      break
    Ai, Bi = map(int, input().split(" "))
    if Ai in stores:
        stores[Ai] += Bi
    else:
        stores[Ai] = Bi
    p = min(p, Ai)


price = 0
for i, c in sorted(stores, key=lambda x: x[0]):
    if M <= c:
        price += i * M
        break
    else:
        price += i * c
        M -= c

print(price)


Fixed submission:
N, M = map(int, input().split(" "))
stores = []

for i in range(N):
    Ai, Bi = map(int, input().split(" "))
    stores.append((Ai, Bi))    

price = 0
for a, b in sorted(stores, key=lambda x: x[0]):
    if M <= b:
        price += a * M
        break
    else:
        price += a * b
        M -= b
print(price)

Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split(" "))
stores = dict()
p = 10000000000

for i in range(N):
    if p==1 and stores[p] >= M:
      break
    Ai, Bi = map(int, input().split(" "))
    if Ai in stores:
        stores[Ai] += Bi
    else:
        stores[Ai] = Bi
    p = min(p, Ai)


price = 0
while True:
    if p in stores:
        if M <= stores[p]:
            price += p * M
            break
        else:
            price += p * stores[p]
            M -= stores[p]
    p += 1
print(price)


Fixed submission:
N, M = map(int, input().split(" "))
stores = []

for i in range(N):
    Ai, Bi = map(int, input().split(" "))
    stores.append((Ai, Bi))    

price = 0
for a, b in sorted(stores, key=lambda x: x[0]):
    if M <= b:
        price += a * M
        break
    else:
        price += a * b
        M -= b
print(price)

Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split(" "))
stores = dict()
p = 10000000000

for i in range(N):
    Ai, Bi = map(int, input().split(" "))
    if Ai in stores:
        stores[Ai] += Bi
    else:
        stores[Ai] = Bi
    p = min(p, Ai)


price = 0
while True:
    if p in stores:
        if M <= stores[p]:
            price += p * M
            break
        else:
            price += p * stores[p]
            M -= stores[p]
    p += 1
print(price)

Fixed submission:
N, M = map(int, input().split(" "))
stores = []

for i in range(N):
    Ai, Bi = map(int, input().split(" "))
    stores.append((Ai, Bi))    

price = 0
for a, b in sorted(stores, key=lambda x: x[0]):
    if M <= b:
        price += a * M
        break
    else:
        price += a * b
        M -= b
print(price)

Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split(" "))
stores = dict()

for i in range(N):
    Ai, Bi = map(int, input().split(" "))
    if Ai in stores:
        stores[Ai] += Bi
    else:
        stores[Ai] = Bi

price = 0
for i in range(1, 10000000000):
    if i in stores:
        if M <= stores[i]:
            price += i * M
            break
        else:
            price += i * stores[i]
            M -= stores[i]
print(price)

Fixed submission:
N, M = map(int, input().split(" "))
stores = []

for i in range(N):
    Ai, Bi = map(int, input().split(" "))
    stores.append((Ai, Bi))    

price = 0
for a, b in sorted(stores, key=lambda x: x[0]):
    if M <= b:
        price += a * M
        break
    else:
        price += a * b
        M -= b
print(price)

Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split(" "))
stores = []
can_buy = False
for i in range(N):
    Ai, Bi = map(int, input().split(" "))
    if can_buy and Ai >= stores[-1][0]:
        continue
    stock = 0
    last_idx = -1
    tg_idx = -1
    for idx, s in enumerate(stores):
        if s[0] > Ai and tg_idx == -1:
            stock += Bi
            tg_idx = idx
        if stock < M:
            stock += s[1]
        else:
            last_idx = idx
            can_buy = True
            break
    if tg_idx != -1:
        stores.insert(tg_idx, (Ai, Bi))
    else:
        stores.append((Ai, Bi))
    if last_idx != -1:
        stores = stores[:last_idx+1]

price = 0
for store in stores:
    if M <= store[1]:
        price += store[0] * M
        break
    else:
        price += store[0] * store[1]
        M -= store[1]
print(price)


Fixed submission:
N, M = map(int, input().split(" "))
stores = []

for i in range(N):
    Ai, Bi = map(int, input().split(" "))
    stores.append((Ai, Bi))    

price = 0
for a, b in sorted(stores, key=lambda x: x[0]):
    if M <= b:
        price += a * M
        break
    else:
        price += a * b
        M -= b
print(price)

Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split(" "))
stores = []
can_buy = False
for i in range(N):
    Ai, Bi = map(int, input().split(" "))
    if can_buy and Ai > stores[-1][0]:
        continue
    stock = 0
    last_idx = -1
    tg_idx = -1
    for idx, s in enumerate(stores):
        if s[0] > Ai and tg_idx == -1:
            stock += Bi
            tg_idx = idx
        if stock < M:
            stock += s[1]
        else:
            last_idx = idx
            can_buy = True
            break
    if tg_idx != -1:
        stores.insert(tg_idx, (Ai, Bi))
    else:
        stores.append((Ai, Bi))
    if last_idx != -1:
        stores = stores[:last_idx+1]

price = 0
for store in stores:
    if M <= store[1]:
        price += store[0] * M
        break
    else:
        price += store[0] * store[1]
        M -= store[1]
print(price)


Fixed submission:
N, M = map(int, input().split(" "))
stores = []

for i in range(N):
    Ai, Bi = map(int, input().split(" "))
    stores.append((Ai, Bi))    

price = 0
for a, b in sorted(stores, key=lambda x: x[0]):
    if M <= b:
        price += a * M
        break
    else:
        price += a * b
        M -= b
print(price)

Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split(" "))
stores = []
for i in range(N):
    Ai, Bi = map(int, input().split(" "))
    stock = 0
    last_idx = -1
    tg_idx = -1
    for idx, s in enumerate(stores):
        if s[0] > Ai and tg_idx == -1:
          stock += Bi
          tg_idx = idx
        if stock < M:
            stock += s[1]
        else:
            last_idx = idx
            break
    if tg_idx != -1:
        stores.insert(tg_idx, (Ai, Bi))
    else:
        stores.append((Ai, Bi))
    if last_idx != -1:
        stores = stores[:last_idx+1]

price = 0
for store in stores:
    if M <= store[1]:
        price += store[0] * M
        break
    else:
        price += store[0] * store[1]
        M -= store[1]
print(price)


Fixed submission:
N, M = map(int, input().split(" "))
stores = []

for i in range(N):
    Ai, Bi = map(int, input().split(" "))
    stores.append((Ai, Bi))    

price = 0
for a, b in sorted(stores, key=lambda x: x[0]):
    if M <= b:
        price += a * M
        break
    else:
        price += a * b
        M -= b
print(price)

Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split(" "))
stores = []
for i in range(N):
    Ai, Bi = map(int, input().split(" "))
    tg_idx = -1
    for idx, s in enumerate(stores):
        if s[0] > Ai:
            tg_idx = idx
            break
    if tg_idx != -1:
        stores.insert(tg_idx, (Ai, Bi))
    else:
        stores.append((Ai, Bi))

    stock = 0
    unuse_idx = -1
    for idx, s in enumerate(stores):
        if stock <= M:
            stock += s[1]
        else:
            unuse_idx = idx
            break
    if unuse_idx != -1:
        stores = stores[:unuse_idx]

price = 0
for store in stores:
    if M <= store[1]:
        price += store[0] * M
        break
    else:
        price += store[0] * store[1]
        M -= store[1]
print(price)


Fixed submission:
N, M = map(int, input().split(" "))
stores = []

for i in range(N):
    Ai, Bi = map(int, input().split(" "))
    stores.append((Ai, Bi))    

price = 0
for a, b in sorted(stores, key=lambda x: x[0]):
    if M <= b:
        price += a * M
        break
    else:
        price += a * b
        M -= b
print(price)

Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split(" "))
stores = []
for i in range(N):
    Ai, Bi = map(int, input().split(" "))
    stock = 0
    unuse_idx = -1
    tg_idx = -1
    for idx, s in enumerate(stores):
        if stock <= M:
            stock += s[1]
        else:
            unuse_idx = idx
        if s[0] > Ai:
            if tg_idx == -1:
	            tg_idx = idx
    if unuse_idx != -1:
        stores = stores[:unuse_idx]
    if tg_idx != -1:
        stores.insert(tg_idx, (Ai, Bi))
    else:
        stores.append((Ai, Bi))

price = 0
for store in stores:
    if M <= store[1]:
        price += store[0] * M
        break
    else:
        price += store[0] * store[1]
        M -= store[1]
print(price)

Fixed submission:
N, M = map(int, input().split(" "))
stores = []

for i in range(N):
    Ai, Bi = map(int, input().split(" "))
    stores.append((Ai, Bi))    

price = 0
for a, b in sorted(stores, key=lambda x: x[0]):
    if M <= b:
        price += a * M
        break
    else:
        price += a * b
        M -= b
print(price)

Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split(" "))
stores = []
for i in range(N):
    Ai, Bi = map(int, input().split(" "))
    tg_idx = -1
    for idx, s in enumerate(stores):
        if s[0] > Ai:
            tg_idx = idx
            break
    if tg_idx != -1:
        stores.insert(tg_idx, (Ai, Bi))
    else:
        stores.append((Ai, Bi))

    stock = 0
    unuse_idx = -1
    for idx, s in enumerate(stores):
        if stock <= M:
            stock += s[1]
        else:
            unuse_idx = idx
    if unuse_idx != -1:
        stores = stores[:unuse_idx]

price = 0
for store in stores:
    if M <= store[1]:
        price += store[0] * M
        break
    else:
        price += store[0] * store[1]
        M -= store[1]
print(price)


Fixed submission:
N, M = map(int, input().split(" "))
stores = []

for i in range(N):
    Ai, Bi = map(int, input().split(" "))
    stores.append((Ai, Bi))    

price = 0
for a, b in sorted(stores, key=lambda x: x[0]):
    if M <= b:
        price += a * M
        break
    else:
        price += a * b
        M -= b
print(price)

Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split(" "))
stores = []
for i in range(N):
    Ai, Bi = map(int, input().split(" "))
    tg_idx = -1
    for idx, s in enumerate(stores):
        if s[0] > Ai:
            tg_idx = idx
            break
    if tg_idx != -1:
        stores.insert(tg_idx, (Ai, Bi))
    else:
        stores.append((Ai, Bi))

price = 0
for store in stores:
    if M <= store[1]:
        price += store[0] * M
        break
    else:
        price += store[0] * store[1]
        M -= store[1]
print(price)

Fixed submission:
N, M = map(int, input().split(" "))
stores = []

for i in range(N):
    Ai, Bi = map(int, input().split(" "))
    stores.append((Ai, Bi))    

price = 0
for a, b in sorted(stores, key=lambda x: x[0]):
    if M <= b:
        price += a * M
        break
    else:
        price += a * b
        M -= b
print(price)