Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
A_list = []
B_list = []
for i in range(N):
    A, B = map(int, input().split())
    A_list.append(A)
    B_list.append(B)

new_A_list = []
for i in A_list:
    if i not in new_A_list:
        new_A_list.append(i)
    else:
        pass

sorted_new_A_list = sorted(new_A_list)

def counter(x, l=A_list): #リストlに格納されている_xのインデックスを全て取得する
    return [i for i, _x in enumerate(l) if _x == x]


count_list = [0]
count = 0
ans = 0
if N == 1:
    ans = A_list[0] * M
else:
    for i in range(N):
        index_B_list = counter(sorted_new_A_list[i])
        for j in index_B_list: 
            count += B_list[j]
        count_list.append(count)
            
        if count_list[i+1] < M:
            ans += sorted_new_A_list[i] * (count_list[i+1] - count_list[i])
        else:
            ans += sorted_new_A_list[i] * (M - count_list[i])
            break

print(ans)


Fixed submission:
N, M = map(int, input().split())
ab = sorted([list(map(int, input().split())) for _ in range(N)]) #入力する時から気をつける

count = 0
ans = 0
for _ab in ab:
    diff = M - count
    if _ab[1] < diff:
        count += _ab[1]  
        ans += _ab[0] * _ab[1]
    else:
        ans += _ab[0] * diff
        break

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
A_list = []
B_list = []
for i in range(N):
    A, B = map(int, input().split())
    A_list.append(A)
    B_list.append(B)

sorted_A_list = sorted(A_list)
new_sorted_A_list = []
for i in sorted_A_list:
    if i not in new_sorted_A_list:
        new_sorted_A_list.append(i)
    else:
        pass

def counter(x, l=A_list): #リストlに格納されている_xのインデックスを全て取得する
    return [i for i, _x in enumerate(l) if _x == x]


count_list = [0]
count = 0
ans = 0
if N == 1:
    ans = A_list[0] * M
else:
    for i in range(N):
        index_B_list = counter(new_sorted_A_list[i])
        for j in index_B_list: 
            count += B_list[j]
        count_list.append(count)
            
        if count_list[i+1] < M:
            ans += new_sorted_A_list[i] * (count_list[i+1] - count_list[i])
        else:
            ans += new_sorted_A_list[i] * (M - count_list[i])
            break

print(ans)


Fixed submission:
N, M = map(int, input().split())
ab = sorted([list(map(int, input().split())) for _ in range(N)]) #入力する時から気をつける

count = 0
ans = 0
for _ab in ab:
    diff = M - count
    if _ab[1] < diff:
        count += _ab[1]  
        ans += _ab[0] * _ab[1]
    else:
        ans += _ab[0] * diff
        break

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
A_list = []
B_list = []
for i in range(N):
    A, B = map(int, input().split())
    A_list.append(A)
    B_list.append(B)

sorted_A_list = sorted(A_list)

def counter(x, l=A_list): #リストlに格納されている_xのインデックスを全て取得する
    return [i for i, _x in enumerate(l) if _x == x]


count = 0
gate = 0
ans = 0
if N == 1:
    ans = A_list[0] * M
    print(ans)
else:
    for i in range(N):
        index_B_list = counter(sorted_A_list[i])
        for j in index_B_list:
            count += B_list[j]
            if count <= M:
                ans += sorted_A_list[i] * B_list[j]
            else:
                if gate == 0: #ここを使用するのは答えを出す一回だけ
                    count -= B_list[j]
                    ans += sorted_A_list[i] * (M - count)
                    print(ans)
                    gate += 1


Fixed submission:
N, M = map(int, input().split())
ab = sorted([list(map(int, input().split())) for _ in range(N)]) #入力する時から気をつける

count = 0
ans = 0
for _ab in ab:
    diff = M - count
    if _ab[1] < diff:
        count += _ab[1]  
        ans += _ab[0] * _ab[1]
    else:
        ans += _ab[0] * diff
        break

print(ans)