Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
ls = [[int(x) for x in input().split()] for _ in range(N)]

q = [[] for _ in range(M)]
for a, b in ls:
    if a <= M:
        q[M-a].append(b*-1)

# print(q)

from heapq import heappop

pool = []
answer = 0
for x in reversed(q):
    pool.extend(sorted(x))
    m = heappop(pool)*-1
    answer += m
    

print(answer)

Fixed submission:
N, M = map(int, input().split())
ls = [[int(x) for x in input().split()] for _ in range(N)]


q = [[0] for _ in range(M)]
for a, b in ls:
    if a <= M:
        q[M-a].append(b*-1)

# print(q)

from heapq import heappop, heappush

pool = []
answer = 0
for x in reversed(q):
    for y in x:
        heappush(pool, y)
    m = heappop(pool)*-1
    answer += m
    

print(answer)

Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
ls = [[int(x) for x in input().split()] for _ in range(N)]

q = [[0] for _ in range(M)]
for a, b in ls:
    if a <= M:
        q[M-a].append(b)

# print(q)

pool = [0]
answer = 0
for x in reversed(q):
    x.append(sorted(pool, reverse=True)[0])
    m = max(x)
    answer += m
    pool += x
    pool.remove(m)
    

print(answer)

Fixed submission:
N, M = map(int, input().split())
ls = [[int(x) for x in input().split()] for _ in range(N)]


q = [[0] for _ in range(M)]
for a, b in ls:
    if a <= M:
        q[M-a].append(b*-1)

# print(q)

from heapq import heappop, heappush

pool = []
answer = 0
for x in reversed(q):
    for y in x:
        heappush(pool, y)
    m = heappop(pool)*-1
    answer += m
    

print(answer)

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

ls = [[int(x) for x in input().split()] for _ in range(N)]

# これでからの配列を生成すると、全てのリストに値が入っちゃう
# q = [[]]*M
# q[0].append(1)

q = [[0] for _ in range(M)]
for a, b in ls:
    if a <= M:
        q[M-a].append(b)

# print(q)

pool = []
answer = 0
for x in reversed(q):
    m = max(x+pool)
    # print(m, x, pool)
    answer += m
    pool += x
    pool.remove(m)
    

print(answer)

Fixed submission:
N, M = map(int, input().split())
ls = [[int(x) for x in input().split()] for _ in range(N)]


q = [[0] for _ in range(M)]
for a, b in ls:
    if a <= M:
        q[M-a].append(b*-1)

# print(q)

from heapq import heappop, heappush

pool = []
answer = 0
for x in reversed(q):
    for y in x:
        heappush(pool, y)
    m = heappop(pool)*-1
    answer += m
    

print(answer)

Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
ls = [[int(x) for x in input().split()] for _ in range(N)]

q = [[0] for _ in range(M)]
for a, b in ls:
    q[M-a].append(b)

pool = []
answer = 0
for x in reversed(q):
    m = max(x+pool)
    answer += m
    pool += x
    pool.remove(m)
    

print(answer)

Fixed submission:
N, M = map(int, input().split())
ls = [[int(x) for x in input().split()] for _ in range(N)]


q = [[0] for _ in range(M)]
for a, b in ls:
    if a <= M:
        q[M-a].append(b*-1)

# print(q)

from heapq import heappop, heappush

pool = []
answer = 0
for x in reversed(q):
    for y in x:
        heappush(pool, y)
    m = heappop(pool)*-1
    answer += m
    

print(answer)

Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
ls = [[int(x) for x in input().split()] for _ in range(N)]

q = [[1e-10] for _ in range(M)]
for a, b in ls:
    q[M-a].append(b)

print(sum(int(max(x)) for x in q))

Fixed submission:
N, M = map(int, input().split())
ls = [[int(x) for x in input().split()] for _ in range(N)]


q = [[0] for _ in range(M)]
for a, b in ls:
    if a <= M:
        q[M-a].append(b*-1)

# print(q)

from heapq import heappop, heappush

pool = []
answer = 0
for x in reversed(q):
    for y in x:
        heappush(pool, y)
    m = heappop(pool)*-1
    answer += m
    

print(answer)