qyliang/CodeNanoFix huggingface dataset:
Buggy code:
import heapq
n,m=map(int,input().split())
ab=[[] for i in range(m)]
for i in range(n):
  a,b=map(int,input().split())
  if a<=m:
    ab[a-1].append(-b)
l=[]
heapq.heapify(l)
ans=0
for i in range(m):
  for j in ab[i]:
    heapq.heappush(l,j)
  if l:
    print(l)
    ans+=-heapq.heappop(l)
print(ans)

Fixed code:
import heapq
n,m=map(int,input().split())
ab=[[] for i in range(m)]
for i in range(n):
  a,b=map(int,input().split())
  if a<=m:
    ab[a-1].append(-b)
l=[]
ans=0
for i in range(m):
  for j in ab[i]:
    heapq.heappush(l,j)
  if l:
    ans+=-heapq.heappop(l)
print(ans)
Buggy code:
import heapq
job = list()
salary = list()
n,m = map(int,input().split())

for i in range(n):
    a,b = map(int,input().split())
    job.append(a,b)
    
job.sort(reverse = True)

for x in job:
    s,t = x
    heapq.heappush(salary,t)
    if s - m > 0:
        heapq.heappop(salary)
    else:
        m -= 1

print(sum(salary))


Fixed code:
import heapq
job = list()
salary = list()
n,m = map(int,input().split())

for i in range(n):
    a,b = map(int,input().split())
    job.append((a,b))

job.sort(reverse = True)

for x in job:
    s,t = x
    heapq.heappush(salary,t)
    if s - m > 0:
        heapq.heappop(salary)
    else:
        m -= 1

print(sum(salary))
Buggy code:
from Lib import heapq
Heappop=heapq.heappop
Heappush=heapq.heappush
N,M=map(int,input().split())
L=[]
for _ in range(N):
    a,b=map(int,input().split())
    L.append([a,-b])
L.sort()
q=[0]*10**5
ans=0
d=1
memo=0
while d<=M:
    while memo<=N-1:
        a,b=L[memo]
        if d<a:
            break
        else:
            Heappush(q,b)
            memo+=1
    ans-=Heappop(q)
    d+=1
print(ans)

Fixed code:
import heapq
Heappop=heapq.heappop
Heappush=heapq.heappush
N,M=map(int,input().split())
L=[]
for _ in range(N):
    a,b=map(int,input().split())
    L.append([a,-b])
L.sort()
q=[0]*10**5
ans=0
d=1
memo=0
while d<=M:
    while memo<=N-1:
        a,b=L[memo]
        if d<a:
            break
        else:
            Heappush(q,b)
            memo+=1
    ans-=Heappop(q)
    d+=1
print(ans)
Buggy code:
mport heapq
n,m=map(int,input().split())
list=[[] for i in range(m)]
h=[]
for i in range(n):
  a,b=map(int,input().split())
  if a<=m:
    list[a-1].append(-b)
ans=0
for i in range(m):
  for j in list[i]:
    heapq.heappush(h,j)
  if h:
    ans+=-heapq.heappop(h)
  else:
    continue
print(ans)  

Fixed code:
import heapq
n,m=map(int,input().split())
list=[[] for i in range(m)]
h=[]
for i in range(n):
  a,b=map(int,input().split())
  if a<=m:
    list[a-1].append(-b)
ans=0
for i in range(m):
  for j in list[i]:
    heapq.heappush(h,j)
  if h:
    ans+=-heapq.heappop(h)
  else:
    continue
print(ans)
Buggy code:
import heapq
N,M=map(int,input().split())
AB=[list(map(int,input().split())) for _ in range(N)]

AB.sort(reverse=True)
works=[]
heapq.heapify(works)
ans=0
AB.append(0)
for i in range(1,M+1):
  day=M-i
  latest=i
  while AB and AB[-2][0]<=latest:
    a,b=AB.pop(-2)
    heapq.heappush(works,-b)
  if not works:
    continue
  ans-=heapq.heappop(works)

print(ans)


Fixed code:
import heapq
N,M=map(int,input().split())
AB=[list(map(int,input().split())) for _ in range(N)]

AB.sort(reverse=True)
works=[]
heapq.heapify(works)
ans=0
for i in range(1,M+1):
  day=M-i
  latest=i
  while AB and AB[-1][0]<=latest:
    a,b=AB.pop()
    heapq.heappush(works,-b)
  if not works:
    continue
  ans-=heapq.heappop(works)

print(ans)
Buggy code:
from operator import itemgetter
import bisect
import heapq
import sys
input = sys.stdin.readline

def main():
    N,M = [int(x) for x in input().split()]
    work = {}
    for _ in range(N):
        a,b = [int(x) for x in input().split()]
        if(a in work):
            work[a].append(-b)
        else:
            work[a] = [-b]

    cand = []
    heapq.heapify(cand)
    cnt = 0
    for i in range(1,M+1):
        if(i in work):
            cand += work[i]
        if(len(cand)==0):
            continue
        x = -heapq.heappop(cand)
        cnt += x

    print(cnt)

if __name__ == '__main__':
    main()


Fixed code:
from operator import itemgetter
import bisect
import heapq
import sys
input = sys.stdin.readline

def main():
    N,M = [int(x) for x in input().split()]
    work = {}
    for _ in range(N):
        a,b = [int(x) for x in input().split()]
        if(a in work):
            work[a].append(-b)
        else:
            work[a] = [-b]

    cand = []
    heapq.heapify(cand)
    cnt = 0
    for i in range(1,M+1):
        if(i in work):
            for x in work[i]:
                heapq.heappush(cand,x)
        if(len(cand)==0):
            continue
        x = -heapq.heappop(cand)
        cnt += x

    print(cnt)

if __name__ == '__main__':
    main()
Buggy code:
import heapq
N,M = map(int,input().split())
jobs = [ [] for _ in range(M+1) ]
for _ in range(N):
  a,b = map(int,input().split())
  jobs[a].append(b)

pq = []
d = 1
res = 0
for _ in range(M-1, -1, -1):
  for b in jobs[d]:
    heapq.heappush(pq, -b)
  if pq:
    res += -heapq.heappop(pq)
  d += 1

print(res)

Fixed code:
import heapq
N,M = map(int,input().split())
jobs = [ [] for _ in range(M+1) ]
for _ in range(N):
  a,b = map(int,input().split())
  if a <= M:
    jobs[a].append(b)

pq = []
d = 1
res = 0
for _ in range(M-1, -1, -1):
  for b in jobs[d]:
    heapq.heappush(pq, -b)
  if pq:
    res += -heapq.heappop(pq)
  d += 1

print(res)
Buggy code:
# coding: utf-8
import heapq
n, m = map(int, input().split())
jobs = [[] for i in range(m)]
for i in range(n):
    a, b = map(int, input().split())
    if a > m:
        continue
    jobs[m-a].append(b)
ans = 0
l = []
for i in range(m-a, -1, -1):
    for j in jobs[i]:
        heapq.heappush(l, -j)
    if len(l):
        ans += -heapq.heappop(l)
print(ans)

Fixed code:
# coding: utf-8
import heapq
n, m = map(int, input().split())
jobs = [[] for i in range(m)]
for i in range(n):
    a, b = map(int, input().split())
    if a > m:
        continue
    jobs[m-a].append(b)
ans = 0
l = []
for i in range(m-1, -1, -1):
    for j in jobs[i]:
        heapq.heappush(l, -j)
    if len(l):
        ans += -heapq.heappop(l)
print(ans)
Buggy code:
import heapq

n,m=map(int,input().split())
ab=[]
for i in range(n):
    ab.append(list(map(int,input().split())))
ab.sort()

q=[]
ans=0
for i in range(m):
    while j <= n-1:
        if ab[j][0]<=i+1:
            heapq.heappush(q,-ab[j][1])
        else:
            ans-=heapq.heappop(q)
            break
        j+=1
print(ans)

Fixed code:
import heapq

n,m=map(int,input().split())
ab=[]
for i in range(n):
    ab.append(list(map(int,input().split())))
ab.sort()

q=[]
ans=0
j=0
for i in range(m):
    while j <= n-1:
        if ab[j][0]<=i+1:
            heapq.heappush(q,-ab[j][1])
        else:
            break
        j+=1
    if len(q)!=0:
        ans-=heapq.heappop(q)
print(ans)
Buggy code:
import sys
import heapq

N,M = [int(k) for k in sys.stdin.readline().split()]

job=[]
for i in range(N):
    A,B = [int(k) for k in sys.stdin.readline().split()]
    job.append((A,-B))

job.sort(key=lambda t: -t[0])

heap=[]
heapq.heapify(heap)

ans=0

for i in range(1,M+1):
    if len(job)!=0:
      while job[-1][0]==i:
         heapq.heappush(heap,job.pop()[1])
          if len(job)==0:
             break
    if len(heap) == 0:
        continue
    ans -= heapq.heappop(heap)
    
print(ans)


Fixed code:
import sys
import heapq

N,M = [int(k) for k in sys.stdin.readline().split()]

job=[]
for i in range(N):
    A,B = [int(k) for k in sys.stdin.readline().split()]
    job.append((A,-B))

job.sort(key=lambda t: -t[0])

heap=[]
heapq.heapify(heap)

ans=0

for i in range(1,M+1):
    if len(job)!=0:
      while job[-1][0]==i:
          heapq.heappush(heap,job.pop()[1])
          if len(job)==0:
             break
    if len(heap) == 0:
        continue
    ans -= heapq.heappop(heap)
    
print(ans)
Buggy code:
import heapq
n,m= map(int,input().split())
feeindays = [[] for _ in range(m)]
for i in range(n):
    a,b= map(int,input().split())
    feeindays[a-1]+=[b]
q=[]
heapq.heapify(q)
pay=0
for l in feeindays:
    for c in l:heapq.heappush(q,-c)
    if len(q)!=0:pay+=-1 * heapq.heappop(q)
print(pay)

Fixed code:
import heapq
n,m= map(int,input().split())
feeindays = [[] for _ in range(m)]
for i in range(n):
    a,b= map(int,input().split())
    if a<=m:feeindays[a-1]+=[b]
q=[]
heapq.heapify(q)
pay=0
for l in feeindays:
    for c in l:heapq.heappush(q,-c)
    if len(q)!=0:pay+=-1 * heapq.heappop(q)
print(pay)
Buggy code:
N, M =map(int, input().split())
A = [[] for i in range(10**5+1)]

for i in range(M):
    a, b = map(int,input().split())
    A[a].append(-b)

work_cand = []
sum = 0

for i in range(M+1):
    add_jobs = A[i]
    if len(add_jobs) != 0:
        for j in add_jobs:
            heapq.heappush(work_cand, j)
    sum += heapq.heappop(work_cand)
ans = -(sum)
print(ans)

Fixed code:
import heapq
N, M =map(int, input().split())
A = [[] for i in range(10**5+1)]
 
for i in range(N):
    a, b = map(int,input().split())
    if a > M:
        continue
    A[a].append(-b)
 
work_cand = []
sum = 0
 
for i in range(M+1):
    add_jobs = A[i]
    if len(add_jobs) != 0:
        for j in add_jobs:
            heapq.heappush(work_cand, j)
    if len(work_cand) == 0:
        continue
    sum += heapq.heappop(work_cand)
ans = -(sum)
print(ans)
Buggy code:
import heapq
N, M = map(int, input().split())
S = list()
A = [list() for _ in range(M+1)]
for _ in range(N):
    a, b = map(int, input().split())
    if M < a:
        continue
    heapq.heappush(A[M-a], -b)

ans = 0
for i in range(1, M+1):
    for num in A[i]:
        heapq.heappush(S, num)
    if S == []:
        continue
    ans -= heapq.heappop(S)
print(ans)


Fixed code:
import heapq
N, M = map(int, input().split())
S = list()
A = [list() for _ in range(M+1)]
for _ in range(N):
    a, b = map(int, input().split())
    if M < a:
        continue
    heapq.heappush(A[a], -b)

ans = 0
for i in range(1, M+1):
    for num in A[i]:
        heapq.heappush(S, num)
    if S == []:
        continue
    ans -= heapq.heappop(S)
print(ans)
Buggy code:
import heapq
n, m = map(int, input().split())
ab = [[] for _ in range(m)]
for _ in range(n):
    a, b = map(int, input().split())
    ab[a-1].append(-b)
heap = []
ans = 0
for i in range(m):
    for j in ab[i]:
        heapq.heappush(heap, j)
    if heap:
        res = heapq.heappop(heap)
        ans += -res
print(ans)

Fixed code:
import heapq
n, m = map(int, input().split())
ab = [[] for _ in range(m)]
for _ in range(n):
    a, b = map(int, input().split())
    if m >= a:
        ab[a-1].append(-b)
heap = []
ans = 0
for i in range(m):
    for j in ab[i]:
        heapq.heappush(heap, j)
    if heap:
        res = heapq.heappop(heap)
        ans += -res
print(ans)
Buggy code:
import heapq

N, M = map(int, input().split())
dic = {}
for i in range(N):
    A, B = map(int, input().split())
    if A not in dic:
        dic[A] = [-B]
    else:
        dic[A] += [-B]
print(dic, sorted(dic.keys()))

ans = 0
heap = []

for i in range(M):
    # print(i)
    if i + 1 in dic:
        heap += dic[i + 1]
    heapq.heapify(heap)
    # print(heap)
    if heap:
        ans += -heapq.heappop(heap)

print(ans)


Fixed code:
import heapq

N, M = map(int, input().split())
dic = {}
for i in range(N):
    A, B = map(int, input().split())
    if A not in dic:
        dic[A] = [-B]
    else:
        dic[A].append(-B)
# print(dic, sorted(dic.keys()))

ans = 0
heap = []

for i in range(M):
    # print(i)
    if i + 1 in dic:
        for j in dic[i + 1]:
            heapq.heappush(heap, j)
    # print(heap)
    if heap:
        ans = ans - heapq.heappop(heap)

print(ans)
Buggy code:
import heapq
n,m=map(int, input().split())
lst = []
for i in range(n):
  a,b=map(int, input().split())
  lst.append((-b,a))
lst = sorted(lst, key=lambda x:x[1])

now_idx = 0
queue = []
sum_ = 0
for i in range(1,m):
  for j in range(now_idx, n):
    if lst[j][1] <= i:
      heapq.heappush(queue, lst[j])
    else:
      now_idx = j
      break
  sum_ -= heapq.heappop(queue)
print(sum_)

Fixed code:
import heapq
n,m=map(int, input().split())
lst = []
for i in range(n):
  a,b=map(int, input().split())
  lst.append((-b,a))
lst = sorted(lst, key=lambda x:x[1])

now_idx = 0
queue = []
sum_ = 0
for i in range(1,m+1):
  for j in range(now_idx, n):
    if lst[j][1] <= i:
      heapq.heappush(queue, lst[j])
    else:
      now_idx = j
      break
  else:
    now_idx = n
  if len(queue)>0:
    sum_ -= heapq.heappop(queue)[0]
print(sum_)
Buggy code:
# -*- coding: utf-8 -*-
import heapq

N, M = map(int, input().split())
Wlist = []
for i in range(N):
    A, B = map(int, input().split())
    Wlist.append([A,B])
Wlist.sort(key=lambda x:x[0])

h = []
Ans = 0
Index = 0
for day in range(1,M+1):
    while Index < N:
        if Wlist[Index][0] <= day:
            heapq.heappush(h, -Wlist[Index][1])
            Index += 1
        else:
            break
    Ans += -heapq.heappop(h)

print(Ans)


Fixed code:
# -*- coding: utf-8 -*-
import heapq

N, M = map(int, input().split())
Wlist = []
for i in range(N):
    A, B = map(int, input().split())
    Wlist.append([A,B])
Wlist.sort(key=lambda x:x[0])

h = []
Ans = 0
Index = 0
for day in range(1,M+1):
    while Index < N:
        if Wlist[Index][0] <= day:
            heapq.heappush(h, -Wlist[Index][1])
            Index += 1
        else:
            break
    if len(h):
        Ans += -heapq.heappop(h)

print(Ans)
Buggy code:
N,M = input().split()
N,M = int(N),int(M)
f_start = [0 for i in range(N)]
A,B = [],[]
for i in range(N):
    a,b = input().split()
    a,b = int(a),int(b)
    A.append(a)
    B.append(-b)
    
def add(q_,add_):
    for i in range(len(add_)):
        heapq.heappush(q_,add_[i])

def kouho(A,B,m):
    kouho_list = []
    for i in range(len(B)):
        if(A[i]==m):
            kouho_list.append(B[i])
    return kouho_list

q = []
heapq.heapify(q)
sum_money = 0

for m in range(1,M+1):
    kouho_list = kouho(A,B,m)
    add(q,kouho_list)
    #print(q)
    if(len(q)>0):
        sum_money += -heapq.heappop(q)
print(sum_money)

Fixed code:
N,M = input().split()
N,M = int(N),int(M)
f_start = [0 for i in range(N)]
A,B = [],[]
import heapq
for i in range(N):
    a,b = input().split()
    a,b = int(a),int(b)
    A.append(a)
    B.append(-b)
    
def add(q_,add_):
    for i in range(len(add_)):
        heapq.heappush(q_,add_[i])

def kouho(A,B,M):
    kouho_list = [[] for i in range(M+1)]
    for i in range(len(A)):
        if(A[i]<=M):
            kouho_list[A[i]].append(B[i])
    return kouho_list

q = []
heapq.heapify(q)
sum_money = 0

kouho_list = kouho(A,B,M)
for m in range(1,M+1):
    kouho_ = kouho_list[m]
    add(q,kouho_)
    #print(q)
    if(len(q)>0):
        sum_money += -heapq.heappop(q)
print(sum_money)
Buggy code:
N,M = map(int,input().split())
lis = [[] for _ in range(M)]
sum = 0
for i in range(N):
    a,b = map(int,input().split())
    if a-1 < M:
        lis[a-1].append(-b)
print(lis)
import heapq
heap = []
for i in range(M):
    for e in lis[i]:
        heapq.heappush(heap,e)
    if len (heap) > 0:
        tmp = heapq.heappop(heap)
        sum += -tmp


    
print(sum)


Fixed code:
N,M = map(int,input().split())
lis = [[] for _ in range(M)]
sum = 0
for i in range(N):
    a,b = map(int,input().split())
    if a-1 < M:
        lis[a-1].append(-b)
import heapq
heap = []
for i in range(M):
    for e in lis[i]:
        heapq.heappush(heap,e)
    if len (heap) > 0:
        tmp = heapq.heappop(heap)
        sum += -tmp


    
print(sum)
Buggy code:
import heapq as hp

n,m =[int(i) for i in input().split()]
lists = [[] for i in range(m)]

for _ in range(n):
  a,b = [int(i) for i in input().split()]
  lists[a-1].append(b)
  
h = []
ans = 0
for day in range(m):
  for v in lists[day]:
    hp.heappush(h, -v)
  if len(h)>0:
    ans -= hp.heappop(h)
print(ans)
  

Fixed code:
import heapq as hp

n,m =[int(i) for i in input().split()]
lists = [[] for i in range(m)]

for _ in range(n):
  a,b = [int(i) for i in input().split()]
  if a<=m:
  	lists[a-1].append(b)
  
h = []
ans = 0
for day in range(m):
  for v in lists[day]:
    hp.heappush(h, -v)
  if len(h)>0:
    ans -= hp.heappop(h)
print(ans)
Buggy code:
import heapq

N, M = map(int, input().split())
AB = []
for i in range(N):
    a, b = map(int, input().split())
    heapq.heappush(AB, (a, b))

print(N, M, AB)

ans = 0
work = []
for i in range(M):
    remain = i + 1
    # print('remain={}, AB={}, ans={}'.format(remain, AB, ans))
    while len(AB) > 0:
        ab = heapq.heappop(AB)
        if ab[0] > remain:
            heapq.heappush(AB, ab)
            break
        heapq.heappush(work, (-ab[1], ab[0]))
    if len(work) == 0:
        continue
    v = heapq.heappop(work)
    ans -= v[0]
    # print('work={}'.format(work))
print(ans)


Fixed code:
import heapq

N, M = map(int, input().split())
AB = []
for i in range(N):
    a, b = map(int, input().split())
    heapq.heappush(AB, (a, b))

# print(N, M, AB)

ans = 0
work = []
for i in range(M):
    remain = i + 1
    # print('remain={}, AB={}, ans={}'.format(remain, AB, ans))
    while len(AB) > 0:
        ab = heapq.heappop(AB)
        if ab[0] > remain:
            heapq.heappush(AB, ab)
            break
        heapq.heappush(work, (-ab[1], ab[0]))
    if len(work) == 0:
        continue
    v = heapq.heappop(work)
    ans -= v[0]
    # print('work={}'.format(work))
print(ans)
Buggy code:

N,M = map(int,input().split())
AB = [list(map(int,input().split())) for _ in range(N)]
import heapq
AB.sort()
heap = []
heapq.heapify(heap)
ans = 0
i = 0
day = 1
while i < N and day <= M:
    while AB[i][0] <= day:
        heapq.heappush(heap,-AB[i][1])
        i += 1
    
    ans -= heapq.heappush(heap)

print(ans)

Fixed code:

N,M = map(int,input().split())
AB = [list(map(int,input().split())) for _ in range(N)]
import heapq
AB.sort()
heap = []
heapq.heapify(heap)
ans = 0
i = 0
day = 1
while day <= M:
    while i < N and AB[i][0] <= day:
        heapq.heappush(heap,-AB[i][1])
        i += 1
    day += 1
    if not(heap):continue
    ans -= heapq.heappop(heap)

print(ans)
Buggy code:
from collections import defaultdict
import heapq
n,m=map(int,input().split())
dic=defaultdict(list)
for i in range(n):
    a,b=map(int,input().split())
    dic[a]+=(-b)
    
li=[]
ans=0

for i in range(1,m+1):
    if dic[i]:
        for j in dic[i]:
            heapq.heappush(li,j)
    if li:
        ans+=heapq.heappop(li)
print(-ans)

Fixed code:
from collections import defaultdict
import heapq
n,m=map(int,input().split())
dic=defaultdict(list)
for i in range(n):
    a,b=map(int,input().split())
    dic[a].append(-b)
    
li=[]
ans=0

for i in range(1,m+1):
    if dic[i]:
        for j in dic[i]:
            heapq.heappush(li,j)
    if li:
        ans+=heapq.heappop(li)
print(-ans)
Buggy code:

import heapq
from collections import defaultdict

N, M = map(int, input().split())

a_b_dict = defaultdict(list)
for _ in range(N):
    a, b = tuple(map(int, input().split()))
    a_b_dict[a].append(b)


result = []
h = []
num_days = 0
for i in range(1, 1+M):
    for b in a_b_dict.get(i, []):
        heapq.heappush(h, -b)

    while len(result) < i:
        if len(h) > 0:
            result.append(-1*heapq.heappop(h))
        else:
            break

print(sum(result))



Fixed code:

import heapq
from collections import defaultdict

N, M = map(int, input().split())

a_b_dict = defaultdict(list)
for _ in range(N):
    a, b = tuple(map(int, input().split()))
    a_b_dict[a].append(b)

result = []
h = []
num_days = 0
for i in range(1, 1+M):
    for b in a_b_dict.get(i, []):
        heapq.heappush(h, -b)
    if len(h) > 0:
        result.append(-1*heapq.heappop(h))
print(sum(result))
Buggy code:
#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)

Fixed code:
#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)
        if tmp:
            ans += h.heappop(tmp)
        
    print(-ans)



if __name__=='__main__':
    main()
Buggy code:
def main():
    import sys
    sys.setrecursionlimit(10**9)
    input = sys.stdin.readline
    from heapq import heappush, heappop

    N, M = map(int, input().split())
    AB = [ [] for _ in range(100000) ]

    for _ in range(N):
        a, b = map(int, input().split())
        AB[a-1].append(-b)

    ans = 0
    heap = []
    for a in range(M):
        for b in AB[a]:
            heappush(heap, b)
        if heap:
            ans -= heappop(heap)

main()


Fixed code:
def main():
    import sys
    sys.setrecursionlimit(10**9)
    input = sys.stdin.readline
    from heapq import heappush, heappop

    N, M = map(int, input().split())
    AB = [ [] for _ in range(100000) ]

    for _ in range(N):
        a, b = map(int, input().split())
        AB[a-1].append(-b)

    ans = 0
    heap = []
    for a in range(M):
        for b in AB[a]:
            heappush(heap, b)
        if heap:
            ans -= heappop(heap)
    
    print(ans)

main()
Buggy code:
from itertools import accumulate
import heapq as hq
n,m = map(int,input().split())
ab = [list(map(int,input().split())) for i in range(n)]
ab.sort()
ls = []
hq.heapify(ls)
k = max([a[0] for a in ab])
daylist = [0]*(k+1)
for i in range(n):
  daylist[ab[i][0]] += 1
daylistsum = list(accumulate(daylist))
ans = 0
for i in range(1,m+1):
  for j in range(daylistsum[i-1],daylistsum[i]):
    hq.heappush(ls,-ab[j][1])
  if ls:
    ans -= hq.heappop(ls)
print(ans)

Fixed code:
from itertools import accumulate
import heapq as hq
n,m = map(int,input().split())
ab = [list(map(int,input().split())) for i in range(n)]
ab.sort()
ls = []
hq.heapify(ls)
k = max([a[0] for a in ab]+[m])
daylist = [0]*(k+1)
for i in range(n):
  daylist[ab[i][0]] += 1
daylistsum = list(accumulate(daylist))
ans = 0
for i in range(1,m+1):
  for j in range(daylistsum[i-1],daylistsum[i]):
    hq.heappush(ls,-ab[j][1])
  if ls:
    ans -= hq.heappop(ls)
print(ans)
Buggy code:
import bisect
n,m=map(int, input().split())
l={}
for i in range(n):
    a,b=map(int, input().split())
    if not a in l:
        l[a]=[b]
    else:
        l[a].append(b)

res=0
target=[0]
for i in range(1,m+1):
    if i in l:
        for j in l[i]:
            bisect.insort_left(target, j)
    val=target.pop()
    res+=val
    #print(target, max(target))

print(res)

Fixed code:
import bisect
import array

n,m=map(int, input().split())
l={}
for i in range(n):
    a,b=map(int, input().split())
    if not a in l:
        l[a]=[b]
    else:
        l[a].append(b)

res=0
target=array.array('I', [])
for i in range(1,m+1):
    if i in l:
        for j in l[i]:
            bisect.insort_left(target, j)

    if not target:
        val=0
    else:
        val=target.pop()
    res+=val
    #print(target, max(target))

print(res)
Buggy code:
import heapq
N, M = map(int, input().split())
W = [tuple(map(int, input().split())) for i in range(N)]
W.sort()
print(W)
h = []

j = 0
ans = 0
for i in range(M+1):
    while j < N and W[j][0] < i+1:
        heapq.heappush(h, (-W[j][1], W[j][1]))
        j += 1
    if h:
        p = heapq.heappop(h)
        ans += p[1]

print(ans)

Fixed code:
import heapq
N, M = map(int, input().split())
W = [tuple(map(int, input().split())) for i in range(N)]
W.sort()
h = []

j = 0
ans = 0
for i in range(M+1):
    while j < N and W[j][0] < i+1:
        heapq.heappush(h, (-W[j][1], W[j][1]))
        j += 1
    if h:
        p = heapq.heappop(h)
        ans += p[1]

print(ans)