Harryxun/sft_time huggingface dataset:
### BUGGY CODE ###

import copy

s = input()
dp = [0 for i in range(13)]
dp[0] = 1
num = 0
c = 1000000007
mul = 1
for i in range(len(s) - 1, -1, -1):
    nextdp = [0 for i in range(13)]
    if s[i] == '?':
        for j in range(10):
            for k in range(13):
                nextdp[(j * mul + k) % 13] += dp[k]
                nextdp[(j * mul + k) % 13] %= c
    else:
        j = int(s[i])
        for k in range(13):
            nextdp[(j * mul + k) % 13] += dp[k]
            nextdp[(j * mul + k) % 13] %= c
    dp = copy.copy(nextdp)
    mul *= 10
    mul %= 13

print(dp[5])

### FIXED CODE ###

import copy

s = input()
dp = [0 for i in range(13)]
dp[0] = 1
num = 0
c = 1000000007
mul = 1
for i in range(len(s) - 1, -1, -1):
    nextdp = [0 for i in range(13)]
    if s[i] == '?':
        for j in range(10):
            for k in range(13):
                nextdp[(j * mul + k) % 13] += dp[k]
                nextdp[(j * mul + k) % 13] %= c
    else:
        j = int(s[i])
        for k in range(13):
            nextdp[(j * mul + k) % 13] += dp[k]
            nextdp[(j * mul + k) % 13] %= c
    dp = copy.copy(nextdp)
    mul *= 10
    mul %= 13

print(dp[5])
### BUGGY CODE ###

import heapq
h,w,k = list(map(int, input().split()))
x1,y1,x2,y2 = list(map(int, input().split()))
x1,y1,x2,y2 = x1-1,y1-1,x2-1,y2-1
c = [[]*w for _ in range(h)]
dp = [[0]*w for _ in range(h)]
que = []
for i in range(h):
  for j,s in enumerate(input()):
    c[i].append(s)
    if s != '.':
      dp[i][j] = -1

dp[x1][y1] = 1
heapq.heappush(que, (dp[x1][y1], [x1,y1]))
dx = [1,0,-1,0]
dy = [0,1,0,-1]

while que:
  p= heapq.heappop(que)
  p = p[1]
  if (p[0] == x2) &( p[1] == y2):
    break
  for i in range(4):
    nx = p[0] + dx[i]
    ny = p[1] + dy[i]
    if (nx>=0) & (nx<=(h-1)) & (ny>=0) & (ny<=(w-1)):
      cnt = 1
      while (dp[nx][ny] == 0) | (dp[nx][ny] == (dp[p[0]][p[1]] + 1)):
        dp[nx][ny] = dp[p[0]][p[1]] + 1
        heapq.heappush(que, (dp[nx][ny], [nx,ny]))
        cnt += 1
        nnx = nx + dx[i]
        nny = ny + dy[i]
        if (nnx<0) | (nnx>(h-1)) | (nny<0) | (nny>(w-1)) | (cnt > k):
          break
        nx = nnx
        ny = nny

if dp[x2][y2] != 0:
  print(dp[x2][y2]-1)
else:
  print(-1)

### FIXED CODE ###

#import heapq
from collections import deque
h,w,k = list(map(int, input().split()))
x1,y1,x2,y2 = list(map(int, input().split()))
x1,y1,x2,y2 = x1-1,y1-1,x2-1,y2-1
dp = [[-1]*w for _ in range(h)]
#que = []
que = deque()
c = [input() for _ in range(h)]

dp[x1][y1] = 0
#heapq.heappush(que, (dp[x1][y1], [x1,y1]))
que.append((x1,y1))
dx = [1,0,-1,0]
dy = [0,1,0,-1]
while que:
  x,y=que.popleft()
  if x==x2 and y==y2:
    exit(print(dp[x][y]))
  for dx,dy in [[1,0],[-1,0],[0,-1],[0,1]]:
    for i in range(1,k+1):
      xx=x+dx*i
      yy=y+dy*i
      if not(0<=xx<h and 0<=yy<w) or c[xx][yy]=="@":break
      if 0<=dp[xx][yy]<=dp[x][y]:break
      if dp[xx][yy]==-1:que.append((xx,yy))
      dp[xx][yy]=dp[x][y]+1
print(-1)
### BUGGY CODE ###

N, Q = map(int, input().split())
S = input()
X = [list(map(int, input().split()))for _ in range(Q)]
for i in range(Q):
    print(S[X[i][0]-1:X[i][1]].count("AC"))

### FIXED CODE ###

N, Q = map(int, input().split())
S = input()
X = [list(map(int, input().split()))for _ in range(Q)]

a =[0]*N
for i in range(1,N):
    if S[i] =="C" and S[i-1] =="A":
        a[i] = a[i-1]+1
    else:
        a[i] = a[i-1]
# print(a)
for i in range(Q):
    print(a[X[i][1]-1]-a[X[i][0]-1])
### BUGGY CODE ###

N = str(input())
lists = []

for x in N:
    lists.append(int(x))
    a = sum(lists)

if a % 9 == 0:
        print('Yes')
else:
        print('No')

### FIXED CODE ###

N = str(input())
lists = [int(x) for x in N]
a = sum(lists)

if  a % 9 == 0:
        print('Yes')
else:
        print('No')
### BUGGY CODE ###

N = int(input())
s = input()
S=[]
for i in range(N):
    for j in range(i+1,N):
        for k in range(j+1,N):
            a=[s[i],s[j],s[k]]
            if a not in S:
                S.append(a)
print(len(S))

### FIXED CODE ###

N = int(input())
s = input()
cnt=0
for i in range(10):
    for j in range(10):
        for k in range(10):
            a=s.find(str(i))
            if a==-1:
                continue
            b=s[a+1:].find(str(j))
            if b==-1:
                continue
            b+=a+1
            c=s[b+1:].find(str(k))
            if c==-1:
                continue
            cnt+=1

print(cnt)
### BUGGY CODE ###

from fractions import gcd
N = int(input())
a = [int(c) for c in input().split()]
mod = 10**9+7
ans = a[0]
b = 0
for i in range(1, N):
  ans = ans*a[i]//gcd(ans, a[i])
b = 0
for i in range(N):
  b += (ans//a[i])%mod
print(b%mod)

### FIXED CODE ###

import numpy as np
N = int(input())
a = np.array(input().split(), np.int64)
MOD = 10**9+7
U = 10**6+10
is_prime = np.zeros(U, np.bool)
is_prime[2] = 1
is_prime[3::2] = 1
for p in range(3, U, 2):
  if p*p>U:
    break
  if is_prime[p]==1:
    is_prime[p*p::p+p] = 0

M = 10**3
small_primes = np.where(is_prime[:M])[0].tolist()

B = a.copy()
lcm = 1
for p in small_primes:
  e = 0
  while np.any(a%p==0):
    a[a%p==0] //= p
    e += 1
  lcm *= p**e
  lcm %= MOD

for x in set(a.tolist()):
  lcm *= x
  lcm %= MOD

answer = sum(pow(x, MOD-2, MOD) for x in B.tolist())%MOD
answer *= lcm
answer %= MOD
print(answer)
### BUGGY CODE ###

import sys

N = int(input())
tasks = []

for i in range(N):
    (A, B) = (int(i) for i in input().split())
    tasks.append((A, B))


def modify_order(l, i):
    for j in range(len(l) - 1, i, -1):
        if l[j-1][1] > l[j][1]:
            l[j-1], l[j] = l[j], l[j-1]

def sort(l):
    for i in range(0, len(l) - 1):
        modify_order(l, i)        
        
sort(tasks)

time = 0

for i in range(N):
    time += tasks[i][0]
    if time > tasks[i][1]:
        print("No")
        sys.exit()
        
print("Yes")


### FIXED CODE ###

import sys

N = int(input())
tasks = []

for i in range(N):
    (A, B) = (int(i) for i in input().split())
    tasks.append((A, B))


sorted_tasks = sorted(tasks, key=lambda k: k[1])

time = 0

for i in range(N):
    time += sorted_tasks[i][0]
    if time > sorted_tasks[i][1]:
        print("No")
        sys.exit()
        
print("Yes")
### BUGGY CODE ###

import math
from collections import deque

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

graph = []

for i in range(m):
  a, b = map(int, input().split())
  graph.append([a, b])

dist = [-1] * (n+1)
dist[0] = 0
dist[1] = 0

d = deque()
d.append(1)

guidepost = [-1] * (n+1)

while d:
  v = d.popleft()
  for i, j in graph:
    if dist[i] != -1 and dist[j] != -1:
      continue
    elif i == v:
      dist[j] = dist[v] + 1
      d.append(j)
      if guidepost[j] == -1:
        guidepost[j] = v
      else:
        print("No")
        exit()
    elif j == v:
      dist[i] = dist[v] + 1
      d.append(i)
      if guidepost[i] == -1:
        guidepost[i] = v
      else:
        print("No")
        exit()
  
for i in range(2, len(guidepost)):
  if guidepost[i] == -1:
    print("No")
    exit()

print("Yes")
for i in range(2, len(guidepost)):
  print(guidepost[i])

### FIXED CODE ###

import math
from collections import deque

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

graph = [[] for _ in range(n+1)]

for i in range(m):
  a, b = map(int, input().split())
  graph[a].append(b)
  graph[b].append(a)

flag = [0] * (n+1)
flag[0] = 1
flag[1] = 1

d = deque()
d.append(1)

guidepost = [-1] * (n+1)

while d:
  v = d.popleft()
  for i in graph[v]:
    if flag[i] != 0:
      continue
    flag[i] = 1
    d.append(i)
    if guidepost[i] != -1:
      print("No")
      exit()
    else:
      guidepost[i] = v
  
if not all(guidepost):
  print("No")
  exit()

ans = guidepost[2:]    

print("Yes")
print(*ans, sep="\n")
### BUGGY CODE ###

import sys
#from numba import jit

input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

tin=lambda : map(int, input().split())
lin=lambda : list(map(int, input().split()))
mod=1000000007

#+++++

#@jit
def gg(nn, x, y, n, is_sit, cc, av):
	nn[x][y]-=1
	
	q = [(x, y, nn[x][y])]
	while q:
		(x, y, v) = q.pop()
		for dx,dy in ([-1,0], [0,-1], [1,0], [0,1]):
			if x+dx < 0 or x +dx >= n or y + dy < 0 or y + dy >= n:
				continue
			iss = 1 if is_sit[x+dx][y+dy] else 0
			if nn[x+dx][y + dy] <= v + iss:
				continue
			nn[x+dx][y+dy] = v + iss
			q.append((x+dx, y+dy, v+is_sit[x+dx][y+dy]))

def main():
	n = int(input())
	nn = [[min(i+1,j+1,n-i,n-j) for j in range(n)] for i in range(n)]
	is_sit = [[True] * n for _ in range(n)]
	cc = [[0]*n for _ in range(n)]
	
	#b , c = tin()
	pl = lin()
	ans = 0
	for i, p in enumerate(pl):
		x, y = (p-1) // n, (p-1) % n
		ans += nn[x][y]-1
		is_sit[x][y] = 0
		gg(nn, x, y, n, is_sit, cc, i)
		
	print(ans)
	#s = input()	
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)


### FIXED CODE ###

import sys

input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

#+++++

def main():
	n = int(input())
	nn = [[min(i,j,n-i-1,n-j-1) for j in range(n)] for i in range(n)]
	is_sit = [[True] * n for _ in range(n)]
	cc = [[0]*n for _ in range(n)]
	
	#b , c = tin()
	pl = list(map(int, input().split()))
	ans = 0
	for p in pl:
		x, y = (p-1) // n, (p-1) % n
		ans += nn[x][y]
		is_sit[x][y] = False
		q = [(x, y, nn[x][y])]
		while q:
			(x, y, v) = q.pop()
			if x >= 0 and nn[x-1][y]>v:
				nn[x-1][y] = v
				q.append((x-1, y, v+is_sit[x-1][y]))
			if x < n-1 and nn[x+1][y]>v:
				nn[x+1][y] = v
				q.append((x+1, y, v+is_sit[x+1][y]))		
			if y >= 0 and nn[x][y-1]>v:
				nn[x][y-1] = v
				q.append((x, y-1, v+is_sit[x][y-1]))
			if y < n-1 and nn[x][y+1]>v:
				nn[x][y+1] = v
				q.append((x, y+1, v+is_sit[x][y+1]))	
		
	print(ans)
	#s = input()	
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)
### BUGGY CODE ###

l=input()
n=len(l)
s=list(l)
i=0
ans=0
while i<n-2:
    if s[i]=="A" and s[i+1]=="B" and s[i+2]=="C":
        s[i]="B"
        s[i+1]="C"
        s[i+2]="A"
        i=max(0,i-1)
        ans+=1
    else:
        i+=1

print(ans)

### FIXED CODE ###

l=input()
n=len(l)
s=list(l)
i=0
ans=0
p=0
while i<n-2:
    if s[i]=="A":
        p+=1
    else:
        p=0
    if s[i]=="A" and s[i+1]=="B" and s[i+2]=="C":
        ans+=p
        i+=2
        s[i]="A"
        p-=1
    else:
        i+=1
print(ans)
### BUGGY CODE ###

n,k=map(int,input().split())
h=[int(i) for i in input().split()]
h.sort
a=0
if n-k<=0:
  print(0)
else:
  for j in range(n-k):
    while True:
      if h[j]-1>0:
        h[j]=h[j]-1
        a+=1
      else:
        break
  print(a+k+1)

### FIXED CODE ###

n,k=map(int,input().split())
h=[int(i) for i in input().split()]
h.sort()
a=0
if n>k:
  for j in range(n-k):
    a+=h[j]
  print(a)
else:
  print(0)
### BUGGY CODE ###

import sys
import collections
stdin = sys.stdin

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))

N,K,Q=nm()
Al=[0]*Q
for i in range(Q):
    Al[i]=int(input())



for i in range(N):
    print('No' if (K-Q+Al.count(i+1)<1) else 'Yes')

### FIXED CODE ###

import sys
import collections
stdin = sys.stdin

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))

N,K,Q=nm()
Al=[0]*Q
ans_l=[K-Q]*N
for i in range(Q):
    #Al[i]=int(input())
    ans_l[int(input())-1]+=1
    


for i in range(N):
    #print(Al.count(i+1))
    #print('No' if (K-Q+Al.count(i+1)<1) else 'Yes')
    print('No' if (ans_l[i]<1) else 'Yes')
### BUGGY CODE ###

n,k=map(int,input().split())
h=list(map(int,input().split()))
dp=[0 for _ in range(n+1)]
dp[2]=abs(h[1]-h[0])
for i in range(2,n):
    dp[i+1]=999999999
    for x in range(min(k,i)):
        if dp[i+1]>dp[i-x]+abs(h[i]-h[i-1-x]):
            dp[i+1]=dp[i-x]+abs(h[i]-h[i-1-x])
print(dp[n])


### FIXED CODE ###

n,k=map(int,input().split())
h=list(map(int,input().split()))
dp=[0 for _ in range(n+1)]
dp[2]=abs(h[1]-h[0])
for i in range(2,n):
    dp[i+1]=999999999
    for x in range(min(k,i)):
        if dp[i+1]>dp[i-x]+abs(h[i]-h[i-1-x]):
            dp[i+1]=dp[i-x]+abs(h[i]-h[i-1-x])
print(dp[n])
### BUGGY CODE ###

n = int(input())
a = list(map(int, input().split()))

sum = a[0]
count = 0

for i in range(1, n) :
    temp = sum
    sum += a[i]
    if temp > 0 and sum > 0 :
        while sum >= 0 :
            count += 1
            sum -= 1
    elif temp < 0 and sum < 0 :
        while sum <= 0 :
            count += 1
            sum += 1

if sum == 0 :
    count += 1

print(count)


### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))

sum = a[0]
count1 = 0
count2 = 0

sum1 = 0
sum2 = 0

for i in range(n) :
    sum1 += a[i]
    sum2 += a[i]
    if i % 2 == 0 :
        if sum1 >= 0 :
            count1 += abs(sum1) + 1
            sum1 = -1
        if sum2 <= 0 :
            count2 += abs(sum2) + 1
            sum2 = 1
    elif i % 2 == 1 :
        if sum1 <= 0 :
            count1 += abs(sum1) + 1
            sum1 = 1
        if sum2 >= 0 :
            count2 += abs(sum2) + 1
            sum2 = -1

print(min(count1, count2))
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10**7)
n, q = list(map(int, input().split(' ')))
inf = [[] for _ in range(n)]
p_list = [0 for _ in range(n)]
     
for i in range(n-1):
    a, b = list(map(int, input().split(' ')))
    inf[a-1].append(b-1)
    inf[b-1].append(a-1)
     
for i in range(q):
    p, x = list(map(int, input().split(' ')))
    p_list[p-1] += x
visit = [0]*n
def add_p(num):
    """
    if all(visit[x] == 1 for x in inf[num]):
        return 0
    """
    visit[num] = 1
    for k in inf[num]:
        if visit[k] == 1:
            continue
        else:
            p_list[k] += p_list[num]
            add_p(k)
    return 0
add_p(0)
print(*p_list)

### FIXED CODE ###

def main():
    n, q = map(int, input().split(' '))
    import sys
    from collections import deque
    sys.setrecursionlimit(10**7)

    visit = [True for _ in range(n)]
    point = [0 for _ in range(n)]
    dic = [[] for _ in range(n)]
    for _ in range(n-1):
        a, b = map(int, input().split(' '))
        dic[a-1].append(b-1)
        dic[b-1].append(a-1)
    for _ in range(q):
        p, x = map(int, input().split(' '))
        point[p-1] += x
    next_visit = deque()
    next_visit.append(0)
    visit[0] = False
    counter = 1
    while counter < n:
        t = next_visit.pop()
        for s in dic[t]:
            if visit[s]:
                point[s] += point[t]
                visit[s] = False
                counter += 1
                next_visit.append(s)
    print(*point)
if __name__ == '__main__':
    main()
### BUGGY CODE ###

# https://atcoder.jp/contests/abc168/tasks/abc168_d
from pprint import pprint
from collections import deque

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

A = []
B = []
for i in range(M):
    _a, _b = map(int, input().split(' '))
    A.append(_a)
    B.append(_b)

# # 隣接行列
# route = [[False for j in range(N)] for i in range(N)]
# 
# for a, b in zip(A, B):
#     route[a - 1][b - 1] = True
#     route[b - 1][a - 1] = True

# 隣接リスト
route2 = [[] for n in range(N)]

for a, b in zip(A, B):
    route2[a - 1].append(b - 1)
    route2[b - 1].append(a - 1)

room_depth = [None] * N
room_depth[0] = 0
room_sign = [None] * N

stack = [0]

queue = deque()
visited = []

queue.append(0)
visited.append(0)

while queue:
    now = queue.popleft()
    # now = stack.pop()
    # next_room = [r for r in room_connection[now] if r not in visited]
    # print('now=', now)
    # print('next_room', next_room)


    for r in route2[now]:
    # for r in range(N):
        if r not in visited:
        # if route[now][r] and r not in visited:
            # print('r=', r)
            # for r in next_room:
            # if r not in visited:
            queue.append(r)
            visited.append(r)

            # stack.append(r)
            # print(room_depth[now], room_depth[r])

            # if room_depth[r] is None or room_depth[r] > room_depth[now] + 1:
            if room_depth[r]:
                room_depth[r] = min(room_depth[now] + 1, room_depth[r])
            else:
                room_depth[r] = room_depth[now] + 1

            room_sign[r] = now + 1

    # visited.append(now)

    # if set(visited) == set(range(N)):
    #     break

    # print('queue', queue)
    # print('visited', visited)
    # print('depth', room_depth)
    # print('stack', stack)
    # print('sign', room_sign)
    # print('-----')

print('Yes')
for s in room_sign[1:]:
    print(s)


### FIXED CODE ###

# https://atcoder.jp/contests/abc168/tasks/abc168_d
from collections import deque

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

A = []
B = []

# 隣接リスト
route2 = [[] for n in range(N)]

for i in range(M):
    a, b = map(int, input().split(' '))
    A.append(a)
    B.append(b)

for a, b in zip(A, B):
    route2[a - 1].append(b - 1)
    route2[b - 1].append(a - 1)

room_sign = [None] * N

queue = deque([])
visited = set()

queue.append(0)
visited.add(0)

while len(queue) > 0:
    now = queue.popleft()
    for i in route2[now]:
        if i not in visited:
            queue.append(i)
            visited.add(i)

            room_sign[i] = now + 1

print('Yes')
for s in room_sign[1:]:
    print(s)
### BUGGY CODE ###

# -*- coding: utf-8 -*-

# スペース区切りの整数の入力
a, b = map(int, raw_input().split())
list1=[]
d=b-a
for i in xrange(d+1):
    list1.append(a+i)
s=1
for i in list1:
    s=s*i
if s<0:
    print "Negative"
elif s==0:
    print "Zero"
else:
    print "Positive"

### FIXED CODE ###

# -*- coding: utf-8 -*-
# スペース区切りの整数の入力
a, b = map(int, raw_input().split())
dnum=b-a+1
if b<0:
    odd=0
    if dnum%2==1:
        odd=1
    if odd==0:
        print "Positive"
    else:
        print "Negative"
if a*b==0:
    print "Zero"
if b>0 and a<0:
    print "Zero"
if a>0:
    print "Positive"
### BUGGY CODE ###

import bisect
n,m = map(int, input().split())
a = sorted(list(map(int,input().split())))
bc = [list(map(int, input().split())) for _ in range(m)]
bc.sort(key=lambda x:(-x[1])) 
for b,c in bc:
    index = bisect.bisect_left(a, c)
    d = min(index,b)
    for j in range(d):
        a[j] = c
    a.sort()

print(sum(a))
    


### FIXED CODE ###

n,m = map(int, input().split())
a = sorted(list(map(int,input().split())))
d = [list(map(int, input().split())) for _ in range(m)]
d.sort(key=lambda x:(-x[1]))
e = []
for b,c in d:
    e += [c]*b
    if len(e) >= n:
        break
e = sorted(e)[::-1]
ans = 0
j = 0
for i in range(n):
    if j < len(e):
        if a[i] >= e[j]:
            ans += a[i]
        else:
            ans += e[j]
            j += 1
    else:
        ans += a[i]
print(ans)
### BUGGY CODE ###

k=0
s=0
combi = 0

def nyu():
    num1,num2 = input().split()
    k = int(num1)
    s = int(num2)
    return k,s

def calc(l_k,l_s):
    l_combi = 0
    for x in range(l_k):
        check_tmp =0
        check_tmp =check1(x,l_s,l_k)
        if check_tmp == 1:
            break
        elif check_tmp  == 2:
            continue
        for y in range(l_k):
            check_tmp =check2(x,y,l_s,l_k)
            if check_tmp == 1:
                break
            elif check_tmp  == 2:
                continue
            sum = x+y+l_k    
            if l_s <= sum:
#                print("x=",x,"y=",y)
                l_combi +=1
    return l_combi

def check1(x,s,k):
    if s<x:
        return 1
    if x+(k-1)*2 < s:
        return 2
    return 0

def check2(x,y,s,k):
    sum = x+y
    if s<sum:
        return 1
    if x+y+k-1 < s:
       return 2
    return 0

def check3(x,y,z,s):
    sum = x+y+z
    if s<sum:
        return 1
    return 0    

def check_ini(k,s):
    if k*3 < s:
        return True
    return False


k,s=nyu()
if check_ini == True:
    print("0")
else :
    print(calc(k+1,s))









### FIXED CODE ###

k=0
s=0
combi = 0

def nyu():
    num1,num2 = input().split()
    k = int(num1)
    s = int(num2)
    return k,s

def calc(l_k,l_s):
    l_combi = 0
    for x in range(l_k):
#        check_tmp =0
#        check_tmp =check1(x,l_s,l_k)
#        if check_tmp == 1:
#            break
#        elif check_tmp  == 2:
#            continue
        for y in range(l_k):
#            check_tmp =check2(x,y,l_s,l_k)
#            if check_tmp == 1:
#                break
#            elif check_tmp  == 2:
#                continue2
#            sum = x+y+l_k 
            sum = l_s- x-y 
            if 0<=sum and sum <= k:
#                print("x=",x,"y="   ,y) 
                l_combi +=1
    return l_combi

def check1(x,s,k):
    if s<x:
        return 1
    if x+(k-1)*2 < s:
        return 2
    return 0

def check2(x,y,s,k):
    sum = x+y
    if s<sum:
        return 1
    if x+y+k-1 < s:
       return 2
    return 0

def check3(x,y,z,s):
    sum = x+y+z
    if s<sum:
        return 1
    return 0    

def check_ini(k,s):
    if k*3 < s:
        return True
    return False


k,s=nyu()
if check_ini == True:
    print("0")
else :
    print(calc(k+1,s))
### BUGGY CODE ###

# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush, heapify
import math
import itertools
import random
 
# NO, PAY-PAY
#import numpy as np
#import statistics
#from statistics import mean, median,variance,stdev
 
INF = float('inf')
def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
 
def main():
    N,M = inputMap()
    ab = []
    for i in range(N):
        a,b = inputMap()
        if a > M:
            continue
        ab.append((a,b))
        
    ab = sorted(ab, key=lambda x:(x[0],-x[1]))
    pq = []
    heapify(pq)
    
    ans = 0
    for i in range(1,M+1):
        for j,val in enumerate(ab):
            a,b = val
            if a > i:
                break
            if i == a:
                heappush(pq, -b)
                
        if len(pq) > 0:
            tmp = heappop(pq) * (-1)
            ans += tmp
    
    print(ans)
    
if __name__ == "__main__":
	main()


### FIXED CODE ###

# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush, heapify
import math
import itertools
import random
 
# NO, PAY-PAY
#import numpy as np
#import statistics
#from statistics import mean, median,variance,stdev
 
INF = float('inf')
def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
 
def main():
    N,M = inputMap()
    ab = []
    heapify(ab)
    for i in range(N):
        a,b = inputMap()
        if a > M:
            continue
        heappush(ab, (a,b))
    
    ans = 0
    pq = []
    heapify(pq)
    for i in range(1,M+1):
        while True:
            if len(ab) == 0 or ab[0][0] != i:
                break
            a,b = heappop(ab)
            heappush(pq, -b)
            
        if len(pq) > 0:
            ans = ans + (heappop(pq) * (-1))
        
    
    print(ans)
    
if __name__ == "__main__":
	main()