Harryxun/stf_run huggingface dataset:
# @author 

import sys

class SDigitSum:
    def solve(self):
        MOD = 10 ** 9 + 7

        k = int(input())
        d = int(input())

        s = len(str(k))
        dp = [[0] * d for _ in range(s)]
        dp[0][0] = 1
        for i in range(10):
            dp[1][i % d] += 1
        for l in range(2, s):
            for r in range(d):
                dp[l][r] = (dp[l - 1][r] + sum(dp[l - 1][(-lm + r) % d] for lm in range(1, 10))) % MOD


        ans = dp[s - 1][0]
        done = 0
        for i in range(s):
            lm = int(str(k)[i])
            ans = (ans + sum(dp[s - 1 - i][(-done - (lm - v)) % d] for v in range(1, lm + 1 * (i != 0)))) % MOD
            done += lm

        if (sum(int(x) for x in str(k))) % d == 0:
            ans = (ans + 1) % MOD

        print((ans - 1) % MOD)

solver = SDigitSum()
input = sys.stdin.readline

solver.solve()


### FIXED CODE ###

# @author 

import sys

class SDigitSum:
    def solve(self):
        MOD = 10 ** 9 + 7

        k = input().strip()
        d = int(input())

        s = len(k)
        dp = [[0] * d for _ in range(s + 1)]
        dp[0][0] = 1
        for i in range(10):
            dp[1][i % d] += 1

        pre = [[0] * (d + 1) for _ in range(s + 1)]
        for i in range(d):
            pre[1][i] = pre[1][i - 1] + dp[1][i]
        for l in range(2, s):
            # cur is sum(dp[l - 1][(-lm + r) % d] for lm in range(1, 10)
            cur = sum(dp[l - 1][(-lm + 0) % d] for lm in range(1, 10))
            for r in range(d):
                # dp[l][r] = (dp[l - 1][r] + sum(dp[l - 1][(-lm + r) % d] for lm in range(1, 10))) % MOD
                dp[l][r] = (dp[l - 1][r] + cur) % MOD
                cur -= dp[l - 1][(r - 9) % d]
                cur += dp[l - 1][(r + 1 - 1) % d]


        ans = dp[s - 1][0]
        done = 0
        for i in range(s):
            lm = int(k[i])
            ans = (ans + sum(dp[s - 1 - i][(-done - (lm - v)) % d] for v in range(1, lm + 1 * (i != 0)))) % MOD
            done += lm

        if (sum(int(x) for x in k)) % d == 0:
            ans = (ans + 1) % MOD

        print((ans - 1) % MOD)

solver = SDigitSum()
input = sys.stdin.readline

solver.solve()
N, M = map(int, input().split())
A = set([int(input()) for _ in range(M)])
mod = 10**9 + 7
ans = [0] * (N+1)
ans[0] = 1
ans[1] = 1 if i not in a else 0
for i in range(2, N+1):
  ans[i] = (ans[i-1]+ans[i-2])%mod if i not in a else 0
print(ans[N])

### FIXED CODE ###

N, M = map(int, input().split())
A = set([int(input()) for _ in range(M)])
mod = 10**9 + 7
ans = [0] * (N+1)
ans[0] = 1
ans[1] = 1 if 1 not in A else 0
for i in range(2, N+1):
  ans[i] = (ans[i-1]+ans[i-2])%mod if i not in A else 0
print(ans[N])
a,b=map(int,input().split())
if a=="H" and b== "H":print("H")
elif a=="H" and b== "D":print("D")
elif a=="D" and b== "H":print("D")
else:print("H")

### FIXED CODE ###

a,b=input().split()
if a=="H" and b== "H":print("H")
elif a=="H" and b== "D":print("D")
elif a=="D" and b== "H":print("D")
else:print("H")
import numpy as np
from sys import stdin
mod = 998244353
def main():
    N,S = map(int,stdin.readline().split())
    a = list(map(int,stdin.readline().split()))
    a = np.asarray(a)
    dp = np.zeros((N+1,S+1,3))
    dp[0][0][0] = 1
    for i in range(N):
        for j in range(S+1):
            dp[i+1][j][0] += dp[i][j][0] ;dp[i+1][j][0] %= mod
            dp[i+1][j][1] += dp[i][j][0]+dp[i][j][1];dp[i+1][j][1] %= mod
            dp[i+1][j][2] += dp[i][j][0]+dp[i][j][1]+dp[i][j][2];dp[i+1][j][2]%= mod
            if j+a[i] <= S:
                dp[i+1][j+a[i]][1] += dp[i][j][0]+dp[i][j][1];dp[i+1][j+a[i]][1] %= mod
                dp[i+1][j+a[i]][2] += dp[i][j][0]+dp[i][j][1];dp[i+1][j+a[i]][2] %= mod
    print(int(dp[N][S][2]))
if __name__ == "__main__":
    main()

### FIXED CODE ###

from sys import stdin
mod = 998244353
def main():
    N,S = map(int,stdin.readline().split())
    a = list(map(int,stdin.readline().split()))
    dp = [0]*(S+1)
    ans = 0
    for A in a:
        dp[0] += 1
        for i in reversed(range(A,S+1)):
            dp[i] += dp[i-A]    
            dp[i] %= mod
        ans += dp[S]
        ans %= mod
    print(ans)
if __name__ == "__main__":
    main()
import sys
input=sys.stdin.readline

n=int(input())
s=input()
dp=[[[False]*1000 for j in range(4)] for i in range(n+1)]

dp[0][0][0]=True

for i in range(n):
    for j in range(4):
        for k in range(1000):
            if dp[i][j][k]==False:continue
            dp[i+1][j][k]=True
            if j<=2:
                dp[i+1][j+1][k*10+int(s[i])]=True
cnt=0
for i in range(1000):
    if dp[n][3][i]==1:cnt+=1
print(cnt)

### FIXED CODE ###

m,d=map(int,input().split(" "))
mm,dd=map(int,input().split(" "))
if m==mm:print(0)
else:print(1)
L,R= map(int,input().split())
#境界条件
bool = True
for i in range(L,R):
    for j in range(i+1,r+1):
        temp = (i * j) % 2019
        if bool:
            min = temp
            ans = min
            bool = False
        elif min > temp:
            min = temp
            ans = min
        if min == 0:
            break
print(ans)

### FIXED CODE ###

L,R= map(int,input().split())
#境界条件
bool = True
flag = False
for i in range(L,R):
    for j in range(i+1,R+1):
        temp = (i * j) % 2019
        if bool:
            min = temp
            ans = min
            bool = False
        elif min > temp:
            min = temp
            ans = min
        if min == 0:
            flag = True
            break
    if flag:
        break
print(ans)
import math
A, B = map(int, input().strip().split())

minAB = min(A,B);

hurui = [True] * (minAB+1)

upper = int(math.sqrt(minAB+1))
ans = 1
for i in range(2, upper+1):
    """
    if not(hurui[i]):
        continue
    
    for j in range(2*i, minAB+1, i):
        hurui[j] = False
    """
    if A % i == 0  and B % i == 0:
        ans += 1

print(ans)

### FIXED CODE ###

import math
A, B = map(int, input().strip().split())

divisors = []

minAB = min(A,B)
maxAB = max(A,B)
upper = int(math.sqrt(minAB+1) + 1)
ans = 1

for i in range(1, upper):
    if minAB % i == 0:
        divisors.append(i)
        if i != minAB//i:
            divisors.append(minAB//i)

divisors.sort()
#print(divisors)

flag = [True] * len(divisors)
for i, num in enumerate(divisors):
    if maxAB % num != 0:
        flag[i] = False
        continue
    for x in divisors:
        if x == 1 :
            continue
        if x > math.sqrt(num):
            break
        if num % x ==0:
            flag[i] = False
            break

print(flag.count(True))
#0<3>2>1>0<1<2>0<1<2<3<4<5>2>1>0<1
import math
s = input()
bigger=0
smaller=0
count = 0
for i in range(len(s)-1):
    if (s[i]==">" and s[i+1]=="<"):
        count += (max(bigger,smaller))*((max(bigger,smaller))+1)/2
        count += (min(bigger,smaller)-1)*((min(bigger,smaller)-1)+1)/2 if (min(bigger,smaller)-1)!=0 else 0
        bigger = 0
        smaller = 0
    elif (s[i]=="<" and s[i+1]=="<"):
        bigger += 1
    elif (s[i]=="<" and s[i+1]==">"):
        bigger += 1
        smaller += 1
    elif (s[i]==">" and s[i+1]==">"):
        smaller += 1
count += (max(bigger,smaller))*((max(bigger,smaller))+1)/2
count += math.factorial(min(bigger,smaller)-1) if smaller!=0 else True

print(int(count))


### FIXED CODE ###

#0<3>2>1>0<1<2>0<1<2<3<4<5>2>1>0<1
import math
s = input()
bigger=0
smaller=0
count = 0
bigger=1 if s[0]=="<" else 0 
smaller=1 if s[0]==">" else 0 


for i in range(len(s)-1):
    if (s[i]==">" and s[i+1]=="<"):
        count += (max(bigger,smaller))*((max(bigger,smaller))+1)/2
        count += (min(bigger,smaller)-1)*(min(bigger,smaller))/2 if (min(bigger,smaller)-1)!=0 else 0
        bigger = 1
        smaller = 0
    elif (s[i]=="<" and s[i+1]=="<"):
        bigger += 1
    elif (s[i]=="<" and s[i+1]==">"):
        smaller += 1
    elif (s[i]==">" and s[i+1]==">"):
        smaller += 1
count += (max(bigger,smaller))*((max(bigger,smaller))+1)/2
count += (min(bigger,smaller)-1)*(min(bigger,smaller))/2 if (min(bigger,smaller)-1)!=0 else 0

print(int(count))
a,b=input()
c=a*b
d=(a+b)*2
print c+" "+d

### FIXED CODE ###

l = map(int, raw_input().split())
a=l[0]
b=l[1]
c=a*b
d=(a+b)*2
print str(c)+" "+str(d)
s=int(input())
print("Heisei" if s<="2019/04/30" else "TBD")

### FIXED CODE ###

s=input()
print("Heisei" if s<="2019/04/30" else "TBD")
A=input ()
B=0
while B =!2:
if A[B] == A[B+1]:
    print ('Bad')
    break
else:
    B +=1
else:
    print('Good')


### FIXED CODE ###

A=str(input () )
B=0
while B!=3:
    if A[B]==A[B+1]:
        print('Bad')
        break
    else:    
        B=B+1
else:
    print('Good')
import sys
import res
#X = list(map(str,input().split()))
X = str(input())
print(re.sub(',',' ',X))

### FIXED CODE ###

import sys
import re
#X = list(map(str,input().split()))
X = str(input())
print(re.sub(',',' ',X))
#レート
#1-399：灰色
#400-799：茶色
#800-1199：緑色
#1200-1599：水色
#1600-1999：青色
#2000-2399：黄色 
#2400-2799：橙色
#2800-3199：赤色



N = int(input())
scores = sorted(list(map(int,input().split())))
colors = []

color = ""
another = 0

for point in scores:
  if point <= 399:
    color = "gray"
    if color not in colors:
      colors.append(color)
  elif point <= 799 and points :
    color = "brown"
    if color not in colors:
      colors.append(color)
  elif point <= 1199:
    color = "sky"
    if color not in colors:
      colors.append(color)
  elif point <= 1999:
    color = "blue"
    if color not in colors:
      colors.append(color)
  elif point <= 2399:
    color = "yellow"
    if color not in colors:
      colors.append(color)
  elif point <= 2799:
    color = "orange"
    if color not in colors:
      colors.append(color)
  elif point <= 3199:
    color = "red"
    if color not in colors:
      colors.append(color)
  elif point > 3199:
    another += 1
    
ans = len(colors)

print(ans,ans + another)

### FIXED CODE ###

#レート
#1-399：灰色
#400-799：茶色
#800-1199：緑色
#1200-1599：水色
#1600-1999：青色
#2000-2399：黄色 
#2400-2799：橙色
#2800-3199：赤色

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

colors = []
color = ""
another = 0

for point in scores:
  if point <= 399:
    color = "gray"
    if color not in colors:
      colors.append(color)
  elif point <= 799:
    color = "brown"
    if color not in colors:
      colors.append(color)
  elif point <= 1199:
    color = "green"
    if color not in colors:
      colors.append(color)
  elif point <= 1599:
    color = "sky"
    if color not in colors:
      colors.append(color)
  elif point <= 1999:
    color = "blue"
    if color not in colors:
      colors.append(color)
  elif point <= 2399:
    color = "yellow"
    if color not in colors:
      colors.append(color)
  elif point <= 2799:
    color = "orange"
    if color not in colors:
      colors.append(color)
  elif point <= 3199:
    color = "red"
    if color not in colors:
      colors.append(color)
  elif point > 3199:
    another += 1
    
ans = len(colors)
if ans == 0:
  print(1,another)
else:
  print(ans,ans + another)
def pie(A, P):
    P_cra = A*3

    P_all = P_cra + P

    pie = P_all//2

    print(pie)

A, P = input(), input()
pie(A, P)
    

### FIXED CODE ###

def pie(A, P):
    P_cra = A*3
 
    P_all = P_cra + P
 
    pie = P_all//2
 
    print(pie)

l = list(map(int, input().split()))
A = int(l[0])
P = int(l[1])
pie(A, P)
while 1:
     x, y = map(int, raw_input().split())
     if x == 0 and y == 0:
         break
     else:
         if x > y:
           print '%s %s' % (y,x)
         else:
           print '%s %s' % (x,y)
    

### FIXED CODE ###

while 1:
   x, y = map(int, raw_input().split())
   if x == 0 and y == 0:
      break
   elif x > y:
      print '%s %s' % (y,x)
   else:
      print '%s %s' % (x,y)
from collections import Counter

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

def combinations_count(n, r):
    if n==1:
        return 0
    else:
        return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

for k in range(N):
    tmp=Balls[k]
    del Balls[k]

    array_k = Balls
    sum_k=0
    c= Counter(array_k)
    for j in list(c.values()):
        sum_k += combinations_count(j,2)
    
    Balls.insert(k,tmp)
    print(sum_k)




### FIXED CODE ###

import math
from collections import Counter

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

def combinations_count(n, r):
    if n==1:
        return 0
    else:
        return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
c = Counter(Balls)
d={}
ALL_SUM=0
for i,j in c.most_common():
    d[i]=j
    ALL_SUM+=combinations_count(j,2)
for k in Balls:
    print(ALL_SUM-(d[k] - 1))

# for k in range(N):
#     tmp=Balls[k]
#     array_k = Balls
#     sum_k=0
#     c= Counter(array_k)


#     for j in list(c.values()):
#         sum_k += combinations_count(j,2)
    
#     Balls.insert(k,tmp)
#     print(sum_k)
import numpy as np
i8 = np.int64
i4 = np.int32


def solve(i, prev, t, d, ans):
    if i == 0:
        num = len(t[i])
    else:
        num = len(t[i]) + 1
    x = 1
    if prev == 1:
        x = 2
    for c in t[i]:
        if c == prev:
            continue
        ans[d[i, c]] = x
        num = max(num, solve(c, x, t, d, ans))
        x += 1
        if x == prev:
            x += 1
    return num


def main():
    stdin = open('/dev/stdin')
    N = int(stdin.readline())
    d = np.empty((N, N), i8)
    d.fill(-1)
    t = [[] for _ in range(N)]
    count = 0
    ans = np.zeros(N - 1, i8)
    for _ in range(N - 1):
        a, b = map(int, stdin.readline().split())
        t[a - 1].append(b - 1)
        t[b - 1].append(a - 1)
        d[a - 1, b - 1] = count
        d[b - 1, a - 1] = count
        count += 1
    num = solve(0, -1, t, d, ans)
    print(num)
    for c in ans:
        print(c)

main()


### FIXED CODE ###

import numpy as np
import sys
sys.setrecursionlimit(100000)
i8 = np.int64
i4 = np.int32


def solve(i, prev, prevc, t, d, ans):
    num = len(t[i])
    x = 1
    if prevc == 1:
        x = 2
    for c in t[i]:
        if c == prev:
            continue
        ans[d[(i, c)]] = x
        num = max(num, solve(c, i, x, t, d, ans))
        x += 1
        if x == prevc:
            x += 1
    return num


def main():
    stdin = open('/dev/stdin')
    N = int(stdin.readline())
    d = {}
    t = [[] for _ in range(N)]
    count = 0
    ans = np.zeros(N - 1, i8)
    for _ in range(N - 1):
        a, b = map(int, stdin.readline().split())
        t[a - 1].append(b - 1)
        t[b - 1].append(a - 1)
        d[(a - 1, b - 1)] = count
        d[(b - 1, a - 1)] = count
        count += 1
    num = solve(0, -1, -1, t, d, ans)
    print(num)
    for c in ans:
        print(c)

main()
data = input().split()
n = int(data[0])
m = int(data[1])
edge=[]
for i in range(m):
    tmp = []
    data = input().split()
    tmp.append(int(data[0])-1)
    tmp.append(int(data[1])-1)
    edge.append(tmp)

grp=list(range(0, n))
def group(num):
    if grp[num] != num:
        return group(grp[num])
    return num

def merge(num1, num2):
    grp[num2]=grp[num1]

res=[]
ans = [1]*n
ben = int(n*(n-1)/2)
edge.reverse()
for e in edge:
    #print(e, ans, ben, grp)
    res.append(ben)
    if group(e[0]) != group(e[1]):
        ben -= ans[group(e[0])]*ans[group(e[1])]
        sum = ans[group(e[0])]+ans[group(e[1])]
        merge(group(e[0]), group(e[1]))
        ans[group(e[0])]=sum

res.reverse()
for r in res:
    print(r)

#print(int(n*(n-1)/2))

### FIXED CODE ###

import sys
sys.setrecursionlimit(100000)

data = input().split()
n = int(data[0])
m = int(data[1])
edge=[]
for i in range(m):
    tmp = []
    data = input().split()
    tmp.append(int(data[0])-1)
    tmp.append(int(data[1])-1)
    edge.append(tmp)

grp=list(range(0, n))
def group(num):
    if grp[num] == num:
        return num
    return group(grp[num])

def merge(p_num, c_num):
    grp[c_num]=grp[p_num]

res=[]
ans = [1]*n
ben = int(n*(n-1)/2)
edge.reverse()
for e in edge:
    #print(e, ans, ben, grp)
    res.append(ben)
    g0 = group(e[0])
    g1 = group(e[1])
    if g0 != g1:
        ben -= ans[g0]*ans[g1]
        sum = ans[g0]+ans[g1]
        if ans[g0] > ans[g1]:
            merge(g0, g1)
        else:
            merge(g1, g0)
        ans[g0]=sum
        ans[g1]=sum

res.reverse()
for r in res:
    print(r)

#print(int(n*(n-1)/2))
a,op,b = list(map(str, input().split()))
if op == "+":
  ans = int(a) + int(b)
else:
  ans == int(a) - int(b)
print(ans)

### FIXED CODE ###

a,op,b = list(map(str, input().split()))
if op == "+":
  ans = int(a) + int(b)
else:
  ans = int(a) - int(b)
print(ans)
#49a
s = input()
if s=='a' or s=='i' or s=='u' or s='e' or s='o':
    print('vowel')
else:
    print('consonant')

### FIXED CODE ###

#49a
s = input()
if s=='a' or s=='i' or s=='u' or s=='e' or s=='o':
    print('vowel')
else:
    print('consonant')
n, m, d = map(int, input().split())
if d == 0:
    print((m-1) / double(n) )
else:
    print(2 * (m-1) * (n-d) / double(n * n))

### FIXED CODE ###

(n, m, d) = map(int, input().split())
if d == 0:
    print((m-1) / float(n))
else:
    print(2 * (m-1) * (n-d) / float(n * n))
import fractions

K = input()

Sum = 0

for A in range(K):
    a = A + 1
    for B in range(K):
        b = B + 1
        for C in range(K):
            c = C + 1

            Sum = Sum + fractions.gcd(fractions.gcd(a, b), c)

print(Sum)

### FIXED CODE ###

import math
 
K = input()
 
Sum = 0
k = int(K)
 
for A in range(k):
    a = A + 1
    for B in range(k):
        b = B + 1
        gcd_ab = math.gcd(a, b)
        for C in range(k):
            c = C + 1
 
            Sum = Sum + math.gcd(gcd_ab, c)
 
print(Sum)
X,Y,A,B,C = map(int,input().split())
p = list(map(int,input().split()))
q = list(map(int,input().split()))
r = list(map(int,input().split()))

p.sort(reverse=True)
q.sort(reverse=True)
r.sort(reverse=True)

a = p[:X]
b = q[:Y]
p_c = -1
q_c = -1
r_c = 0
k = 0


ans = sum(a)+sum(b)
while(True):
    if p_c < - X or a[p_c] >= b[q_c]:
        if b[q_c] < r[r_c] and q_c >= - Y:
            ans += ( r[r_c] - b[q_c] )
            r_c += 1
            q_c -= 1
        else:
            k = 1

    else:
        if a[p_c] < r[r_c]:
            ans += (r[r_c] - a[p_c])
            r_c += 1
            p_c -= 1
        else:
            k = 1

    if k == 1 or r_c >= C:
        break

print(ans)

### FIXED CODE ###

X,Y,A,B,C = map(int,input().split())
p = list(map(int,input().split()))
q = list(map(int,input().split()))
r = list(map(int,input().split()))

p.sort(reverse=True)
q.sort(reverse=True)
r.sort(reverse=True)

a = [10**10]*(10**5)
a.extend(p[:X])
b = [10**10]*(10**5)
b.extend(q[:Y])
p_c = -1
q_c = -1
r_c = 0
k = 0

ans = sum(p[:X])+sum(q[:Y])
while(True):
    if a[p_c] >= b[q_c]:
        if b[q_c] < r[r_c] and q_c >= - Y:
            ans += ( r[r_c] - b[q_c] )
            r_c += 1
            q_c -= 1
        else:
            k = 1

    else:
        if a[p_c] < r[r_c]:
            ans += (r[r_c] - a[p_c])
            r_c += 1
            p_c -= 1
        else:
            k = 1

    if k == 1 or r_c >= C:
        break

print(ans)
print(A*B)

### FIXED CODE ###

A,B=(int(x) for x in input().split())
num = A * B
print(num)
import sys                                                                      
 
if __name__ == '__main__':  
    x = sys.argv[1]
    a = sys.argv[2]
    if (x < a): 
        print('0')
    else:
        print('10')

### FIXED CODE ###

import sys                                                                      
 
if __name__ == '__main__':
    s = input().strip().split(' ')
    x = int(s[0])
    a = int(s[1])
    if (x < a): 
        print('0')
    else:
        print('10')
#! /usr/bin/python3
# こだわり者いろはちゃん / Iroha's Obsession

"""
    1≦N<10000
    1≦K<10
    0≦D1<D2<…<DK≦9
    {D1,D2,…,DK}≠{1,2,3,4,5,6,7,8,9}
"""

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

test_mode = False


def check_num(x, d):
    """
    金額xの中に中の文字があるか確認する関数。
    x : 現在の金額（N, x+1 を想定）
    d : 嫌いな数字のリスト（D を想定）
    文字列 x にリスト d 中の要素が含まれているか、d の要素 num を順に確認し、
    含まれていたら1円足して再試行する。
    """
    if test_mode:
        print('x =', x)
    for num in d:
        str_x = str(x)
        str_num = str(num)
        if str_num in str_x:
            return check_num(x+1, d)
    return x

  
amount = check_num(N, D)
print(amount)


### FIXED CODE ###

#! /usr/bin/python3
# こだわり者いろはちゃん / Iroha's Obsession
# 参考 : https://abc042.contest.atcoder.jp/submissions/3419872

"""
    1≦N<10000
    1≦K<10
    0≦D1<D2<…<DK≦9
    {D1,D2,…,DK}≠{1,2,3,4,5,6,7,8,9}
"""

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

test_mode = False


def check_num(x, d):
    """
    金額xの中に中の文字があるか確認する関数。
    x : 現在の金額（N, x+1 を想定）
    d : 嫌いな数字のリスト（D を想定）
    文字列 x にリスト d 中の要素が含まれているか、d の要素 num を順に確認し、
    含まれていたら1円足して再試行する。
    """
    if test_mode:
        print('x =', x)
    while len(set(list(str(x))) & d) != 0:
        x += 1
    return x


def main():
    """
    金額を算出して出力
    """
    amount = check_num(N, D)
    print(amount)


if __name__ == '__main__':
    main()
# coding: utf-8
import sys

try:
    inputline = list(input()) #1文字ずつ文字のリストに
    akihabara = list("AKIHABARA")
    
    lineLength = len(akihabara) - len(inputline)
    # 正解より文字数が多い、あるいは文字数が5文字以下のとき
    if lineLength < 0 or lineLength >= 5:
        sys.exit("NO")
    # 正解と文字数が同じとき
    elif lineLength == 0:
        if inputline == akihabara:
            sys.exit("YES")
        else:
            sys.exit("NO")
    # 正解より文字数が少ないとき
    else:
        for i in range(9):
            if i == 8 and len(inputline)<9:
                inputline.append("A")
            elif inputline[i] != akihabara[i]:
                inputline.insert(i, "A")
    
    if inputline == akihabara:
        sys.exit("YES")
    else:
        sys.exit("NO")
        
    raise Exception('I know Python!')

except RuntimeError:
    sys.exit("NO")


### FIXED CODE ###

# coding: utf-8
import sys
 
inputline = list(input()) #1文字ずつ文字のリストに
akihabara = list("AKIHABARA")

# Aの数
count = 4

lineLength = len(akihabara) - len(inputline)
for i in range( len(inputline) ):
    if inputline[i] == "A":
      count -= 1
#print(count)
# 正解より文字数が多い、あるいは文字数が5文字以下のとき
if lineLength < 0 or len(inputline)+count < 9 :
    print("NO")
# 正解と文字数が同じとき
elif lineLength == 0:
    if inputline == akihabara:
        print("YES")
    else:
        print("NO")
# 正解より文字数が少ないとき

else:
    for i in range(9):
        if i == 8 and len(inputline)<9:
            inputline.append("A")
        elif inputline[i] != akihabara[i]:
            inputline.insert(i, "A")
            
    if inputline == akihabara:
        print("YES")
    else:
        print("NO")
a,b,k=map(int,input().split())
if a-b<=c:
  for i in range(a,b):
    print(i)
else:
  for i in range(a,a+c-1):
    print(i)
  for y in range(b-c+1,b):
    print(y)

### FIXED CODE ###

a,b,k=map(int,input().split())
if b-a+1<=k*2:
  for i in range(a,1+b):
    print(i)
else:
  for i in range(a,a+k):
    print(i)
  for y in range(b-k+1,b+1):
    print(y)
n,m = map(int,input().split())
dp = [0]*(n+1)
L = []
for i in range(n):
    a,b = map(int,input().split())
    L.append([a,b])

L.sort(key = lambda x:x[1],reverse = True)
#print(L)
cnt =0
cost = 0
for i in range(n):
    if 0 <=L[i][0] <=m and dp[i] !=1:
        dp[m - L[i][0]] = 1
        cost +=L[i][1]
print(cost)


### FIXED CODE ###

import heapq
n,m = map(int,input().split())
dp = [0]*(n+1)
L = []
days = []
cost = []
for i in range(n):
    a,b = map(int,input().split())
    if a > m:
        continue
    L.append([a,b])

L.sort(reverse = True)

ans = 0
li = []
for i in range(1,m+1):
    while L and L[-1][0] <= i:
        (a,b) = L.pop()
        heapq.heappush(li,b*(-1))

    if li:
        h = heapq.heappop(li)
        ans +=(-1)*h

print(ans)