Buggy python submission (verdict: Time Limit Exceeded):
import copy
List = []
N, M = (int(x) for x in input().split())
for i in range(N):
    a, b = (int(x) for x in input().split())
    List.append([a, b])

def merge(list):
    mid = len(list)
    if mid > 1:
        left = merge(list[:(mid//2)])
        right = merge(list[(mid//2):])
        list = []
        while len(left) != 0 and len(right) != 0:
            if left[0][0] < right[0][0]:
                list.append(left.pop(0))
            else:
                list.append(right.pop(0))
        if len(left) != 0:
            list.extend(left)
        elif len(right) != 0:
            list.extend(right)
    return list

num_of_drink, total_fee = 0, 0
List = copy.copy(merge(List))

temp_M = M
list_of_num = []
for i in range(N):
    if temp_M <= List[i][1]:
        list_of_num.append(temp_M)
        break
    else:
        list_of_num.append(List[i][1])
        temp_M += -List[i][1]
index = 0
for x in list_of_num:
    total_fee += List[index][0] * x
    index += 1
print(total_fee)

Fixed submission:
List = []
N, M = (int(x) for x in input().split())
for i in range(N):
    a, b = (int(x) for x in input().split())
    List.append([a, b])

num_of_drink, total_fee = 0, 0
List = sorted(List, key=lambda x:x[0])

temp_M = M
list_of_num = []
for i in range(N):
    if temp_M <= List[i][1]:
        list_of_num.append(temp_M)
        break
    else:
        list_of_num.append(List[i][1])
        temp_M += -List[i][1]
index = 0
for x in list_of_num:
    total_fee += List[index][0] * x
    index += 1
print(total_fee)

Buggy python submission (verdict: Time Limit Exceeded):
import copy
A, B = [], []
N, M = (int(x) for x in input().split())
for i in range(N):
    a, b = (int(x) for x in input().split())
    A.append(a), B.append(b)

#sort main_list with sub_list
def merge(main_list, sub_list):
    mid = len(main_list)
    if mid > 1:
        left = merge(main_list[:(mid//2)], sub_list[:(mid//2)])
        right = merge(main_list[(mid//2):], sub_list[(mid//2):])
        main_list, sub_list = [], []
        while len(left[0]) != 0 and len(right[0]) != 0:
            if left[0][0] < right[0][0]:
                main_list.append(left[0].pop(0))
                sub_list.append(left[1].pop(0))
            else:
                main_list.append(right[0].pop(0))
                sub_list.append(right[1].pop(0))
        if len(left[0]) != 0:
            main_list.extend(left[0])
            sub_list.extend(left[1])
        elif len(right[0]) != 0:
            main_list.extend(right[0])
            sub_list.extend(right[1])
    return main_list, sub_list

num_of_drink, total_fee = 0, 0
A, B = copy.copy(merge(A, B)[0]), copy.copy(merge(A, B)[1])

temp_M = M
list_of_num = []
for i in range(N):
    if temp_M <= B[i]:
        list_of_num.append(temp_M)
        break
    else:
        list_of_num.append(B[i])
        temp_M += -B[i]
index = 0
for x in list_of_num:
    total_fee += A[index] * x
    index += 1
print(total_fee)

Fixed submission:
List = []
N, M = (int(x) for x in input().split())
for i in range(N):
    a, b = (int(x) for x in input().split())
    List.append([a, b])

num_of_drink, total_fee = 0, 0
List = sorted(List, key=lambda x:x[0])

temp_M = M
list_of_num = []
for i in range(N):
    if temp_M <= List[i][1]:
        list_of_num.append(temp_M)
        break
    else:
        list_of_num.append(List[i][1])
        temp_M += -List[i][1]
index = 0
for x in list_of_num:
    total_fee += List[index][0] * x
    index += 1
print(total_fee)

Buggy python submission (verdict: Time Limit Exceeded):
import copy
A, B = [], []
N, M = (int(x) for x in input().split())
for i in range(N):
    a, b = (int(x) for x in input().split())
    A.append(a), B.append(b)

#sort main_list with sub_list
def merge(main_list, sub_list):
    mid = len(main_list)
    if mid > 1:
        left = merge(main_list[:(mid//2)], sub_list[:(mid//2)])
        right = merge(main_list[(mid//2):], sub_list[(mid//2):])
        main_list, sub_list = [], []
        while len(left[0]) != 0 and len(right[0]) != 0:
            if left[0][0] < right[0][0]:
                main_list.append(left[0].pop(0))
                sub_list.append(left[1].pop(0))
            else:
                main_list.append(right[0].pop(0))
                sub_list.append(right[1].pop(0))
        if len(left[0]) != 0:
            main_list.extend(left[0])
            sub_list.extend(left[1])
        elif len(right[0]) != 0:
            main_list.extend(right[0])
            sub_list.extend(right[1])
    return main_list, sub_list

num_of_drink, total_fee = 0, 0
A, B = copy.copy(merge(A, B)[0]), copy.copy(merge(A, B)[1])
for i in range(N):
    for j in range(B[i]):
        num_of_drink += 1
        total_fee += A[i]
        if num_of_drink == M:
            break
    else:
        continue
    break

print(total_fee)

Fixed submission:
List = []
N, M = (int(x) for x in input().split())
for i in range(N):
    a, b = (int(x) for x in input().split())
    List.append([a, b])

num_of_drink, total_fee = 0, 0
List = sorted(List, key=lambda x:x[0])

temp_M = M
list_of_num = []
for i in range(N):
    if temp_M <= List[i][1]:
        list_of_num.append(temp_M)
        break
    else:
        list_of_num.append(List[i][1])
        temp_M += -List[i][1]
index = 0
for x in list_of_num:
    total_fee += List[index][0] * x
    index += 1
print(total_fee)

Buggy python submission (verdict: Time Limit Exceeded):
import itertools
A, B = [], []
N, M = (int(x) for x in input().split())
for i in range(N):
    a, b = (int(x) for x in input().split())
    A.append(a)
    B.append(b)

Max = 0
list = []
for i in range(N):
    Max += A[i] * B[i]
    list.append(range(B[i]+1))

def SumOfList(l):
    ret = 0
    for i in l:
        ret += i
    return ret

def TotalFee(l):
    ret, index = 0, 0
    for z in l:
        ret += A[index] * z
        index += 1
    return ret

for l in itertools.product(*list):
    if SumOfList(l) == M and TotalFee(l) < Max:
        Max = TotalFee(l)

print(Max)

Fixed submission:
List = []
N, M = (int(x) for x in input().split())
for i in range(N):
    a, b = (int(x) for x in input().split())
    List.append([a, b])

num_of_drink, total_fee = 0, 0
List = sorted(List, key=lambda x:x[0])

temp_M = M
list_of_num = []
for i in range(N):
    if temp_M <= List[i][1]:
        list_of_num.append(temp_M)
        break
    else:
        list_of_num.append(List[i][1])
        temp_M += -List[i][1]
index = 0
for x in list_of_num:
    total_fee += List[index][0] * x
    index += 1
print(total_fee)