Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
n = int(input())

scores = list(map(int, input().split()))

colors = [0] * 8
over = 0

for score in scores:
    if score < 3200:
        colors[score // 400] += 1
    else:
        over += 1

ans = sum(colors > 0 for color in colors)

print(ans, ans + over)



Fixed submission:
n = int(input())

scores = list(map(int, input().split()))

colors = [0] * 8
over = 0

for score in scores:
    if score < 3200:
        colors[score // 400] += 1
    else:
        over += 1

ans = sum(color > 0 for color in colors)

if ans:
    print(ans, ans + over)
else:
    print(1, over)

Buggy python submission (verdict: Runtime Error):
n = int(input())
scores = list(map(int, input().split()))
colors = [0] * 9

for score in scores:
    colors[score // 400] += 1

ans = sum(colors[x] > 0 for x in range(8))
print(ans, ans + colors[8])

Fixed submission:
n = int(input())

scores = list(map(int, input().split()))

colors = [0] * 8
over = 0

for score in scores:
    if score < 3200:
        colors[score // 400] += 1
    else:
        over += 1

ans = sum(color > 0 for color in colors)

if ans:
    print(ans, ans + over)
else:
    print(1, over)

Buggy python submission (verdict: Runtime Error):
n = int(input())

scores = list(map(int, input().split()))

colors = [0] * 9

for score in scores:
    colors[score // 400] += 1

ans = sum(colors[x] > 0 for x in range(8))\

print(ans, min(8, ans + colors[8]))



Fixed submission:
n = int(input())

scores = list(map(int, input().split()))

colors = [0] * 8
over = 0

for score in scores:
    if score < 3200:
        colors[score // 400] += 1
    else:
        over += 1

ans = sum(color > 0 for color in colors)

if ans:
    print(ans, ans + over)
else:
    print(1, over)
Buggy python submission (verdict: Runtime Error):
a, b, c = map(int, input().split())

print("Yes" if a <= c <= b else "No)

Fixed submission:
a, b, c = map(int, input().split())

print("Yes" if a <= c <= b else "No")
Buggy python submission (verdict: Runtime Error):
n, time = map(int, input().split())
 
arr = list(map(int, input().split())) + [float("inf")]
 
left, temp, sum_time = 0, 0, 0
 
for t in arr[1:]:
  if t <= temp + time:
    temp = t
  else:
    sum_time += (temp + time - left)
    left, temp = t
 
print(sum_time)

Fixed submission:
n, time = map(int, input().split())
 
arr = list(map(int, input().split())) + [float("inf")]
 
left, temp, sum_time = 0, 0, 0
 
for t in arr[1:]:
  if t <= temp + time:
    temp = t
  else:
    sum_time += (temp + time - left)
    left, temp = t, t
 
print(sum_time)

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

arr = list(map(int, input().split())) + [float("inf")]

left, temp, sum_time = 0, 0, 0

for t in arr[1:]:
  if t <= left + time:
    temp = t
  else:
    sum_time += (temp + time - left)
    left, temp = t

print(sum_time)


Fixed submission:
n, time = map(int, input().split())
 
arr = list(map(int, input().split())) + [float("inf")]
 
left, temp, sum_time = 0, 0, 0
 
for t in arr[1:]:
  if t <= temp + time:
    temp = t
  else:
    sum_time += (temp + time - left)
    left, temp = t, t
 
print(sum_time)
Buggy python submission (verdict: Runtime Error):
a, b, c = map(int, input().split())

print("YES" if b - a = c - b else "NO")

Fixed submission:
a, b, c = map(int, input().split())

print("YES" if b - a == c - b else "NO")
Buggy python submission (verdict: Runtime Error):
n, m = map(int, input().split())

abs = [list(map(int, input().split())) for _ in range(n)]
cds = [list(map(int, input().split())) for _ in range(m)]

for a, b in abs:
  min_distance = float("inf")
  min_checkpoint = 0
  for i, cd in enumerate(cds):
    c, d = cd
    if abs(c - a) + abs(d - b) < min_checkpoint:
      min_checkpoint = i + 1
  print(min_checkpoint)

Fixed submission:
n, m = map(int, input().split())

students = [list(map(int, input().split())) for _ in range(n)]
checkpoints = [list(map(int, input().split())) for _ in range(m)]

for a, b in students:
    min_distance = float("inf")
    min_checkpoint = 0
    for i, cd in enumerate(checkpoints):
        c, d = cd
        if abs(c - a) + abs(d - b) < min_distance:
            min_checkpoint = i + 1
            min_distance = abs(c - a) + abs(d - b)
    print(min_checkpoint)
Buggy python submission (verdict: Runtime Error):
def divisible_length(n):
	min_length = len(str(n))
  	for i in range(1, int(n ** 0.5) + 1):
        if n % i == 0:
            min_length = min(min_length, len(str(i)))
            if i != n // i:
	            min_length = min(min_length, len(str(n // i)))
    return min_length


n = int(input())
print(divisible_length(n))

Fixed submission:
def divisible_length(n):
    min_length = len(str(n))
    for i in range(1, int(n ** 0.5) + 1):
        if n % i == 0:
            min_length = min(min_length, max(len(str(i)), len(str(n // i))))
    return min_length

n = int(input())
print(divisible_length(n))
Buggy python submission (verdict: Time Limit Exceeded):
def word_break(s, words):
    ok = [True]
    for i in range(1, len(s)+1):
        ok += any(ok[j] and s[j:i] in words for j in range(i)),
    return ok[-1]


s = input()
words = ["eraser", "erase", "dreamer", "dream"]
print("YES" if word_break(s, words) else "NO")

Fixed submission:
s = input()

while s:
    if s[:6] == "eraser":
        s = s[6:]
    elif s[:5] == "erase":
        s = s[5:]
    elif s[:5] == "dream":
        if s[5:8] == "era":
            s = s[5:]
        elif s[5:7] == "er":
            s = s[7:]
        else:
            s = s[5:]
    else:
        print("NO")
        exit()
print("YES")
Buggy python submission (verdict: Runtime Error):
w, h, n = map(int, input().split())

x1, x2, y3, y4 = [], [], [], []

for _ in range(n):
  x, y, a = map(int, input().split())
  if a == 1:
    x1.append(x)
  elif a == 2:
    x2.append(x)
  elif a == 3:
    y3.append(y)
  else:
    y4.append(y)

print(max(min(w, min(x2)) - max(max(x1), 0), 0) * max(min(h, min(y4)) - max(max(y3), 0), 0))


Fixed submission:
w, h, n = map(int, input().split())

x1, x2, y3, y4 = [0], [w], [0], [h]

for _ in range(n):
    x, y, a = map(int, input().split())
    if a == 1:
        x1.append(x)
    elif a == 2:
        x2.append(x)
    elif a == 3:
        y3.append(y)
    else:
        y4.append(y)

print(max(min(x2) - max(x1), 0) * max(min(y4) - max(y3), 0))
Buggy python submission (verdict: Runtime Error):
x = list(map(int, input().split()))

print(len(set(x))

Fixed submission:
x = list(map(int, input().split()))
 
print(len(set(x)))
Buggy python submission (verdict: Runtime Error):

S = {c: input() for c in "abc"}

s = "a"

while S[s]:
  s = S[s].pop(0)

print(s.upper())

Fixed submission:
import sys

p = ["A", "B", "C"]
p_dic = {"a": 0, "b": 1, "c": 2}

def card(cards, player):
  if len(cards[player]) == 0:
    print(p[player])
    sys.exit()
  else:
    x = cards[player][0]
    cards[player] = cards[player][1:]
    card(cards, p_dic[x])

cards = [input() for i in range(3)]
card(cards, 0)

Buggy python submission (verdict: Runtime Error):
import sys

p = ["A", "B", "C"]
p_dic = {"a": 0, "b": 1, "c": 2}

def card(cards, player):
  if len(cards[player]) == 1:
    print(p[player])
    sys.exit()
  else:
    x = cards[player][0]
    cards[player] = cards[player][1:]
    def card(cards, p_dic[x])

cards = [input() for i in range(3)]
card(cards, 0)

Fixed submission:
import sys

p = ["A", "B", "C"]
p_dic = {"a": 0, "b": 1, "c": 2}

def card(cards, player):
  if len(cards[player]) == 0:
    print(p[player])
    sys.exit()
  else:
    x = cards[player][0]
    cards[player] = cards[player][1:]
    card(cards, p_dic[x])

cards = [input() for i in range(3)]
card(cards, 0)
Buggy python submission (verdict: Runtime Error):
w = input()

import collections

c = collections.Counter(w)

b = True
for i in c.values:
  if i % 2 == 1:
    b = False

print("Yes" if b else "No")

Fixed submission:
w = input()

import collections

c = collections.Counter(w)

b = True
for i in c.values():
  if i % 2 == 1:
    b = False

print("Yes" if b else "No")
Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict


n, k = map(int, input().split())

arr = list(map(int, input().split()))

arr = [x - k for x in arr]
arr.sort()

arr_minus = [-x for x in arr if x < 0]
arr_zero = sum(x==0 for x in arr)
arr_plus = [x for x in arr if x > 0]

minus_nums = defaultdict(int)

for i in range(1, 2 ** len(arr_minus)):
    bin_minus = "{:050b}".format(i)[::-1]
    item = sum(x for idx, x in enumerate(arr_minus) if bin_minus[idx] == "1")
    minus_nums[item] += 1

cnt = 0
for i in range(1, 2 ** len(arr_plus)):
    bin_plus = "{:050b}".format(i)[::-1]
    item = sum(x for idx, x in enumerate(arr_plus) if bin_plus[idx] == "1")
    cnt += minus_nums[item]

print((1 + cnt) * 2 ** arr_zero - 1)

Fixed submission:
from collections import defaultdict

n, k = map(int, input().split())
arr = list(map(int, input().split()))
arr = [x - k for x in arr]

dct = defaultdict(int)
dct[0] = 1

for x in arr:
    for k, v in list(dct.items()):
        dct[k + x] += v

print(dct[0] - 1)
Buggy python submission (verdict: Runtime Error):
def main():
    num = int(K)
    if num >= len(S):
        print(S)
    else:
        print(S[:num]+'...')

K, S = input().split()

main()


Fixed submission:
def main():
    num = int(K)
    if num >= len(S):
        print(S)
    else:
        print(S[:num]+'...')

K = int(input())
S = input()

main()
Buggy python submission (verdict: Runtime Error):
message = input()

temp_list=list(message)


if (temp_list[2] == temp_list[3]) and (temp_list[4] == temp_list[5]):
    print("Yes")
else
    print("No")

Fixed submission:
message = input()

temp_list=list(message)


if (temp_list[2] == temp_list[3]) and (temp_list[4] == temp_list[5]):
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Runtime Error):
#!/usr/bin/python3

import sys
# input = sys.stdin.readline
sys.setrecursionlimit(100000)
INF = float('inf')
MOD = 10**9+7
EPS = 10**-7

#N = int(input())
#A = [int(x) for x in input().split()]
#V = [[0] * 100 for _ in range(100)]

A, B, C = [x for x in input().split()]
print(f"{C} {A} {B}")

Fixed submission:
#!/usr/bin/python3

import sys
# input = sys.stdin.readline
sys.setrecursionlimit(100000)
INF = float('inf')
MOD = 10**9+7
EPS = 10**-7

#N = int(input())
#A = [int(x) for x in input().split()]
#V = [[0] * 100 for _ in range(100)]

A, B, C = [x for x in input().split()]
print("{} {} {}".format(C,A,B))
Buggy python submission (verdict: Time Limit Exceeded):
import math
import sys
sys.setrecursionlimit(1000000000)
from functools import lru_cache

N = int(input())
K = int(input())

# f(N,K)が回答になるようにする。
@lru_cache(maxsize=10009900)
def f(n, k):
    # 終了条件
    if n < 10:
        if k==0:
            return 1
        elif k==1:
            return n
        return 0
    
    ret = 0
    z = int(math.log10(n))
    keta = 10**z
    base = n % keta

    # 0のとき
    ret += f(keta-1, k)
    # 1..9のとき
    for i in range(1,10):
        if keta * (i+1) <= n:
            ret += f(keta-1, k-1)
        elif keta * i <= n:
            ret += f(base, k-1)

    return ret

print(f(N,K))

Fixed submission:
import sys
import math
sys.setrecursionlimit(1000000)


N = int(input())
K = int(input())

from functools import lru_cache

@lru_cache(maxsize=10000)
def f(n,k):
    # print('n:{},k:{}'.format(n,k))
    if k == 0:
        return 1
    if k== 1 and n < 10:
        return n

    keta = len(str(n))
    if keta < k:
        return 0

    h = n // (10 ** (keta-1))
    b = n % (10 ** (keta-1))

    ret = 0
    for i in range(h+1):
        if i==0:
            ret += f(10 ** (keta-1) - 1, k)
        elif 1 <= i < h:
            ret += f(10 ** (keta-1) - 1, k-1)
        else:
            ret += f(b,k-1)
        
    return ret

print(f(N,K))
Buggy python submission (verdict: Time Limit Exceeded):
import bisect

N = int(input())
L = [int(x) for x in input().split()]
L.sort()
ret = 0
# print(L)
for i in range(N-2):
    for j in range(i+1, N-1):
        add = bisect.bisect_left(L,L[i]+L[j]-0.01) - (j+1)
        # print(f"{L[i]}, {L[j]} , add:{add}")
        ret += add

print(ret)



Fixed submission:
import bisect

N = int(input())
L = [int(x) for x in input().split()]
L.sort()
ret = 0
# print(L)
for i in range(N-2):
    for j in range(i+1, N-1):
        add = bisect.bisect_left(L,L[i]+L[j]-0.01) - (j+1)
        # print(f"{L[i]}, {L[j]} , add:{add}")
        ret += add

print(ret)
Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/python3

import sys
# input = sys.stdin.readline
sys.setrecursionlimit(100000)
MOD = 10 ** 9 + 7

#N = int(input())
#A = [int(x) for x in input().split()]
#V = [[0] * 100 for _ in range(100)]
def gcd(x, y):
    while (y):
        x, y = y, x % y
    return x


def divisor_list(n):
    # ret = set()
    ret = dict()
    ret[1] = 1
    i=2
    while n!=1:
        while n % i == 0:
            ret[i] = ret.get(i,0) + 1
            n /= i
        i+=1
    return ret

A,B = [int(x) for x in input().split()]
dA = divisor_list(A)
dB = divisor_list(B)

cm = set(dA.keys()).intersection(set(dB.keys()))

print(len(cm))

Fixed submission:
#!/usr/bin/python3

import sys
# input = sys.stdin.readline
sys.setrecursionlimit(100000)
MOD = 10 ** 9 + 7

#N = int(input())
#A = [int(x) for x in input().split()]
#V = [[0] * 100 for _ in range(100)]

def prime_decomposition(n):
    i = 2
    table = []
    while i * i <= n:
        while n % i == 0:
            n //= i
            table.append(i)
        i += 1
    if n > 1:
        table.append(n)
    return table

A,B = [int(x) for x in input().split()]
dA = set(prime_decomposition(A))
dB = set(prime_decomposition(B))

cm = dA.intersection(dB)
cm.add(1)

print(len(cm))

Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/python3

import sys
# input = sys.stdin.readline
sys.setrecursionlimit(100000)
MOD = 10 ** 9 + 7

#N = int(input())
#A = [int(x) for x in input().split()]
#V = [[0] * 100 for _ in range(100)]
def gcd(x, y):
    while (y):
        x, y = y, x % y
    return x


def divisor_list(n):
    # ret = set()
    ret = dict()
    ret[1] = 1
    i=2
    while n!=1:
        while n % i == 0:
            ret[i] = ret.get(i,0) + 1
            n /= i
        i+=1
    return ret

A,B = [int(x) for x in input().split()]
dA = divisor_list(A)
dB = divisor_list(B)

cm = set(dA.keys()).intersection(set(dB.keys()))

print(len(cm))

Fixed submission:
#!/usr/bin/python3

import sys
# input = sys.stdin.readline
sys.setrecursionlimit(100000)
MOD = 10 ** 9 + 7

#N = int(input())
#A = [int(x) for x in input().split()]
#V = [[0] * 100 for _ in range(100)]

def prime_decomposition(n):
    i = 2
    table = []
    while i * i <= n:
        while n % i == 0:
            n //= i
            table.append(i)
        i += 1
    if n > 1:
        table.append(n)
    return table

A,B = [int(x) for x in input().split()]
dA = set(prime_decomposition(A))
dB = set(prime_decomposition(B))

cm = dA.intersection(dB)
cm.add(1)

print(len(cm))
Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/python3

import sys
# input = sys.stdin.readline
sys.setrecursionlimit(100000)
MOD = 10 ** 9 + 7
INF = float('INF')
#N = int(input())
#A = [int(x) for x in input().split()]
#V = [[0] * 100 for _ in range(100)]

N, M = [int(x) for x in input().split()]
COSTS = [INF] * (1 << N)
COSTS[0] = 0
KEYS = [0]
A = [0]
for _ in range(M):
    a, b = [int(x) for x in input().split()]
    C = [int(x) for x in input().split()]
    key = 0
    for c in C:
        key |= (1 << (c-1))
    A.append(a)
    KEYS.append(key)

for pat in range(1 << N):
    for a, key in zip(A, KEYS):
        COSTS[pat | key] = min(COSTS[pat | key], COSTS[pat] + a)

ans = COSTS[(1 << N) - 1] 
if ans == INF:
    ans = -1 
print(ans)


Fixed submission:
#!/usr/bin/python3

import sys
# input = sys.stdin.readline
sys.setrecursionlimit(100000)
MOD = 10 ** 9 + 7
INF = float('INF')
#N = int(input())
#A = [int(x) for x in input().split()]
#V = [[0] * 100 for _ in range(100)]

N, M = [int(x) for x in input().split()]
COSTS = [INF] * (1 << N)
COSTS[0] = 0
KEYS = [0]
A = [0]
for _ in range(M):
    a, b = [int(x) for x in input().split()]
    C = [int(x) for x in input().split()]
    key = 0
    for c in C:
        key |= (1 << (c-1))
    A.append(a)
    KEYS.append(key)

for pat in range(1 << N):
    for a, key in zip(A, KEYS):
        COSTS[pat | key] = min(COSTS[pat | key], COSTS[pat] + a)

ans = COSTS[(1 << N) - 1] 
if ans == INF:
    ans = -1 
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/python3

import sys
# input = sys.stdin.readline
sys.setrecursionlimit(100000)
MOD = 10 ** 9 + 7

N, M = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
A.sort(reverse=True)

for _ in range(M):
    A[0] = A[0] // 2
    A.sort(reverse=True)

print(sum(A))



    

Fixed submission:
#!/usr/bin/python3

import sys
import heapq
# input = sys.stdin.readline
sys.setrecursionlimit(100000)
MOD = 10 ** 9 + 7

N, M = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]

Q = []
for a in A:
    heapq.heappush(Q, -a)

for _ in range(M):
    a = heapq.heappop(Q)
    a = (-a)//2
    heapq.heappush(Q, -a)



print(-sum(Q))

Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/python3

import sys
# input = sys.stdin.readline
sys.setrecursionlimit(100000)
MOD = 10 ** 9 + 7

N, M = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
A.sort(reverse=True)

for _ in range(M):
    A[0] = A[0] // 2
    A.sort(reverse=True)

print(sum(A))



    

Fixed submission:
#!/usr/bin/python3

import sys
import heapq
# input = sys.stdin.readline
sys.setrecursionlimit(100000)
MOD = 10 ** 9 + 7

N, M = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]

Q = []
for a in A:
    heapq.heappush(Q, -a)

for _ in range(M):
    a = heapq.heappop(Q)
    a = (-a)//2
    heapq.heappush(Q, -a)



print(-sum(Q))
Buggy python submission (verdict: Time Limit Exceeded):
import sys
# 10倍速いらしい
input = sys.stdin.readline

INF = float('inf')
MOD = 10 ** 9 + 7
EPS = 10 ** -7
sys.setrecursionlimit(1000000)

S = input().rstrip()
T = input().rstrip()

sn = len(S)
M = [dict() for _ in range(sn)]
for i, s in enumerate(S):
    for j in range(sn):
        M[(i - j + sn) % sn][s] = min(M[(i - j + sn) % sn].get(s, INF), j)
    for j in range(sn):
        if M[(i - j + sn) % sn][s] == 0:
            M[(i - j + sn) % sn][s] = M[(i - j + sn + 1) % sn][s] + 1


ans = 0
idx = sn - 1
for t in T:
    if M[idx].get(t, INF) == INF:
        print(-1)
        sys.exit()
    ans += M[idx][t]
    idx = (idx + M[idx][t]) % sn

print(ans)


Fixed submission:
import sys
import bisect

# 10倍速いらしい
input = sys.stdin.readline

INF = float('inf')
MOD = 10 ** 9 + 7
EPS = 10 ** -7
sys.setrecursionlimit(1000000)

S = input().rstrip()
T = input().rstrip()

sn = len(S)
d = dict()
for i, s in enumerate(S):
    d[s] = d.get(s, [])
    d[s].append(i)

nowidx = -1
loop = 0
for t in T:
    l = d.get(t, [])
    if len(l) == 0:
        print(-1)
        sys.exit()
    j = bisect.bisect_right(l, nowidx)
    if len(l) <= j:
        nowidx = l[0]
        loop += 1
    else:
        nowidx = l[j]

# print(loop, nowidx)
print(loop * sn + nowidx + 1)

Buggy python submission (verdict: Runtime Error):
import sys, math, itertools, bisect, copy, re
from collections import Counter, deque, defaultdict
from itertools import accumulate, permutations, combinations, takewhile, compress, cycle
from functools import reduce
from math import ceil, floor, log10, log2, factorial
from pprint import pprint

# 10倍速いらしい
input = sys.stdin.readline

INF = float('inf')
MOD = 10 ** 9 + 7
EPS = 10 ** -7
sys.setrecursionlimit(1000000)

S = input().rstrip()
T = input().rstrip()

sn = len(S)
M = [dict() for _ in range(sn)]
for i, s in enumerate(S):
    for j in range(sn):
        M[(i - j + sn) % sn][s] = min(M[(i - j + sn) % sn].get(s, INF), j)
    for j in range(sn):
        if M[(i - j + sn) % sn][s] == 0:
            M[(i - j + sn) % sn][s] = M[(i - j + sn + 1) % sn][s] + 1


ans = 0
idx = sn - 1
for t in T:
    if M[idx].get(t, INF) == INF:
        print(-1)
        sys.exit()
    ans += M[idx][t]
    idx = (idx + M[idx][t]) % sn

print(ans)


Fixed submission:
import sys
import bisect

# 10倍速いらしい
input = sys.stdin.readline

INF = float('inf')
MOD = 10 ** 9 + 7
EPS = 10 ** -7
sys.setrecursionlimit(1000000)

S = input().rstrip()
T = input().rstrip()

sn = len(S)
d = dict()
for i, s in enumerate(S):
    d[s] = d.get(s, [])
    d[s].append(i)

nowidx = -1
loop = 0
for t in T:
    l = d.get(t, [])
    if len(l) == 0:
        print(-1)
        sys.exit()
    j = bisect.bisect_right(l, nowidx)
    if len(l) <= j:
        nowidx = l[0]
        loop += 1
    else:
        nowidx = l[j]

# print(loop, nowidx)
print(loop * sn + nowidx + 1)
Buggy python submission (verdict: Time Limit Exceeded):
import sys, math, itertools, bisect, copy, re
from collections import Counter, deque, defaultdict

from itertools import accumulate, permutations, combinations, takewhile, compress, cycle

# from functools import reduce
# from math import ceil, floor, log10, log2, factorial
# from pprint import pprint


INF = float('inf')
MOD = 10 ** 9 + 7
EPS = 10 ** -7
sys.setrecursionlimit(1000000)

# N = int(input())
# N,M = [int(x) for x in input().split()]
# V = [[0] * 100 for _ in range(100)]
# A = [int(input()) for _ in range(N)]
# DP = [[0] * 100 for _ in range(100)]
# DP = defaultdict(lambda: float('inf'))

N, M = [int(x) for x in input().split()]
AB = []
for _ in range(N):
    A, B = [int(x) for x in input().split()]
    AB.append((A, B))

AB = sorted(AB, key=lambda x: (-x[1], -x[0]))

ans = 0
used = set()
for m in range(M, -1, -1):
    for i in range(N):
        a, b = AB[i]
        if a + m <= M and i not in used:
            ans += b
            used.add(i)
            # print("m:{}, a:{},b{}".format(m, a, b))
            break

print(ans)


Fixed submission:
import sys, math, itertools, bisect, copy, re
from collections import Counter, deque, defaultdict

from itertools import accumulate, permutations, combinations, takewhile, compress, cycle

# from functools import reduce
# from math import ceil, floor, log10, log2, factorial
# from pprint import pprint
import heapq

INF = float('inf')
MOD = 10 ** 9 + 7
EPS = 10 ** -7
sys.setrecursionlimit(1000000)

# N = int(input())
# N,M = [int(x) for x in input().split()]
# V = [[0] * 100 for _ in range(100)]
# A = [int(input()) for _ in range(N)]
# DP = [[0] * 100 for _ in range(100)]
# DP = defaultdict(lambda: float('inf'))

N, M = [int(x) for x in input().split()]
AB = []
for _ in range(N):
    A, B = [int(x) for x in input().split()]
    AB.append((A, B))

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

idx = 0
available = []
ans = 0
for d in range(1, M + 1):
    while idx < N and AB[idx][0] <= d:
        heapq.heappush(available, -AB[idx][1])
        idx += 1

    if len(available) != 0:
        ans += (-heapq.heappop(available))

print(ans)