Buggy python submission (verdict: Runtime Error):
from heapq import heappop, heappush
import sys
input = sys.stdin.readline

def calculate(N,M,arr):
    ret = 0

    j = 0

    res = []

    # 1,2,3,4,5
    #         ↑
    # 4,3,2,1

    # M = 4
    # range(1,5) => 1,2,3,4

    for i in range(1,M+1):
        # i = 1,2,3
        # 比如M=4的话，第三天(最多1天),第二天(最多2天),第一天(最多3天)

        # 记下来循环打工信息资源,以j为标记
        # j为资源编号
        # arr[j][0]为该编号资源的天数


        # 候补的资源，满足所有天数，因为是满足后续的天数来算的

        while (j < N) and (arr[j][0] <= i):

                heappush(res, -arr[j][1])
                j = j + 1 #j找到的话就往上顶一格，一共这一天，或者前一天寻找的时候以下一个资源天为开始

        if len(res) > 0:
            ret -= heappop(res)

    return ret


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


# 后面的逻辑是基于前面的从小到大的排序的
list = [list(map(int,input().split())) for i in range(N)]

arr = sorted(list,key=lambda x:x[0])

result = calculate(5,3,arr)

print(result)



Fixed submission:
from heapq import heappush, heappop
n, m = map(int, input().split())
jobs = {}
for _ in range(n):
  a, b = map(int, input().split())
  if a > m:
    continue
  if a in jobs:
    jobs[a].append(b)
  else:
    jobs[a] = [b]
result = 0
candidates = []
for a in range(1, m + 1):
  if a in jobs:
    for b in jobs[a]:
      heappush(candidates, -b)
  else:
    if len(candidates) == 0:
      continue
  result += -heappop(candidates)
print(result)

Buggy python submission (verdict: Runtime Error):
from heapq import heappop, heappush


def calculate(N,M,arr):
    ret = 0

    j = 0

    res = []

    # 1,2,3,4,5
    #         ↑
    # 4,3,2,1

    # M = 4
    # range(1,5) => 1,2,3,4

    for i in range(1,M+1):
        # i = 1,2,3
        # 比如M=4的话，第三天(最多1天),第二天(最多2天),第一天(最多3天)

        # 记下来循环打工信息资源,以j为标记
        # j为资源编号
        # arr[j][0]为该编号资源的天数


        # 候补的资源，满足所有天数，因为是满足后续的天数来算的

        while (j < N) and (arr[j][0] <= i):

                heappush(res, -arr[j][1])
                j = j + 1 #j找到的话就往上顶一格，一共这一天，或者前一天寻找的时候以下一个资源天为开始

        if len(res) > 0:
            ret -= heappop(res)

    return ret


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


# 后面的逻辑是基于前面的从小到大的排序的
list = [list(map(int,input().split())) for i in range(N)]

arr = sorted(list,key=lambda x:x[0])

result = calculate(5,3,arr)

print(result)



Fixed submission:
from heapq import heappush, heappop
n, m = map(int, input().split())
jobs = {}
for _ in range(n):
  a, b = map(int, input().split())
  if a > m:
    continue
  if a in jobs:
    jobs[a].append(b)
  else:
    jobs[a] = [b]
result = 0
candidates = []
for a in range(1, m + 1):
  if a in jobs:
    for b in jobs[a]:
      heappush(candidates, -b)
  else:
    if len(candidates) == 0:
      continue
  result += -heappop(candidates)
print(result)

Buggy python submission (verdict: Runtime Error):
def calculate(arr,M):
    sum = 0
    for i in range(M):
        index = 0
        value = 0
        for j in range(len(arr)):
            lastDay = i + arr[j][0]
            if lastDay <= M:
                if arr[j][1] > value:
                    index = j
                    value = arr[j][1]

                if (arr[j][1] == value) and (arr[index][0] < arr[j][0]):
                        index = j
                        value = arr[j][i]

        if len(arr) > 0:
            sum += value
            arr.pop(index)

        if len(arr) == 0:
            break

    return sum

N, M = map(int, input().split())
arr = []
for i in range(N):
    day, mount = map(int, input().split())
    arr.append([day,mount])
result = calculate(arr,M)
print(result)

Fixed submission:
from heapq import heappush, heappop
n, m = map(int, input().split())
jobs = {}
for _ in range(n):
  a, b = map(int, input().split())
  if a > m:
    continue
  if a in jobs:
    jobs[a].append(b)
  else:
    jobs[a] = [b]
result = 0
candidates = []
for a in range(1, m + 1):
  if a in jobs:
    for b in jobs[a]:
      heappush(candidates, -b)
  else:
    if len(candidates) == 0:
      continue
  result += -heappop(candidates)
print(result)

Buggy python submission (verdict: Runtime Error):
def calculate(arr,M):
    sum = 0
    for i in range(M):
        index = 0
        value = 0
        for j in range(len(arr)):
            lastDay = i + 1
            if lastDay <= M:
                if arr[j][1] > value:
                    index = j
                    value = arr[j][1]

                if (arr[j][1] == value) and (arr[index][0] < arr[j][0]):
                        index = j
                        value = arr[j][i]

        if len(arr) > 0:
            sum += value
            arr.pop(index)

        if len(arr) == 0:
            break

    return sum

N, M = map(int, input().split())
arr = []
for i in range(N):
    day, mount = map(int, input().split())
    arr.append([day,mount])
result = calculate(arr,M)
print(result)

Fixed submission:
from heapq import heappush, heappop
n, m = map(int, input().split())
jobs = {}
for _ in range(n):
  a, b = map(int, input().split())
  if a > m:
    continue
  if a in jobs:
    jobs[a].append(b)
  else:
    jobs[a] = [b]
result = 0
candidates = []
for a in range(1, m + 1):
  if a in jobs:
    for b in jobs[a]:
      heappush(candidates, -b)
  else:
    if len(candidates) == 0:
      continue
  result += -heappop(candidates)
print(result)

Buggy python submission (verdict: Runtime Error):
def calculate(arr,M):
    sum = 0
    for i in range(M):
        index = 0
        value = 0
        for j in range(len(arr)):
            lastDay = i + arr[j][0]
            if lastDay <= M:
                # if arr[j][1] > value:
                #     index = j
                #     value = arr[j][1]
                # 
                # if (arr[j][1] == value) and (arr[index][0] < arr[j][0]):
                #         index = j
                #         value = arr[j][i]

        if len(arr) > 0:
            sum += value
            arr.pop(index)

        if len(arr) == 0:
            break

    return sum

N, M = map(int, input().split())
arr = []
for i in range(N):
    day, mount = map(int, input().split())
    arr.append([day,mount])
result = calculate(arr,M)
print(result)

Fixed submission:
from heapq import heappush, heappop
n, m = map(int, input().split())
jobs = {}
for _ in range(n):
  a, b = map(int, input().split())
  if a > m:
    continue
  if a in jobs:
    jobs[a].append(b)
  else:
    jobs[a] = [b]
result = 0
candidates = []
for a in range(1, m + 1):
  if a in jobs:
    for b in jobs[a]:
      heappush(candidates, -b)
  else:
    if len(candidates) == 0:
      continue
  result += -heappop(candidates)
print(result)

Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
d1 = {}
for _ in range(n):
  a, b = map(int, input().split())
  if a in d1:
    d1[a].append(b)
  else:
    d1[a] = [b]
result = 0
d2 = {}
maxb = -1
for i in range(1, m + 1):
  if i in d1:
    for j in d1[i]:
      if j not in d2:
        d2[j] = 0
      d2[j] += 1
      if j > maxb:
        maxb = j
  else:
    if len(d2) == 0:
      continue
  result += maxb
  if d2[maxb] == 1:
    del d2[maxb]
    if len(d2) == 0:
      maxb = 0
    else:
      maxb = max(d2.keys())
  else:
    d2[maxb] -= 1
print(result)

Fixed submission:
from heapq import heappush, heappop
n, m = map(int, input().split())
jobs = {}
for _ in range(n):
  a, b = map(int, input().split())
  if a > m:
    continue
  if a in jobs:
    jobs[a].append(b)
  else:
    jobs[a] = [b]
result = 0
candidates = []
for a in range(1, m + 1):
  if a in jobs:
    for b in jobs[a]:
      heappush(candidates, -b)
  else:
    if len(candidates) == 0:
      continue
  result += -heappop(candidates)
print(result)

Buggy python submission (verdict: Runtime Error):
def calculate(arr,M):
    sum = 0
    for i in range(M):
        index = 0
        value = 0
        for j in range(len(arr)):

            if len(arr) == 0:
                arr[j] = [0,0]
            if len(arr) == 1:
                arr[j][1] = 0

            lastDay = i + arr[j][0]
            if lastDay <= M:
                if arr[j][1] > value:
                    index = j
                    value = arr[j][1]

                if arr[j][1] == value:
                    if arr[index][0] < arr[j][0]:
                        index = j
                        value = arr[j][i]

        if len(arr) > 0:
            sum += value
            arr.pop(index)

        if len(arr) == 0:
            break

    return sum

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


arr = []
for i in range(N):
    day, mount = map(int, input().split())
    day = int(day)
    mount = int(mount)
    arr.append([day,mount])
result = calculate(arr,M)
print(result)

Fixed submission:
from heapq import heappush, heappop
n, m = map(int, input().split())
jobs = {}
for _ in range(n):
  a, b = map(int, input().split())
  if a > m:
    continue
  if a in jobs:
    jobs[a].append(b)
  else:
    jobs[a] = [b]
result = 0
candidates = []
for a in range(1, m + 1):
  if a in jobs:
    for b in jobs[a]:
      heappush(candidates, -b)
  else:
    if len(candidates) == 0:
      continue
  result += -heappop(candidates)
print(result)

Buggy python submission (verdict: Runtime Error):
def calculate(arr,M):
    sum = 0
    for i in range(M):
        index = 0
        value = 0
        for j in range(len(arr)):
            lastDay = i + arr[j][0]
            if lastDay <= M:
                if arr[j][1] > value:
                    index = j
                    value = arr[j][1]

                if (arr[j][1] == value) and (arr[index][0] < arr[j][0]):
                        index = j
                        value = arr[j][i]

        if len(arr) > 0:
            sum += value
            arr.pop(index)

        if len(arr) == 0:
            break

    return sum

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


arr = []
for i in range(N):
    day, mount = map(int, input().split())
    day = int(day)
    mount = int(mount)
    arr.append([day,mount])
result = calculate(arr,M)
print(result)

Fixed submission:
from heapq import heappush, heappop
n, m = map(int, input().split())
jobs = {}
for _ in range(n):
  a, b = map(int, input().split())
  if a > m:
    continue
  if a in jobs:
    jobs[a].append(b)
  else:
    jobs[a] = [b]
result = 0
candidates = []
for a in range(1, m + 1):
  if a in jobs:
    for b in jobs[a]:
      heappush(candidates, -b)
  else:
    if len(candidates) == 0:
      continue
  result += -heappop(candidates)
print(result)

Buggy python submission (verdict: Runtime Error):
def calculate(arr,M):
    sum = 0
    for i in range(M):
        index = 0
        value = 0
        for j in range(len(arr)):
            lastDay = i + arr[j][0]
            if lastDay <= M:
                if arr[j][1] > value:
                    index = j
                    value = arr[j][1]

                if (arr[j][1] == value) and (arr[index][0] < arr[j][0]):
                        index = j
                        value = arr[j][i]

        if len(arr) > 0:
            sum += value
            arr.pop(index)

        if len(arr) == 0:
            break

    return sum


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


arr = []
for i in range(N):
    day,mount = input().split()
    day = int(day)
    mount = int(mount)
    arr.append([day,mount])
result = calculate(arr,M)
print(result)

Fixed submission:
from heapq import heappush, heappop
n, m = map(int, input().split())
jobs = {}
for _ in range(n):
  a, b = map(int, input().split())
  if a > m:
    continue
  if a in jobs:
    jobs[a].append(b)
  else:
    jobs[a] = [b]
result = 0
candidates = []
for a in range(1, m + 1):
  if a in jobs:
    for b in jobs[a]:
      heappush(candidates, -b)
  else:
    if len(candidates) == 0:
      continue
  result += -heappop(candidates)
print(result)