Buggy python submission (verdict: Runtime Error):
#137D
def main():
    import sys
    import heapq as h
    from collections import defaultdict
    N, M = map(int, sys.stdin.readline().split())
    L = tuple([tuple(map(int, sys.stdin.readline().split())) for _ in range(N)])
    #print(L)
    D = defaultdict(list)
    for i in range(N):
        D[L[i][0]-1].append(-L[i][1])
    
    #print(D)
    ans = 0
    tmp=[]
    h.heapify(tmp)
    for d in range(M):
        for b in D[d]:
            h.heappush(tmp, b)
        #print(tmp)
        ans += h.heappop(tmp)
        
    print(-ans)



if __name__=='__main__':
    main()

Fixed submission:
import sys
from collections import defaultdict
import heapq
input = sys.stdin.readline
n, limit = map(int, input().split())
dic = defaultdict(list)

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

L = []
ans = 0
for i in range(limit+1):
    for val in dic[i]:
        heapq.heappush(L, -val)
    if len(L):
        ans -= heapq.heappop(L)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
from collections import defaultdict
#import heapq as hq

n, limit = map(int, sys.stdin.readline().split())
L = [list(map(int, sys.stdin.readline().split())) for _ in range(n)]
#print(L)
D = defaultdict(list)

for a, b in L:
    D[a].append(b)

money =0
tmp = []
for l in range(1, limit+1):
    tmp +=D[l]
    if tmp:
        money+=max(tmp)
        tmp.remove(max(tmp))

print(money)


Fixed submission:
import sys
from collections import defaultdict
import heapq
input = sys.stdin.readline
n, limit = map(int, input().split())
dic = defaultdict(list)

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

L = []
ans = 0
for i in range(limit+1):
    for val in dic[i]:
        heapq.heappush(L, -val)
    if len(L):
        ans -= heapq.heappop(L)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
import heapq
from collections import defaultdict
n, m = map(int, sys.stdin.readline().split())
a_b = [list(map(int, sys.stdin.readline().split())) for _ in range(n)]
dic = defaultdict(list)
for ele in a_b:
    dic[ele[0]].append(ele[1])

#print(dic)
L =[]
money = 0
for d in range(1, m+1):
    dic[d] = map(lambda x:-x, dic[d])
    L+=dic[d]
    heapq.heapify(L)
    if L:
        money +=heapq.heappop(L)
print(-money)

Fixed submission:
import sys
from collections import defaultdict
import heapq
input = sys.stdin.readline
n, limit = map(int, input().split())
dic = defaultdict(list)

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

L = []
ans = 0
for i in range(limit+1):
    for val in dic[i]:
        heapq.heappush(L, -val)
    if len(L):
        ans -= heapq.heappop(L)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
import heapq
import numpy as np
from collections import defaultdict
n, m = map(int, sys.stdin.readline().split())
a_b = [list(map(int, sys.stdin.readline().split())) for _ in range(n)]
dic = defaultdict(list)
for ele in a_b:
    dic[ele[0]].append(ele[1])

#print(dic)
L =[]
money = 0
for d in range(1, m+1):
    L+=list(np.array(dic[d])*(-1))
    heapq.heapify(L)
    if L:
        money +=heapq.heappop(L)
print(-money)

Fixed submission:
import sys
from collections import defaultdict
import heapq
input = sys.stdin.readline
n, limit = map(int, input().split())
dic = defaultdict(list)

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

L = []
ans = 0
for i in range(limit+1):
    for val in dic[i]:
        heapq.heappush(L, -val)
    if len(L):
        ans -= heapq.heappop(L)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
from collections import defaultdict
n, m = map(int, sys.stdin.readline().split())
a_b = [list(map(int, sys.stdin.readline().split())) for _ in range(n)]
dic = defaultdict(list)
for ele in a_b:
    dic[ele[0]].append(ele[1])

L =[]
money = 0
for d in range(1, m+1):
    if dic[d]:
        L+= dic[d]
    if L:
        L.sort()
        money += L[-1]
        L.pop()
print(money)

Fixed submission:
import sys
from collections import defaultdict
import heapq
input = sys.stdin.readline
n, limit = map(int, input().split())
dic = defaultdict(list)

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

L = []
ans = 0
for i in range(limit+1):
    for val in dic[i]:
        heapq.heappush(L, -val)
    if len(L):
        ans -= heapq.heappop(L)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
from collections import defaultdict
n, m = map(int, sys.stdin.readline().split())
a_b = [list(map(int, sys.stdin.readline().split())) for _ in range(n)]
dic = defaultdict(list)
for ele in a_b:
    dic[ele[0]].append(ele[1])

L =[]
money = 0
for d in range(1, m+1):
    L+= dic[d]
    if L:
        max_money = max(L)
        money +=max_money
        L.remove(max_money)
print(money)

Fixed submission:
import sys
from collections import defaultdict
import heapq
input = sys.stdin.readline
n, limit = map(int, input().split())
dic = defaultdict(list)

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

L = []
ans = 0
for i in range(limit+1):
    for val in dic[i]:
        heapq.heappush(L, -val)
    if len(L):
        ans -= heapq.heappop(L)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
from collections import defaultdict
import heapq
import numpy as np
input = sys.stdin.readline
n, limit = map(int, input().split())
dic = defaultdict(list)

for _ in range(n):
    a, b = map(int, input().split())
    dic[a].append(b)
#print(dic)

L = []
ans = 0
for i in range(limit+1):
    L += list(np.array(dic[i])*(-1))
    heapq.heapify(L)
    if len(L) >0:
        #print(L)
        ans -= heapq.heappop(L)
        #print(ans)
print(ans)

Fixed submission:
import sys
from collections import defaultdict
import heapq
input = sys.stdin.readline
n, limit = map(int, input().split())
dic = defaultdict(list)

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

L = []
ans = 0
for i in range(limit+1):
    for val in dic[i]:
        heapq.heappush(L, -val)
    if len(L):
        ans -= heapq.heappop(L)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import itertools as ite
n, m = map(int, input().split())
L = [list(map(int,input().split())) for i in range(n)]
L2= ite.permutations(L, n)
max_money = 0
for ele in L2:
    d = 0
    money = 0
    for ele2 in ele:
        if ele2[0]+d <=m:
            money +=ele2[1]
        d+=1
    if max_money < money:
        max_money = money
print(max_money)

Fixed submission:
import sys
from collections import defaultdict
import heapq
input = sys.stdin.readline
n, limit = map(int, input().split())
dic = defaultdict(list)

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

L = []
ans = 0
for i in range(limit+1):
    for val in dic[i]:
        heapq.heappush(L, -val)
    if len(L):
        ans -= heapq.heappop(L)
print(ans)