Buggy python submission (verdict: Time Limit Exceeded):
N, M= map(int, input().split())
B=[]
for i in range(N):
    B.append([None]*2)
    l=input().split()
    B[i][0]=int(l[1])
    B[i][1]=int(l[0])
B.sort(reverse=True)
h=[False]*(M+1)
a=0
d=M+1
for i in range(N):
    if d>B[i][1]:
      for j in range(B[i][1],d):
        if h[j]==False:
            h[j]=True
            a+=B[i][0]
            break
      else:
        d=B[i][1]
print(a)

Fixed submission:
import sys
def input():
    return sys.stdin.readline()[:-1]
N,M=map(int,input().split())
l=[[] for i in range(10**5)]
for i in range(N):
    a,b=map(int,input().split())
    l[a-1].append(b)
h=[]
import heapq
a=0
for i in range(M):
    for j in l[i]:
        heapq.heappush(h,-j)
    if h:
        a-=heapq.heappop(h)
print(a)

Buggy python submission (verdict: Time Limit Exceeded):
N, M= map(int, input().split())
B=[]
for i in range(N):
    B.append([None]*2)
    l=input().split()
    B[i][0]=int(l[1])
    B[i][1]=int(l[0])
B.sort(reverse=True)
h=[0]*(M+1)
a=0
d=M+1
for i in range(N):
    if d>B[i][1]:
      for j in range(B[i][1],d):
        if h[j]==0:
            h[j]=1
            a+=B[i][0]
            break
      else:
        d=B[i][1]
print(a)

Fixed submission:
import sys
def input():
    return sys.stdin.readline()[:-1]
N,M=map(int,input().split())
l=[[] for i in range(10**5)]
for i in range(N):
    a,b=map(int,input().split())
    l[a-1].append(b)
h=[]
import heapq
a=0
for i in range(M):
    for j in l[i]:
        heapq.heappush(h,-j)
    if h:
        a-=heapq.heappop(h)
print(a)

Buggy python submission (verdict: Time Limit Exceeded):
N, M= map(int, input().split())
B=[]
for i in range(N):
    B.append([None]*2)
    l=input().split()
    B[i][0]=int(l[1])
    B[i][1]=int(l[0])
B.sort(reverse=True)
h=[0]*(M+1)
a=0
d=M+1
for i in range(N):
    if d>B[i][1]:
      for j in range(B[i][1],d):
        if h[j]==0:
            h[j]=1
            a+=B[i][0]
            break
      else:
        d=B[i][1]
print(a)

Fixed submission:
import sys
def input():
    return sys.stdin.readline()[:-1]
N,M=map(int,input().split())
l=[[] for i in range(10**5)]
for i in range(N):
    a,b=map(int,input().split())
    l[a-1].append(b)
h=[]
import heapq
a=0
for i in range(M):
    for j in l[i]:
        heapq.heappush(h,-j)
    if h:
        a-=heapq.heappop(h)
print(a)

Buggy python submission (verdict: Runtime Error):
N, M= map(int, input().split())
B=[]
for i in range(N):
    B.append([None]*2)
    l=input().split()
    B[i][0]=int(l[1])
    B[i][1]=int(l[0])
B.sort(reverse=True)
h=[0]*(M+1)
a=0
d=M+1
for i in range(N):
    for j in range(B[i][1],d):
        if h[j]==0:
            h[j]=1
            a+=B[i][0]
            break
    else:
        d=B[i][1]
print(a)

Fixed submission:
import sys
def input():
    return sys.stdin.readline()[:-1]
N,M=map(int,input().split())
l=[[] for i in range(10**5)]
for i in range(N):
    a,b=map(int,input().split())
    l[a-1].append(b)
h=[]
import heapq
a=0
for i in range(M):
    for j in l[i]:
        heapq.heappush(h,-j)
    if h:
        a-=heapq.heappop(h)
print(a)

Buggy python submission (verdict: Time Limit Exceeded):
N, M= map(int, input().split())
B=[]
for i in range(N):
    B.append([None]*2)
    l=input().split()
    B[i][0]=int(l[1])
    B[i][1]=int(l[0])
B.sort(reverse=True)
h=[0]*(M+1)
a=0
for i in range(N):
    for j in range(B[i][1],M+1):
        if h[j]==0:
            h[j]=1
            a+=B[i][0]
            break
print(a)

Fixed submission:
import sys
def input():
    return sys.stdin.readline()[:-1]
N,M=map(int,input().split())
l=[[] for i in range(10**5)]
for i in range(N):
    a,b=map(int,input().split())
    l[a-1].append(b)
h=[]
import heapq
a=0
for i in range(M):
    for j in l[i]:
        heapq.heappush(h,-j)
    if h:
        a-=heapq.heappop(h)
print(a)