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

s=[int(x) if x!="?" else '?' for x in input()]
mod=10**9+7
n = len(s)
dp=[[0]*(14) for i in range(n+1)]
dp[0][0]=1
for i in range(0,n):
# for i in range(1)
	for j in range(14):
		if s[i]!='?':
		
			if j-(s[i]*(10**(n-i-1)))%13>=0:
				dp[i+1][j]=dp[i][j-(s[i]*(10**(n-i-1)))%13]%mod
			else:
				dp[i+1][j]=dp[i][j-(s[i]*(10**(n-i-1)))%13+13]%mod
		
		else:
			for k in range(10):

				# print(j)
				if j-(k*(10**(n-i-1)))%13>=0:
					dp[i+1][j]+=dp[i][j-(k*(10**(n-i-1)))%13]%mod
				else:
					dp[i+1][j]+=dp[i][j-(k*(10**(n-i-1)))%13+13]%mod
				
# print(dp)
# print(s)
print(dp[n][5]%mod)


	




### FIXED CODE ###

S = input()
dp = [[0]*13 for i in range(len(S))]
MOD = 10**9+7
 
if S[0]=='?':
    for i in range(10):
        dp[0][i] = 1
else:
    dp[0][int(S[0])] = 1
 
for i,c in enumerate(S[1:]):
    for j in range(13):
        if c=='?':
            for k in range(10):
                nj = (j*10 + k) % 13
                dp[i+1][nj] += dp[i][j]
                dp[i+1][nj] %= MOD
        else:
            nj = (j*10 + int(c)) % 13
            dp[i+1][nj] += dp[i][j]
            dp[i+1][nj] %= MOD
 
print(dp[-1][5])
### BUGGY CODE ###

from collections import defaultdict
from collections import deque

n, m = map(lambda x: int(x), input().split())
person_to_friends = defaultdict(set)

for _ in range(m):
    a, b = map(lambda x: int(x), input().split())
    person_to_friends[a].add(b)
    person_to_friends[b].add(a)

not_searched = set(range(1, n+1))
max_pool_num = 1

while len(not_searched) > 0:
#     print(not_searched)
    first_person = not_searched.pop()
    friend_pool = set([first_person])
    que = deque([first_person])
    while len(que) > 0:
        current_person = que.popleft()
        not_searched_friends = person_to_friends[current_person].intersection(not_searched)
#         print(not_searched_friends)
        for friend in not_searched_friends:
            not_searched.remove(friend)
            que.append(friend)
            friend_pool.add(friend)
    max_pool_num = max(len(friend_pool), max_pool_num)
print(max_pool_num)

### FIXED CODE ###

# UnionFind

# 配列で、子のID番目:(親のID), 親のID番目:(その塊の-サイズ)
# Union Findを使う
class UnionFind:
    def __init__(self, size):
        self.parent_indexes = [-1] * size
        
    def find_parent(self, n):
#         print(self.parent_indexes[n])
        if self.parent_indexes[n] < 0:
            return n
#         print('hewe')
        # 探しているnodeが指し示しているのが現在の親ではない場合、
        # 現在の親に書き換え(memo化)た上で返す
        self.parent_indexes[n] = self.find_parent(self.parent_indexes[n])
        return self.parent_indexes[n] 
    
    def union(self, n1, n2):
        if self.same_group(n1, n2):
            return False
        
        # サイズの大きい方の親が親であり続ける
        if self.size(n1) >= self.size(n2):
            tmp = self.size(n2)
            self.parent_indexes[self.find_parent(n2)] = self.find_parent(n1)
            self.parent_indexes[self.find_parent(n1)] -= tmp
            return True
        
        tmp = self.size(n1)
        self.parent_indexes[self.find_parent(n1)] = self.find_parent(n2)
        self.parent_indexes[self.find_parent(n2)] -= tmp
        return True
        
    
    def size(self, n):
        return -self.parent_indexes[self.find_parent(n)]
    
    def same_group(self, n1, n2):
        return self.find_parent(n1) == self.find_parent(n2)



n, m = map(lambda x: int(x), input().split())
uf = UnionFind(n)

for _ in range(m):
    a, b = map(lambda x: int(x), input().split())
    uf.union(a-1, b-1)
    
print(-min(uf.parent_indexes))
### BUGGY CODE ###

S=list(input())

dp=[0 for i in range(13)]
dp[0] = 1

i=0
for k in reversed(S):
    dpcopy=dp.copy()
    dp=[0 for i in range(13)]
    if k=='?':
        for s in range(10):
            p=(s * 10**(i))%13
            for j in range(13):               
                dp[(p + j) % 13] += dpcopy[j]%(10**9+7)
    else:
        k=int(k)
        p=(k * 10**(i))%13
        for j in range(13):
            dp[(p + j) % 13] += dpcopy[j]%(10**9+7)
    i += 1


print(dp[5]%(10**9+7))

### FIXED CODE ###

S = [int(x) if x != '?' else - 1 for x in input()]
le=len(S)

dp = [[0]*13 for i in range(le+1)]
dp[0][0] = 1

i=0
for k in S:
    if k==-1:
        for s in range(10):
            for j in range(13):
                dp[i + 1][(s + j*10) % 13] += dp[i][j]%(10**9+7)

    else:
        k=int(k)
        for j in range(13):
            dp[i + 1][(j *10 + k) % 13] += dp[i][j]%(10**9+7)
        
    i += 1


print(dp[le][5]%(10**9+7))
### BUGGY CODE ###

from collections import deque
N=int(input())
S=input()
Q=int(input())
K=map(int,input().split())

for k in K:
    ans=0
    d=m=dm=0
    for i in range(N):
        c=S[i]
        if c=='D':
            d+=1
        elif c=='M':
            m+=1
            dm+=d
        elif c=='C':
            ans+=dm
        if i>=k-1:
            c=S[i-(k-1)]
            if c=='D':
                d-=1
                dm-=m
            elif c=='M':
                m-=1
    print(ans)

### FIXED CODE ###

N=int(input())
S=tuple(map(ord,input()))
Q=int(input())
K=map(int,input().split())
D,M,C=map(ord,'DMC')

for k in K:
    ans=0
    d=m=dm=0
    for i in range(min(k-1,N)):
        c=S[i]
        if c==D:
            d+=1
        elif c==M:
            m+=1
            dm+=d
        elif c==C:
            ans+=dm
    for i in range(k-1,N):
        c=S[i]
        if c==D:
            d+=1
        elif c==M:
            m+=1
            dm+=d
        elif c==C:
            ans+=dm
        c=S[i-(k-1)]
        if c==D:
            d-=1
            dm-=m
        elif c==M:
            m-=1
    print(ans)
### BUGGY CODE ###

r, g, b = map(int, input().split())

K = int(input())

while K > 0:
  if g < r:
    g *= 2
    K -= 1
    continue

  if b < g:
    b *= 2
    K -= 1
    continue

  if g > r and b > g:
    break




if g > r and b > g:
  print("Yes")
else:
  print("No")



### FIXED CODE ###

r, g, b = map(int, input().split())

K = int(input())

while K > 0:
  if g <= r:
    g *= 2
    K -= 1
  elif b <= g:
    b *= 2
    K -= 1
  else:
    break
    




if g > r and b > g:
  print("Yes")
else:
  print("No")
### BUGGY CODE ###

s = input()
K = int(input())

list = []
for i in range(len(s)):
  for j in range(i+1,len(s)+1):
    tmp = s[i:j]
    if not tmp in list:
      list.append(tmp)
    list.sort()
    if len(list)>K:
      list = list[:K]

print(list[K-1])

### FIXED CODE ###

s = input()
K = int(input())

list = []
for i in range(len(s)):
  for j in range(i+1,len(s)+1):
    tmp = s[i:j]
    if len(list)>=K:
      if tmp>list[-1]:
        break
      else:
        if not tmp in list:
          list.append(tmp)
          list.sort()
          list = list[:K]
    else:
      if not tmp in list:
        list.append(tmp)
        list.sort()
        if len(list)>K:
          list = list[:K]

print(list[K-1])
### BUGGY CODE ###

# -*- coding: utf-8 -*-
from operator import itemgetter

N, M = list(map(int, input().split()))
A = [[0] * 4 for i in range(M)]
for i in range(M):
    A[i][0], A[i][1] = list(map(int, input().split()))
    A[i][2] = i

P = list(set([a[0] for a in A]))
P_counts = [0]*len(P)
sorted_A = sorted(A, key=itemgetter(1))

for a in sorted_A:
    idx = P.index(a[0])
    P_counts[idx] += 1
    a[3] = str(a[0]).zfill(6) + str(P_counts[idx]).zfill(6)

B = sorted(sorted_A, key=itemgetter(2))
for b in B:
    print(b[3])

### FIXED CODE ###

# -*- coding: utf-8 -*-
from operator import itemgetter

N, M = list(map(int, input().split()))
A = [[0] * 4 for i in range(M)]
for i in range(M):
    A[i][0], A[i][1] = list(map(int, input().split()))
    A[i][2] = i

sorted_A = sorted(A, key=itemgetter(1))

P_num = [1]*N
for a in sorted_A:
    y = a[0]
    a[3] = P_num[y-1]
    P_num[y-1] += 1

B = sorted(sorted_A, key=itemgetter(2))
for b in B:
    print("%06d%06d" % (b[0], b[3]))
### BUGGY CODE ###

def main():
    n, w = [int(x) for x in input().split()]
    itens = []
    dp = [[-1]*w for i in range(n)]
    
    for _ in range(n):
        itens.append([int(x) for x in input().split()])#item([peso, valor])

    print(knapsack(n, w, itens, dp))

def knapsack(n, w, itens, dp):

    if n == 0 or w == 0:
        return 0

    if dp[n-1][w-1] != -1:
        return dp[n-1][w-1]

    if itens[n-1][0] > w:
        dp[n-1][w-1] = knapsack(n-1, w, itens, dp)
        return dp[n-1][w-1]

    else:
        dp[n-1][w-1] = max(itens[n-1][1] + knapsack(n-1, w - itens[n-1][0], itens, dp),
                           knapsack(n-1, w, itens, dp))

        return dp[n-1][w-1]

main()

### FIXED CODE ###

ln = input()
n, cap = ln.split()
n = int(n)
cap = int(cap)

'''
weights = [[0 for x in range(2)] for y in range(n)] 
values = [[0 for x in range(2)] for y in range(n)] 
mat = [[0 for x in range(2)] for y in range(1000000)] 
'''
weights = [0 for x in range(n)] 
values =  [0 for x in range(n)] 
mat =  [0 for x in range(1000000)] 

for i in range(n):
    ln = input()
    ln = ln.split()
    weights[i] = int(ln[0])
    values[i] = int(ln[1])
 
for i in range(n):
    for j in range(cap,weights[i]-1,-1):
        '''
        print(j)
        print(values[i])
        print(mat[j-weights[i]])
        '''
        mat[j] = max(mat[j], mat[j-weights[i]] + values[i])
 
        
print(mat[cap])
### BUGGY CODE ###

from collections import deque

n = int(input())
s = input()
cp = []
for i, c in enumerate(s):
    if c == 'D':
        cp.append((0, i))
    elif c == 'M':
        cp.append((1, i))
    elif c == 'C':
        cp.append((2, i))

i = 0
while cp[i][0] != 0:
    i += 1
cp = cp[i:]
while cp[-1][0] != 2:
    cp.pop()

q = int(input())
buf = []
for k in map(int, input().split()):
    ans = 0
    deq = deque()
    count_a = 0
    rejected_a = 0
    count_internal_b = 0
    sum_internal_b = 0
    for item in cp:
        # print(deq, count_a, rejected_a, count_internal_b, sum_internal_b)
        if item[0] == 0:
            count_a += 1
            deq.append(item)
        elif item[0] == 1:
            count_internal_b += 1
            sum_internal_b += count_a
            deq.append((item[0], item[1], count_a))
        else:
            left_limit = item[1] - k
            while deq and deq[0][1] <= left_limit:
                old_item = deq.popleft()
                if old_item[0] == 0:
                    rejected_a += 1
                elif old_item[0] == 1:
                    count_internal_b -= 1
                    sum_internal_b -= old_item[2]
            ans += sum_internal_b - rejected_a * count_internal_b
    buf.append(ans)
print('\n'.join(map(str, buf)))


### FIXED CODE ###

from itertools import accumulate

n = int(input())
s = input()
acc_cnt_a = [0] * (n + 1)
acc_cnt_b = [0] * (n + 1)
acc_cnt_ab = [0] * (n + 1)
c_loc = []
cnt_a = 0
for i, c in enumerate(s):
    if c == 'D':
        acc_cnt_a[i] += 1
        cnt_a += 1
    elif c == 'M':
        acc_cnt_b[i] += 1
        acc_cnt_ab[i] += cnt_a
    elif c == 'C':
        c_loc.append(i + 1)
acc_cnt_a = [0] + list(accumulate(acc_cnt_a))
acc_cnt_b = [0] + list(accumulate(acc_cnt_b))
acc_cnt_ab = [0] + list(accumulate(acc_cnt_ab))

q = int(input())
buf = []
for k in map(int, input().split()):
    ans = 0
    for r in c_loc:
        l = r - k
        if l > 0:
            rejected_a = acc_cnt_a[l]
            cnt_internal_b = acc_cnt_b[r] - acc_cnt_b[l]
            cnt_internal_ab = acc_cnt_ab[r] - acc_cnt_ab[l]
            ans += cnt_internal_ab - rejected_a * cnt_internal_b
        else:
            ans += acc_cnt_ab[r]
    buf.append(ans)
print('\n'.join(map(str, buf)))
### BUGGY CODE ###

N=int(input())
A=list(map(int, input().split()))
MOD=7+10**9
ans=0
for i in range(N-1):
    for j in range(i+1,N):
        c = A[i]*A[j] % MOD
        ans += c
print(ans%MOD)

### FIXED CODE ###

N=int(input())
A=list(map(int, input().split()))

MOD=7+10**9
SUM=sum(A)
ans=0

for i in range(N-1):
    SUM-=A[i]
    ans += A[i]*SUM %MOD
print(ans %MOD)
### BUGGY CODE ###

n = int(input())
a = list(map(int, input().split()))
if 0 in a:
  print(0)
else:
  s = 1
  for i in range(n):
    s *= a[i]
  if s > 10**18:
      s = -1    
  print(s)


### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))
if 0 in a:
  print(0)
else:
  s = 1
  for i in a :
    s *= i
    if s > 10**18:
      s = -1
      break
  print(s)
### BUGGY CODE ###

import copy

n = int(input())
l = list(map(int,input().split()))
p = n//2

for i in range(n):
    tmp = copy.copy(l)
    tmp[i] = 0
    tmp.sort()
    print(tmp[p])

### FIXED CODE ###

import copy

n = int(input())
l = list(map(int,input().split()))
p1 = n//2
p2 = n//2-1
ans = copy.copy(l)
ans.sort()

for i in l:
    if i >= ans[p1]:
        print(ans[p2])
    else:
        print(ans[p1])
### BUGGY CODE ###

import math
import collections
def factorize(m):
    b = 2
    fct = []
    while b * b <= m:
        while m % b == 0:
            m //= b
            fct.append(b)
        b += 1
    if m > 1:
        fct.append(m)
    return fct

def comb(n, r):
    if n < r or n < 0 or r < 0:
        return 0
    else:
        return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))

N, M = map(int, input().split())
ans = 1
M_fact = factorize(M)
c = collections.Counter(M_fact)

for ci in c.values():
    #i個をN通りに分ける→i+N-1,i
    ans *= comb(N+ci-1,ci)
print(ans%(10**9+7))

### FIXED CODE ###

import math
def factorize(m):
    fct = []
    b = 2
    while b * b <= m:
        cnt = 0
        while m % b == 0:
            m //= b
            cnt += 1
        if cnt > 0:
            fct.append(cnt)
        b += 1
    if m > 1:
        fct.append(1)
    return fct

def comb(n, r):
    if n < r or n < 0 or r < 0:
        return 0
    else:
        return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))

N, M = map(int, input().split())
ans = 1
M_fct = factorize(M)

for mf in M_fct:
    #mf[1]個をN通りに分ける→comb(mf[1]+N-1,mf[1])
    ans *= comb(N + mf - 1, mf)
    ans %= 10**9+7
print(ans)
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline

h,w,d = map(int,input().split())
A = [list(map(int,input().split())) for i in range(h)]
q = int(input())
for i in range(q):
    l,r = map(int,input().split())
    res = 0
    for s in range(h):
        for t in range(w):
            if A[s][t] == l:
                y1 = s
                x1 = t
    while l != r:
        l += d
        for hh in range(h):
            for ww in range(w):
                if A[hh][ww] == l:
                    y2 = hh
                    x2 = ww
        res += abs(x2-x1)+abs(y2-y1)
        y1 = y2
        x1 = x2
    print(res)
        

### FIXED CODE ###

H,W,D = map(int,input().split())
A = [list(map(int,input().split())) for i in range(H)]
d = [[0,0,0] for _ in range(H*W+2)]
for h in range(H):
    for w in range(W):
        d[A[h][w]+1] = [h+1,w+1,0]
d = d[2:]
for i in range(H*W):
    if i < D:
        continue
    d[i][2] = d[i-D][2]+abs(d[i][0]-d[i-D][0])+abs(d[i][1]-d[i-D][1])
q = int(input())
for i in range(q):
    l,r = map(int,input().split())
    print(d[r-1][2]-d[l-1][2])
### BUGGY CODE ###

# #!/usr/bin/env python3
# # -*- coding: utf-8 -*-
import numpy as np


def main():
    N, K, Q = map(int, input().split())
    result = np.array([K] * N)
    for _ in range(Q):
        a = int(input())

        result[a - 1] += 1
        result -= 1

    for r in result:
        print('Yes'if r > 0 else 'No')


if __name__ == "__main__":
    main()


### FIXED CODE ###

# #!/usr/bin/env python3
# # -*- coding: utf-8 -*-
import numpy as np


def main():
    N, K, Q = map(int, input().split())
    result = np.array([K - Q] * N)
    for _ in range(Q):
        a = int(input())
        result[a - 1] += 1

    for r in result:
        print('Yes'if r > 0 else 'No')


if __name__ == "__main__":
    main()
### BUGGY CODE ###

k, s = map(int, input().split())
ans = 0
for a in range(k+1):
    if a > s:
        break
    for b in range(k+1):
        if a + b > s:
            break
        for c in range(k+1):
            if a + b + c == s:
                ans += 1
            elif a + b + c > s:
                break
print(ans)

### FIXED CODE ###

k, s = map(int, input().split())
ans = 0
for a in range(k+1):
    for b in range(k+1):
        if 0 <= s - a - b <= k:
            ans += 1
print(ans)
### BUGGY CODE ###

from itertools import groupby
# import copy
def calc():
  s = 0
  for i in range(h):
    gr = groupby(g[i])
    j = 0
    for key,it in gr:
      if key==-1: continue
      l = len(list(it))
      if l >= K:
        for k in range(l):
          g[i][j+k] = -1
        # print("s", key, l, key*l)
        s += key*l
      j += l
      # print("j", j)

  # for m in g:
  #   print(m)
  # print(s)
  # import pdb; pdb.set_trace()
  return s

def flatten():
  for j in range(w):
    lst = []
    for i in range(h-1, -1, -1):
      if g[i][j] > 0:
        lst.append(g[i][j])

    lst += [-1] * (h - len(lst))

    for i in range(h-1, -1, -1):
      g[i][j] = lst[h-i-1]

h,w,K = map(int,input().split())
mat = []
for _ in range(h):
  mat.append([int(e) for e in list(input())])

res = 0
for i in range(h):
  for j in range(w):
    score = 0
    # g = copy.deepcopy(mat)
    g = [ [ mat[n][m] for m in range(w) ] for n in range(h) ]
    g[i][j] = -1
    time = 0
    flatten()
    while True:
      s = calc()
      if s > 0:
        score += pow(2, time) * s
      else:
        break
      flatten()
      time += 1
    res = max(res, score)

print(res)

### FIXED CODE ###

from itertools import groupby

def calc(time):
  t = 0
  for i in range(h):
    gr = groupby(g[i])
    lst = []
    p = 0
    for key,it in gr:
      j = len(list(it))
      lst.append([p,key,j])
      p += j
    for j in range(len(lst)):
      if lst[j][1] == -1:
        continue
      if lst[j][2] >= K:
        t += (2**time)*lst[j][1]*lst[j][2]
        for k in range(lst[j][0],lst[j][0]+lst[j][2]):
          g[i][k] = 0

  return t

def flatten():
  for j in range(w):
    lst = []
    for i in range(h-1, -1, -1):
      if g[i][j] > 0:
        lst.append(g[i][j])

    lst += [-1] * (h - len(lst))

    for i in range(h-1, -1, -1):
      g[i][j] = lst[h-i-1]

h,w,K = map(int,input().split())
mat = [ [int(e) for e in list(input())] for _ in range(h) ]

res = 0
for i in range(h):
  for j in range(w):
    score = 0
    g = [ [ mat[n][m] for m in range(w) ] for n in range(h) ]
    g[i][j] = -1
    time = 0
    flatten()
    while True:
      s = calc(time)
      if s==0: break
      score += s
      flatten()
      time += 1
    res = max(res, score)

print(res)
### BUGGY CODE ###

S = list(input())
Q = int(input())
for _ in range(Q):
    query = list(input().split())
    if query[0] == "1":
        S.reverse()
    if query[0] == "2":
        if query[1] == "1":
            S.insert(0,query[2])
        elif query[1] == "2":
            S.append(query[2])
ans = "".join(S)
print(ans)


### FIXED CODE ###

from collections import deque


def main():
    S = deque(list(input()))
    Q = int(input())
    count = 0
    for _ in range(Q):
        query = list(input().split())
        if query[0] == "1":
            count += 1
        if query[0] == "2":
            if count % 2 == 0:
                if query[1] == "1":
                    S.appendleft(query[2])
                elif query[1] == "2":
                    S.append(query[2])
            else:
                if query[1] == "1":
                    S.append(query[2])
                elif query[1] == "2":
                    S.appendleft(query[2])
    if count % 2 == 0:
        ans = "".join(S)
        print(ans)
    else:
        S.reverse()
        ans = "".join(S)
        print(ans)


if __name__ == '__main__':
    main()
### BUGGY CODE ###

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

for _ in range(k):
    ranges = [(i-a-0.5, i+a+0.5) for i, a in enumerate(A, start=1)]
    B = []
    for i in range(n):
        count = 0 
        for r in ranges[:i]:
            if r[1] >= i+1:
                count += 1
        for r in ranges[i:]:
            if r[0] <= i+1:
                count += 1
        B.append(count)
    if A == B:
        A = B
        break
    A = B
print(' '.join(map(str, A)))

### FIXED CODE ###

N, K = list(map(int, input().split()))
A = list(map(int, input().split()))

dp = [0] * (N + 1)
for k in range(K):
    sta = [max(i-A[i], 0) for i in range(N)]
    end = [min(i+A[i]+1, N) for i in range(N)]
    for s in sta:
        dp[s] += 1
    for e in end:
        dp[e] -= 1
    for i in range(1, len(dp)-1):
        dp[i] += dp[i-1]
    B = dp[:-1]
    if A == B:
        break
    A = B
    dp = [0] * (N + 1)
 
print(' '.join(map(str, A)))
### BUGGY CODE ###

n,a,b=map(int,input().split())
s=[]
x=[]
for i in range(a):
    s.append('b')
for i in range(b):
    s.append('r')
for i in range(10**100):
    x.append(s)

x=list(x)
ans=0
for i in range(n):
    if x[i]=='b':
        ans+=1
print(ans)


### FIXED CODE ###

n,a,b=map(int,input().split())
c=a+b
if n<=c:
    if n<=a:
        ans=n
    else:
        ans=a
else:
    x=n//c
    y=x*a
    z=x*c
    t=n-z
    if t<=a:
        ans=y+t
    else:
        ans=y+a
print(ans)
### BUGGY CODE ###

import heapq

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


d_AB = {a:[] for a,b in AB}
for a,b in AB:
    d_AB[a].append(-b)

H = []
money = 0
for i in range(1,M+1):
    if i in d_AB.keys():
        H += d_AB[i]
    else:
        H += [0]
    #print(H)
    heapq.heapify(H)
    money += heapq.heappop(H)

print(-money)

### FIXED CODE ###

import heapq

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


d_AB = {a:[] for a,b in AB}
for a,b in AB:
    d_AB[a].append(-b)
#print(d_AB)
H = []
heapq.heapify(H)
money = 0
for i in range(1,M+1):
    if i in d_AB.keys():
        for ab in d_AB[i]:
            heapq.heappush(H,ab)
        #print(H)
        money += heapq.heappop(H)
        #print(money)
        
    else:
        money += heapq.heappushpop(H,0)

print(-money)
### BUGGY CODE ###

def args():
    N, W = tuple(map(int, input().split()))

    Wi, Vi = [], []
    for _ in range(N):
        w, v = tuple(map(int, input().split()))
        Wi.append(w)
        Vi.append(v)

    # print(N, W)
    # print(Wi, Vi)

    return N, W, Wi, Vi


def solve(N, W, Wi, Vi):
    if N == 1:
        return Vi[0]

    x, y = N + 1, max(Vi) * N + 1
    DP = [[float("inf") for _ in range(y)] for _ in range(x)]

    # print(len(DP[0]))

    DP[0][0] = 0

    for i in range(N):
        value = Vi[i]
        w_max = max(Vi) * N
        for v in range(w_max):
            remain = v - value
            if 0 <= remain:
                # 選ぶ
                DP[i + 1][v] = min(DP[i + 1][v], DP[i][remain] + Wi[i])
            # 選ばない
            DP[i + 1][v] = min(DP[i + 1][v], DP[i][v])

    # print(DP)
    ans = 0
    for line in DP:
        for v, e in enumerate(line):
            if not e == float("inf") and e <= W:
                # print(v, e)
                ans = max(ans, v)

    # print(DP)

    return ans


if __name__ == '__main__':
    res = solve(*args())
    print(res)


### FIXED CODE ###

def args():
    N, W = tuple(map(int, input().split()))

    Wi, Vi = [], []
    for _ in range(N):
        w, v = tuple(map(int, input().split()))
        Wi.append(w)
        Vi.append(v)

    # print(N, W)
    # print(Wi, Vi)

    return N, W, Wi, Vi


def solve(N, W, Wi, Vi):
    DP = [[float("inf")] * (sum(Vi) + 1) for _ in range(N + 1)]

    DP[0][0] = 0

    for i in range(N):
        value = Vi[i]
        w_max = sum(Vi) + 1
        for v in range(w_max):
            remain = v - value
            if 0 <= remain:
                # 選ぶ
                DP[i + 1][v] = min(DP[i + 1][v], DP[i][remain] + Wi[i])
            # 選ばない
            DP[i + 1][v] = min(DP[i + 1][v], DP[i][v])

    # print(DP)
    ans = 0
    for line in DP:
        for v, e in enumerate(line):
            if not e == float("inf") and e <= W:
                # print(v, e)
                ans = max(ans, v)

    # print(DP)

    return ans


if __name__ == '__main__':
    res = solve(*args())
    print(res)