Buggy python submission (verdict: Time Limit Exceeded):
n,m = map(int,input().split())
ab = [ list(map(int,input().split())) for i in range(n) ]
# print(ab)
ab.sort(reverse=True)
# print(ab)
import heapq
heap = []
ans = 0
for day in reversed(range(m)):
    for i in range(len(ab)):
        if ab[i][0]==(m-day):
            heapq.heappush(heap,-ab[i][1])
    if len(heap)>0:
        ans += abs(heapq.heappop(heap))
print(ans)

Fixed submission:
n,m = map(int,input().split())
ab = [ list(map(int,input().split())) for i in range(n) ]
# print(ab)
ab.sort()
# print(ab)
import heapq
heap = []
ans = 0
i = 0
for day in reversed(range(m)):
    while i<n and ab[i][0]==(m-day):
        heapq.heappush(heap,-ab[i][1])
        i += 1
    if len(heap) > 0:
        ans += -heapq.heappop(heap)
    # print(day,i,ans,heap)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n,m = map(int,input().split())
ab = [ list(map(int,input().split())) for i in range(n) ]
# print(ab)
ab.sort(reverse=True)
# print(ab)
import heapq
heap = []
ans = 0
for day in reversed(range(m)):
    for i in range(len(ab)):
        if ab[i][0]==(m-day):
            heapq.heappush(heap,-ab[i][1])
    if len(heap)>0:
        ans += abs(heapq.heappop(heap))
print(ans)

Fixed submission:
n,m = map(int,input().split())
ab = [ list(map(int,input().split())) for i in range(n) ]
# print(ab)
ab.sort()
# print(ab)
import heapq
heap = []
ans = 0
i = 0
for day in reversed(range(m)):
    while i<n and ab[i][0]==(m-day):
        heapq.heappush(heap,-ab[i][1])
        i += 1
    if len(heap) > 0:
        ans += -heapq.heappop(heap)
    # print(day,i,ans,heap)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n,m = map(int,input().split())
ab = [ list(map(int,input().split())) for i in range(n)]
# print(ab)
ab.sort(reverse=True)
# print(ab)
# print(len(ab))
from heapq import heappush
from heapq import heappop
# from heapq import heapify

heap = [0]*m

ans = 0
for i in reversed(range(m)):
    # print(ab)
    # print("i={}".format(i))
    if i < 0:
        break
    else:
        # print("n={}".format(n))
        for j in range(n):
            if (ab[j][0]+i) > m:
                pass
            else:
                heappush(heap, -(ab[j][1]))
                ab[j][1] = 0
        # print(heap)
    ans += heappop(heap)
    # print(ans)

# print(ans)
print(abs(ans))

Fixed submission:
n,m = map(int,input().split())
ab = [ list(map(int,input().split())) for i in range(n) ]
# print(ab)
ab.sort()
# print(ab)
import heapq
heap = []
ans = 0
i = 0
for day in reversed(range(m)):
    while i<n and ab[i][0]==(m-day):
        heapq.heappush(heap,-ab[i][1])
        i += 1
    if len(heap) > 0:
        ans += -heapq.heappop(heap)
    # print(day,i,ans,heap)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n,m = map(int,input().split())
ab = [ list(map(int,input().split())) for i in range(n)]
# print(ab)
ab.sort(reverse=True)
# print(ab)
# print(len(ab))
from heapq import heappush
from heapq import heappop
from heapq import heapify

heap = [0]*m

ans = 0
for i in reversed(range(m)):
    # print(ab)
    # print("i={}".format(i))
    if i < 0:
        break
    else:
        # print("n={}".format(n))
        for j in range(n):
            if (ab[j][0]+i) > m:
                pass
            else:
                heappush(heap, -(ab[j][1]))
                ab[j][1] = 0
        # print(heap)
    ans += heappop(heap)
    # print(ans)

# print(ans)
print(abs(ans))

Fixed submission:
n,m = map(int,input().split())
ab = [ list(map(int,input().split())) for i in range(n) ]
# print(ab)
ab.sort()
# print(ab)
import heapq
heap = []
ans = 0
i = 0
for day in reversed(range(m)):
    while i<n and ab[i][0]==(m-day):
        heapq.heappush(heap,-ab[i][1])
        i += 1
    if len(heap) > 0:
        ans += -heapq.heappop(heap)
    # print(day,i,ans,heap)
print(ans)

Buggy python submission (verdict: Runtime Error):
n = int(input())
s = [input() for i in range(n)]
# print(n)
# print(s)
s = list(map(list, s))
# print(s)
for i in range(n):
    s[i].sort()
    s[i] = "".join(s[i])
# print(s)
dic = {}
for i in range(n):
    if s[i] in dic:
        dic[s[i]] += 1
    else:
        dic.setdefault(s[i],1)
a = list(dic.values())
# print(a)
import math
count = 0
for i in range(len(a)):
    if a[i] >= 2:
        count += math.factorial(a[i])//(math.factorial(a[i]-2)*2)
print(count)

Fixed submission:
n,m = map(int,input().split())
ab = [ list(map(int,input().split())) for i in range(n) ]
# print(ab)
ab.sort()
# print(ab)
import heapq
heap = []
ans = 0
i = 0
for day in reversed(range(m)):
    while i<n and ab[i][0]==(m-day):
        heapq.heappush(heap,-ab[i][1])
        i += 1
    if len(heap) > 0:
        ans += -heapq.heappop(heap)
    # print(day,i,ans,heap)
print(ans)