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

li = [[] for j in range(10**5+1)]

for _ in range(n):
  a, b = map(int, input().split())
  li[a].append(b)

ans = 0
jobs = []
for i in range(1, m+1):
  jobs.extend(li[i])
  if jobs == []:
    continue
  jobs.sort(reverse = True)
  ans += jobs.pop(0)
print(ans)

Fixed submission:
def insertHeap(array, val):
    array.append(val)
    n = len(array)-1
    while n != 0:
        parent = int((n - 1) / 2)
        if array[n] > array[parent]:
            tmp = array[n]
            array[n] = array[parent]
            array[parent] = tmp
            n = parent
        else:
            break
    return array

def desertHeap(array):
    if array == []:
      return None
    array[0], array[-1] = array[-1], array[0]
    res = array.pop(-1)
    n = len(array)
    if n == 0 or n == 1: 
      return res
    parent = 0
    while True:
        child = 2 * parent + 1
        if child >= n: break
        if (child + 1 < n) and array[child] < array[child + 1]:
            child += 1
        if array[parent] < array[child]:
            array[child], array[parent] = array[parent], array[child]
            parent = child;
        else:
            break
    return res

n, m = map(int, input().split())
 
li = [[] for j in range(10**5+1)]
 
for _ in range(n):
  a, b = map(int, input().split())
  li[a].append(b)
 
ans = 0
jobsHeap = []
for i in range(1, m+1):
  for val in li[i]:
    jobsHeap = insertHeap(jobsHeap, val)
  
  if jobsHeap != []:
    res = desertHeap(jobsHeap)
    ans += res
print(ans)

Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())

md = []
for i in range(0,N):
  d, m = map(int, input().split())
  md.append({"m":m, "d":d-1})

md = sorted(md, key=lambda x:x["m"], reverse=True)

def aa(sh, idx, M, x, ans):
  if idx >= M:
    return sh, ans, x
  elif sh[idx] == 0:
    sh[idx] = idx+1
    sh[x["d"]] = idx+1
    ans += x["m"]
    return sh, ans, x
  else:
    zz = idx
    sh, ans, x = aa(sh, sh[idx], M, x, ans)
    sh[zz] = sh[x["d"]]
    return sh, ans, x
  
sh = [0]*M
ans = 0
for x in md:
  idx = x["d"]
  sh, ans, x = aa(sh, idx, M, x, ans)
print(ans)

Fixed submission:
def insertHeap(array, val):
    array.append(val)
    n = len(array)-1
    while n != 0:
        parent = int((n - 1) / 2)
        if array[n] > array[parent]:
            tmp = array[n]
            array[n] = array[parent]
            array[parent] = tmp
            n = parent
        else:
            break
    return array

def desertHeap(array):
    if array == []:
      return None
    array[0], array[-1] = array[-1], array[0]
    res = array.pop(-1)
    n = len(array)
    if n == 0 or n == 1: 
      return res
    parent = 0
    while True:
        child = 2 * parent + 1
        if child >= n: break
        if (child + 1 < n) and array[child] < array[child + 1]:
            child += 1
        if array[parent] < array[child]:
            array[child], array[parent] = array[parent], array[child]
            parent = child;
        else:
            break
    return res

n, m = map(int, input().split())
 
li = [[] for j in range(10**5+1)]
 
for _ in range(n):
  a, b = map(int, input().split())
  li[a].append(b)
 
ans = 0
jobsHeap = []
for i in range(1, m+1):
  for val in li[i]:
    jobsHeap = insertHeap(jobsHeap, val)
  
  if jobsHeap != []:
    res = desertHeap(jobsHeap)
    ans += res
print(ans)

Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())

md = []
for i in range(0,N):
  d, m = map(int, input().split())
  md.append({"m":m, "d":d-1})

md = sorted(md, key=lambda x:x["m"], reverse=True)

def aa(sh, idx, M, x, ans):
  if idx >= M:
    return sh, ans, x
  elif sh[idx] == 0:
    sh[idx] = idx+1
    sh[x["d"]] = idx+1
    ans += x["m"]
    return sh, ans, x
  else:
    sh, ans, x = aa(sh, sh[idx], M, x, ans)
    sh[idx] = sh[x["d"]]
    return sh, ans, x
  
sh = [0]*M
ans = 0
for x in md:
  idx = x["d"]
  sh, ans, x = aa(sh, idx, M, x, ans)
print(ans)

Fixed submission:
def insertHeap(array, val):
    array.append(val)
    n = len(array)-1
    while n != 0:
        parent = int((n - 1) / 2)
        if array[n] > array[parent]:
            tmp = array[n]
            array[n] = array[parent]
            array[parent] = tmp
            n = parent
        else:
            break
    return array

def desertHeap(array):
    if array == []:
      return None
    array[0], array[-1] = array[-1], array[0]
    res = array.pop(-1)
    n = len(array)
    if n == 0 or n == 1: 
      return res
    parent = 0
    while True:
        child = 2 * parent + 1
        if child >= n: break
        if (child + 1 < n) and array[child] < array[child + 1]:
            child += 1
        if array[parent] < array[child]:
            array[child], array[parent] = array[parent], array[child]
            parent = child;
        else:
            break
    return res

n, m = map(int, input().split())
 
li = [[] for j in range(10**5+1)]
 
for _ in range(n):
  a, b = map(int, input().split())
  li[a].append(b)
 
ans = 0
jobsHeap = []
for i in range(1, m+1):
  for val in li[i]:
    jobsHeap = insertHeap(jobsHeap, val)
  
  if jobsHeap != []:
    res = desertHeap(jobsHeap)
    ans += res
print(ans)

Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())

md = []
for i in range(0,N):
  d, m = map(int, input().split())
  md.append({"m":m, "d":d-1})

md = sorted(md, key=lambda x:x["m"], reverse=True)

def aa(sh, idx, M, x, ans):
  if idx >= M:
    return sh, ans, x
  elif sh[idx] == 0:
    sh[idx] = idx+1
    sh[x["d"]] = idx+1
    ans += x["m"]
    return sh, ans, x
  else:
    sh, ans, x = aa(sh, sh[idx], M, x, ans)
    sh[idx] = sh[x["d"]]
    idx = sh[idx]
    return sh, ans, x
  
sh = [0]*M
ans = 0
for x in md:
  idx = x["d"]
  sh, ans, x = aa(sh, idx, M, x, ans)
print(ans)

Fixed submission:
def insertHeap(array, val):
    array.append(val)
    n = len(array)-1
    while n != 0:
        parent = int((n - 1) / 2)
        if array[n] > array[parent]:
            tmp = array[n]
            array[n] = array[parent]
            array[parent] = tmp
            n = parent
        else:
            break
    return array

def desertHeap(array):
    if array == []:
      return None
    array[0], array[-1] = array[-1], array[0]
    res = array.pop(-1)
    n = len(array)
    if n == 0 or n == 1: 
      return res
    parent = 0
    while True:
        child = 2 * parent + 1
        if child >= n: break
        if (child + 1 < n) and array[child] < array[child + 1]:
            child += 1
        if array[parent] < array[child]:
            array[child], array[parent] = array[parent], array[child]
            parent = child;
        else:
            break
    return res

n, m = map(int, input().split())
 
li = [[] for j in range(10**5+1)]
 
for _ in range(n):
  a, b = map(int, input().split())
  li[a].append(b)
 
ans = 0
jobsHeap = []
for i in range(1, m+1):
  for val in li[i]:
    jobsHeap = insertHeap(jobsHeap, val)
  
  if jobsHeap != []:
    res = desertHeap(jobsHeap)
    ans += res
print(ans)

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

md = []
for i in range(0,N):
  d, m = map(int, input().split())
  md.append({"m":m, "d":d-1})

md = sorted(md, key=lambda x:x["m"], reverse=True)

def aa(sh, idx, M, x, ans):
  while idx < M :
    if sh[idx] == 0:
      sh[idx] = idx+1
      sh[x["d"]] = idx+1
      ans += x["m"]
      break
    else:
      idx = sh[idx]
  return sh, idx, M, x, ans
  
sh = [0]*M
ans = 0
for x in md:
  idx = x["d"]
  sh, idx, M, x, ans = aa(sh, idx, M, x, ans)
print(ans)

Fixed submission:
def insertHeap(array, val):
    array.append(val)
    n = len(array)-1
    while n != 0:
        parent = int((n - 1) / 2)
        if array[n] > array[parent]:
            tmp = array[n]
            array[n] = array[parent]
            array[parent] = tmp
            n = parent
        else:
            break
    return array

def desertHeap(array):
    if array == []:
      return None
    array[0], array[-1] = array[-1], array[0]
    res = array.pop(-1)
    n = len(array)
    if n == 0 or n == 1: 
      return res
    parent = 0
    while True:
        child = 2 * parent + 1
        if child >= n: break
        if (child + 1 < n) and array[child] < array[child + 1]:
            child += 1
        if array[parent] < array[child]:
            array[child], array[parent] = array[parent], array[child]
            parent = child;
        else:
            break
    return res

n, m = map(int, input().split())
 
li = [[] for j in range(10**5+1)]
 
for _ in range(n):
  a, b = map(int, input().split())
  li[a].append(b)
 
ans = 0
jobsHeap = []
for i in range(1, m+1):
  for val in li[i]:
    jobsHeap = insertHeap(jobsHeap, val)
  
  if jobsHeap != []:
    res = desertHeap(jobsHeap)
    ans += res
print(ans)

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

md = []
for i in range(0,N):
  d, m = map(int, input().split())
  md.append({"m":m, "d":d-1})

md = sorted(md, key=lambda x:x["m"], reverse=True)

sh = [0]*M
ans = 0
for x in md:
  idx = x["d"]
  while idx < M :
    if sh[idx] == 0:
      if idx + 1 < M and sh[idx+1]!= 0:
        sh[idx] = sh[idx+1]
        sh[x["d"]] = sh[idx+1]
      else:
        sh[idx] = idx+1
        sh[x["d"]] = idx+1
      ans += x["m"]
      break
    else:
      idx = sh[idx]
print(ans)

Fixed submission:
def insertHeap(array, val):
    array.append(val)
    n = len(array)-1
    while n != 0:
        parent = int((n - 1) / 2)
        if array[n] > array[parent]:
            tmp = array[n]
            array[n] = array[parent]
            array[parent] = tmp
            n = parent
        else:
            break
    return array

def desertHeap(array):
    if array == []:
      return None
    array[0], array[-1] = array[-1], array[0]
    res = array.pop(-1)
    n = len(array)
    if n == 0 or n == 1: 
      return res
    parent = 0
    while True:
        child = 2 * parent + 1
        if child >= n: break
        if (child + 1 < n) and array[child] < array[child + 1]:
            child += 1
        if array[parent] < array[child]:
            array[child], array[parent] = array[parent], array[child]
            parent = child;
        else:
            break
    return res

n, m = map(int, input().split())
 
li = [[] for j in range(10**5+1)]
 
for _ in range(n):
  a, b = map(int, input().split())
  li[a].append(b)
 
ans = 0
jobsHeap = []
for i in range(1, m+1):
  for val in li[i]:
    jobsHeap = insertHeap(jobsHeap, val)
  
  if jobsHeap != []:
    res = desertHeap(jobsHeap)
    ans += res
print(ans)

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

md = []
for i in range(0,N):
  d, m = map(int, input().split())
  md.append({"m":m, "d":d-1})

md = sorted(md, key=lambda x:x["m"], reverse=True)

sh = [0]*M
ans = 0
for x in md:
  idx = x["d"]
  while idx < M :
    if sh[idx] == 0:
      sh[idx] = idx+1
      sh[x["d"]] = idx+1
      ans += x["m"]
      break
    else:
      idx = sh[idx]
print(ans)

Fixed submission:
def insertHeap(array, val):
    array.append(val)
    n = len(array)-1
    while n != 0:
        parent = int((n - 1) / 2)
        if array[n] > array[parent]:
            tmp = array[n]
            array[n] = array[parent]
            array[parent] = tmp
            n = parent
        else:
            break
    return array

def desertHeap(array):
    if array == []:
      return None
    array[0], array[-1] = array[-1], array[0]
    res = array.pop(-1)
    n = len(array)
    if n == 0 or n == 1: 
      return res
    parent = 0
    while True:
        child = 2 * parent + 1
        if child >= n: break
        if (child + 1 < n) and array[child] < array[child + 1]:
            child += 1
        if array[parent] < array[child]:
            array[child], array[parent] = array[parent], array[child]
            parent = child;
        else:
            break
    return res

n, m = map(int, input().split())
 
li = [[] for j in range(10**5+1)]
 
for _ in range(n):
  a, b = map(int, input().split())
  li[a].append(b)
 
ans = 0
jobsHeap = []
for i in range(1, m+1):
  for val in li[i]:
    jobsHeap = insertHeap(jobsHeap, val)
  
  if jobsHeap != []:
    res = desertHeap(jobsHeap)
    ans += res
print(ans)

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

md = []
for i in range(0,N):
  d, m = map(int, input().split())
  md.append({"m":m, "d":d-1})

md = sorted(md, key=lambda x:x["m"], reverse=True)

sh = [0]*M
ans = 0
for x in md:
  idx = x["d"]
  while idx < M :
    if sh[idx] == 0:
      sh[idx] = idx+1
      ans += x["m"]
      break
    else:
      idx = sh[idx]
print(ans)

Fixed submission:
def insertHeap(array, val):
    array.append(val)
    n = len(array)-1
    while n != 0:
        parent = int((n - 1) / 2)
        if array[n] > array[parent]:
            tmp = array[n]
            array[n] = array[parent]
            array[parent] = tmp
            n = parent
        else:
            break
    return array

def desertHeap(array):
    if array == []:
      return None
    array[0], array[-1] = array[-1], array[0]
    res = array.pop(-1)
    n = len(array)
    if n == 0 or n == 1: 
      return res
    parent = 0
    while True:
        child = 2 * parent + 1
        if child >= n: break
        if (child + 1 < n) and array[child] < array[child + 1]:
            child += 1
        if array[parent] < array[child]:
            array[child], array[parent] = array[parent], array[child]
            parent = child;
        else:
            break
    return res

n, m = map(int, input().split())
 
li = [[] for j in range(10**5+1)]
 
for _ in range(n):
  a, b = map(int, input().split())
  li[a].append(b)
 
ans = 0
jobsHeap = []
for i in range(1, m+1):
  for val in li[i]:
    jobsHeap = insertHeap(jobsHeap, val)
  
  if jobsHeap != []:
    res = desertHeap(jobsHeap)
    ans += res
print(ans)