Buggy python submission (verdict: Runtime Error):
import heapq
N,M=map(int,input().split())
x={}
for i in range(M+1):
    x[i]=[]
for i in range(N):
    if i >=M:
        continue
    a,b=map(int,input().split())
    x[a].append(-b)
y=[]
an=0
for i in range(M+1):
    for n in x[i]:
        heapq.heappush(y,n)
    try:
        an-=heapq.heappop(y)
    except:
        pass
print(an)


Fixed submission:
import heapq
N,M=map(int,input().split())
x={}
for i in range(M+1):
    x[i]=[]
for i in range(N):
    a,b=map(int,input().split())
    if a>M:
        continue
    x[a].append(-b)
y=[]
an=0
for i in range(M+1):
    for n in x[i]:
        heapq.heappush(y,n)
    try:
        an-=heapq.heappop(y)
    except:
        pass
print(an)

Buggy python submission (verdict: Runtime Error):
import heapq
N,M=map(int,input().split())
x={}
for i in range(M+1):
    x[i]=[]
for i in range(N):
    if i <=M:
        continue
    a,b=map(int,input().split())
    x[a].append(-b)
y=[]
an=0
for i in range(M+1):
    for n in x[i]:
        heapq.heappush(y,n)
    try:
        an-=heapq.heappop(y)
    except:
        pass
print(an)


Fixed submission:
import heapq
N,M=map(int,input().split())
x={}
for i in range(M+1):
    x[i]=[]
for i in range(N):
    a,b=map(int,input().split())
    if a>M:
        continue
    x[a].append(-b)
y=[]
an=0
for i in range(M+1):
    for n in x[i]:
        heapq.heappush(y,n)
    try:
        an-=heapq.heappop(y)
    except:
        pass
print(an)

Buggy python submission (verdict: Runtime Error):
import heapq
N,M=map(int,input().split())
x={}
for i in range(M+1):
    x[i]=[]
for i in range(N):
    a,b=map(int,input().split())
    x[a].append(-b)
y=[]
an=0
for i in range(M+1):
    for n in x[i]:
        heapq.heappush(y,n)
    try:
        an-=heapq.heappop(y)
    except:
        pass
print(an)

Fixed submission:
import heapq
N,M=map(int,input().split())
x={}
for i in range(M+1):
    x[i]=[]
for i in range(N):
    a,b=map(int,input().split())
    if a>M:
        continue
    x[a].append(-b)
y=[]
an=0
for i in range(M+1):
    for n in x[i]:
        heapq.heappush(y,n)
    try:
        an-=heapq.heappop(y)
    except:
        pass
print(an)

Buggy python submission (verdict: Runtime Error):
import heapq
N,M=map(int,input().split())
x={}
for i in range(M+1):
    x[i]=[]
for i in range(N):
    a,b=map(int,input().split())
    x[a].append(-b)
y=heapq.heapify([])
an=0
for i in range(M+1):
    for n in x[i]:
        heapq.heappush(y,n)
    try:
        an-=heapq.heappop(y)
    except:
        pass
print(an)

Fixed submission:
import heapq
N,M=map(int,input().split())
x={}
for i in range(M+1):
    x[i]=[]
for i in range(N):
    a,b=map(int,input().split())
    if a>M:
        continue
    x[a].append(-b)
y=[]
an=0
for i in range(M+1):
    for n in x[i]:
        heapq.heappush(y,n)
    try:
        an-=heapq.heappop(y)
    except:
        pass
print(an)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict
import heapq
N,M=map(int,input().split())
x=defaultdict(list)
for i in range(N):
    a,b=map(int,input().split())
    x[a].append(-b)
y=[]
an=0
for i in range(M+1):
    y+=x[i]
    heapq.heapify(y)
    try:
        an-=heapq.heappop(y)
    except:
        pass
print(an)

Fixed submission:
import heapq
N,M=map(int,input().split())
x={}
for i in range(M+1):
    x[i]=[]
for i in range(N):
    a,b=map(int,input().split())
    if a>M:
        continue
    x[a].append(-b)
y=[]
an=0
for i in range(M+1):
    for n in x[i]:
        heapq.heappush(y,n)
    try:
        an-=heapq.heappop(y)
    except:
        pass
print(an)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict
N,M=map(int,input().split())
x=defaultdict(list)
for i in range(N):
    a,b=map(int,input().split())
    x[a].append(b)
y=[]
an=0
for i in range(M+1):
    y+=x[i]
    try:
        an+=max(y)
        y.remove(max(y))
    except:
        pass
print(an)

Fixed submission:
import heapq
N,M=map(int,input().split())
x={}
for i in range(M+1):
    x[i]=[]
for i in range(N):
    a,b=map(int,input().split())
    if a>M:
        continue
    x[a].append(-b)
y=[]
an=0
for i in range(M+1):
    for n in x[i]:
        heapq.heappush(y,n)
    try:
        an-=heapq.heappop(y)
    except:
        pass
print(an)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict
N,M=map(int,input().split())
x=defaultdict(list)
for i in range(N):
    a,b=map(int,input().split())
    x[a].append(b)
y=[]
an=0
for i in range(M+1):
    y+=x[i]
    y.sort()
    try:
        an+=y.pop()
    except:
        pass
print(an)

Fixed submission:
import heapq
N,M=map(int,input().split())
x={}
for i in range(M+1):
    x[i]=[]
for i in range(N):
    a,b=map(int,input().split())
    if a>M:
        continue
    x[a].append(-b)
y=[]
an=0
for i in range(M+1):
    for n in x[i]:
        heapq.heappush(y,n)
    try:
        an-=heapq.heappop(y)
    except:
        pass
print(an)

Buggy python submission (verdict: Runtime Error):
N,M=map(int,input().split())
x=[]
an=0
for i in range(M+1):
    x.insert(i,[])
for i in range(N):
    a,b=map(int,input().split())
    if a<=M:
        x[a].append(b)
y=[]
while n in <=M+1:
    y+=x[n]
    try:
        n=y.count(max(y))
        an+=n*max(y)
        for z in range(n)
            y.remove(max(y))
        n+=1
    except:
        continue
print(an)

Fixed submission:
import heapq
N,M=map(int,input().split())
x={}
for i in range(M+1):
    x[i]=[]
for i in range(N):
    a,b=map(int,input().split())
    if a>M:
        continue
    x[a].append(-b)
y=[]
an=0
for i in range(M+1):
    for n in x[i]:
        heapq.heappush(y,n)
    try:
        an-=heapq.heappop(y)
    except:
        pass
print(an)

Buggy python submission (verdict: Time Limit Exceeded):
N,M=map(int,input().split())
x=[]
an=0
for i in range(M+1):
    x.insert(i,[])
for i in range(N):
    a,b=map(int,input().split())
    if a<=M:
        x[a].append(b)
y=[]
for n in range(M+1):
    y+=x[n]
    try:
        an+=max(y)
        y.remove(max(y))
    except:
        continue
print(an)

Fixed submission:
import heapq
N,M=map(int,input().split())
x={}
for i in range(M+1):
    x[i]=[]
for i in range(N):
    a,b=map(int,input().split())
    if a>M:
        continue
    x[a].append(-b)
y=[]
an=0
for i in range(M+1):
    for n in x[i]:
        heapq.heappush(y,n)
    try:
        an-=heapq.heappop(y)
    except:
        pass
print(an)