Harryxun/stf_run huggingface dataset:
nn=[2,5,5,4,5,6,3,7,6]
n,m=map(int,input().split())
a=input().split()
b=[]
for i in range(m):
  a[i]=int(a[i])
  
if 5 in a:
  if 2 in a:
    a.remove(2)
  if 3 in a:
    a.remove(3)
elif 3 in a:
  if 2 in a:
    a.remove(2)
if 9 in a:
  if 6 in a:
    a.remove(6)
    
a.sort(reverse=True)
for i in range(len(a)):
  b.append(nn[a[i]-1])
  
dp=[-10*18 for _ in range(n+1)]
dp[0]=0
for i in range(n):
  for j in range(len(b)):
    if i+b[j]>n:
      continue
    dp[i+b[j]]=max(dp[i+b[j]],dp[i]+1)
    
k=dp[n]
ans=""
for i in range(k):
  for j in range(len(b)):
    if dp[n-b[j]]==dp[n]-1:
      ans+=str(a[j])
      n-=b[j]
      break
      
print(ans)



### FIXED CODE ###

nn=[2,5,5,4,5,6,3,7,6]
n,m=map(int,input().split())
a=input().split()
b=[]
for i in range(m):
  a[i]=int(a[i])
  
if 5 in a:
  if 2 in a:
    a.remove(2)
  if 3 in a:
    a.remove(3)
elif 3 in a:
  if 2 in a:
    a.remove(2)
if 9 in a:
  if 6 in a:
    a.remove(6)
    
a.sort(reverse=True)
for i in range(len(a)):
  b.append(nn[a[i]-1])
  
dp=[-10*18 for _ in range(n+1)]
dp[0]=0
for i in range(n):
  for j in range(len(b)):
    if i+b[j]>n:
      continue
    dp[i+b[j]]=max(dp[i+b[j]],dp[i]+1)
    
k=dp[n]
ans=""
for i in range(k):
  for j in range(len(b)):
    if n-b[j]<0:
      continue
    if dp[n-b[j]]==dp[n]-1:
      ans+=str(a[j])
      n-=b[j]
      break
      
print(ans)
def func(b, n):
    res = 0
    while n > 0:
        res += n % b
        n //= b
    return res


def solve():
    n = int(input())
    s = int(input())

    if n == s:
        return n + 1
    # elif n < s:
    #     return -1

    for b in range(2, n + 1):
        if b**2 > n:
            break
        if func(b, n) == s:
            return b

    for p in range(1, n + 1):
        if p**2 > n:
            break

        b = (n - s) // p + 1
        if func(b, n) == s:
            return b

    return -1


ans = solve()
print(ans)


### FIXED CODE ###

def func(b, n):
    res = 0
    while n > 0:
        res += n % b
        n //= b
    return res


def solve():
    n = int(input())
    s = int(input())

    if n == s:
        return n + 1
    elif n < s:
        return -1

    for b in range(2, n + 1):
        if b**2 > n:
            break
        if func(b, n) == s:
            return b

    b_cand = []
    for p in range(1, n + 1):
        if p**2 > n:
            break
        b = (n - s) // p + 1
        if b > 1:
            b_cand.append(b)
    b_cand = b_cand[::-1]

    for b in b_cand:
        # print(b)
        if func(b, n) == s:
            return b

    return -1


ans = solve()
print(ans)
import math
import fractions
#import sys
#input = sys.stdin.readline

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors

def ValueToBits(x,digit):
    res = [0 for i in range(digit)]
    now = x
    for i in range(digit):
        res[i]=now%2
        now = now >> 1
    return res

def BitsToValue(arr):
    n = len(arr)
    ans = 0
    for i in range(n):
        ans+= arr[i] * 2**i
    return ans

def ZipArray(a):
    aa = [[a[i],i]for i in range(n)]

    aa.sort(key = lambda x : x[0])
    for i in range(n):
        aa[i][0]=i+1
    aa.sort(key = lambda x : x[1])
    b=[aa[i][0] for i in range(len(a))]
    return b

def ValueToArray10(x, digit):
    ans = [0 for i in range(digit)]
    now = x
    for i in range(digit):
        ans[digit-i-1] = now%10
        now = now //10
    return ans

def Zeros(a,b):
    if(b<=-1):
        return [0 for i in range(a)]
    else:
        return [[0 for i in range(b)] for i in range(a)]

class Bit:
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)
 
    def sum(self, i):
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s
 
    def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & -i
            
'''
def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % p

p = 2
N = 10 ** 6 + 2
fact = [1, 1]  # fact[n] = (n! mod p)
factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1]  # factinv 計算用

for i in range(2, N + 1):
    fact.append((fact[-1] * i) % p)
    inv.append((-inv[p % i] * (p // i)) % p)
    factinv.append((factinv[-1] * inv[-1]) % p)

'''

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

#################################################
#################################################
#################################################
#################################################


n = int(input())
c = list(map(int, input().split()))
a = []
for i in range(n):
    temp = list(map(int, input().split()))
    a.append(temp)

ans = [(i%26) for i in range(n)]

def cost(a,c,ans):
    val = 0
    last = [0 for i in range(26)]
    for i in range(n):
        for j in range(26):
            last += 1
        here = ans[i]
        val += a[i][here]
        last[here] = 0
        for j in range(26):
            val -= last[j]*c[j]
    return val
#

for i in range(n):
    maxim = -10**9
    idx = -1
    for j in range(26):
        if(maxim < a[i][j]):
            idx = j
            maxim = a[i][j]
    ans[i] = idx
#print(ans)

d = [[i,c[i]]]

for i in ans:
    print(i+1)











### FIXED CODE ###

for i in range(365):
  print(i%26+1)
W, H, x, y = map(int, input().split())
jufuku = 0
if x == 0 and y == 0:
    if y / x == H / W:
        naname = W * H / 2
        jufuku = 1
        kiri = naname
else:
    # 縦
    tate = min((W - x) * H, x * H)
    # 横
    yoko = min(W * (H - y), W * y)
    if tate == yoko:
        jufuku = 1
    kiri = max(tate, yoko)
print(kiri, jufuku)


### FIXED CODE ###

W, H, x, y = map(int, input().split())
jufuku = 0
if W / 2 == x and H / 2 == y:
    jufuku = 1
print(W * H / 2, jufuku)
s = input()
h = s/3600
s = s%3600
m = s/60
s = s%60

print str(h) + ":" + str(m) + ":" + str(s)

### FIXED CODE ###

S = int(input())
print(S // 3600, S % 3600 // 60, S % 60, sep=':')
d,n=map(int,input())
ans=100**d*n if n<100 else 100*d*101
print(ans)

### FIXED CODE ###

def resolve():
	d,n=map(int,input().split())
	ans=100**d*n if n<100 else 100**d*101
	print(ans)
resolve()
import sys
sys.setrecursionlimit(100000000000000000)
def burger(l):
    memo = [0] * (l+1)
    def l_burger(l):
        if l == 0:
            return 'P'
        if memo[l] != 0:
            return memo[l]
        
        memo[l] = 'B' + l_burger(l-1) + 'P' + l_burger(l-1) + 'B'
        return memo[l]
    return l_burger(l)
n, x = map(int, input().split())
cnt = 0
for i in burger(n)[:x]:
    if i == 'P':
        cnt += 1
        
print(cnt)
    
    

### FIXED CODE ###

N, X = map(int, input().split())
a = [1] * (N+1)
p = [1] * (N+1)
for i in range(1,N+1):
    a[i] = a[i-1]*2 + 3
    p[i] = p[i-1]*2 + 1
def f(n, x):
    if n == 0:
        return 1
    elif x == 1:
        return 0
    elif 2<= x <= a[n-1] + 1:
        return f(n-1, x-1)
    elif x == a[n-1] + 2:
        return p[n-1] + 1
    elif a[n-1]+3 <= x <= 2*a[n-1]+2:
        return p[n-1]+1+ f(n-1, x-(a[n-1]+2))
    elif x == 2*a[n-1]+3:
        return p[n]
print(f(N,X))
import collections

blue = int(input())
blue_string = [input() for i in range(blue)]
blue_type = set(blue_string)
red = int(input())
red_string = [input() for i in range(red)]
red_type = set(red_string)
blue_number = len(blue_type)
result = [0]

for i in range(blue_number):
    blue_sort = blue_type[i]
    bulue_sort_count = blue_string.count(blue_sort)
    red_sort_count = red_string.count(blue_sort)
    result.append(bulue_sort_count - red_sort_count )
print(max(result))


### FIXED CODE ###

import collections

blue = int(input())
blue_string = [input() for i in range(blue)]
blue_type = set(blue_string)
red = int(input())
red_string = [input() for i in range(red)]
red_type = set(red_string)
result = [0]

for i in blue_type:
    bulue_sort_count = blue_string.count(i)
    red_sort_count = red_string.count(i)
    result.append(bulue_sort_count - red_sort_count )
print(max(result))
#include <bits/stdc++.h>
#define INF 100000007
#define rep(i, N) for(ll i = 0; i < N; i++)
#define rep2(i, j, k) for(ll i = j; i < k; i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = inx(x, y)
#define print(x) cout << x << "\n"
#define printv(vec) rep(i, vec.size()) cout << vec[i] << " "; print("");
#define ALL(v) v.begin(), v.end()
#define SUM(v) accumulate(ALL(v), 0)
#define MAX(v) *max_element(ALL(v))
#define MIN(v) *min_element(ALL(v))
#define SORT(v) sort(ALL(v))
#define REV(v) reverse(ALL(v))
typedef long long ll;
using namespace std;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vs = vector<string>;
using vvs = vector<vector<string>>;

/*
ダブリング
10**100のビットがたっているか否かってC++でわかる?
*/

void solve(){
	
	string S;
	cin >> S;
	ll length = S.size();
	vvl v(60, vl(length));
	vl ans(length);
	rep(i, length){
		if(S[i] == 'R') v[0][i] = i + 1;
		else v[0][i] = i - 1;
	}
	rep(i, 59) rep(j, length) v[i + 1][j] = v[i][v[i][j]];
	rep(i, length) ans[v[59][i]] += 1;
	printv(ans);
	
}	

int main(){
	
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	solve();
    
	return 0;
	
}

### FIXED CODE ###

import math
from itertools import groupby

def rlE(S: str):
    grouped = groupby(S)
    res = []
    for k, v in grouped:
        res.append((k, (len(list(v)))))
    return res

S = input()
ans = [0 for _ in range(len(S))]
cnt = 0
rS = rlE(S)
rS.append(["", 0])
temp = rS[0][1] - 1

while(cnt < len(rS) - 1):
    ans[temp] = math.ceil(rS[cnt][1] / 2) + rS[cnt + 1][1] - math.ceil(rS[cnt + 1][1] / 2)
    ans[temp + 1] = math.ceil(rS[cnt + 1][1] / 2) + rS[cnt][1] - math.ceil(rS[cnt][1] / 2)
    temp += (rS[cnt + 1][1] + rS[cnt + 2][1])
    cnt += 2
print(*ans)
import math

x1,y1 = 0, 0

def fact(n):
    b = 2
    fct = []
    while b * b <= n:
        while n % b == 0:
            n //= b
            fct.append(b)
        b = b + 1
    if n > 1:
        fct.append(n)
    return fct

S = int(input())

list1 = sorted(fact(S))#おおきいのが最後

if int(list1[-1]) <= 10**9:
  b = int(list1[-1])
  x2,y2 = b,0
  x3,y3 = 0,S//b

else:
  list2 = []
  list2.append(int(S//list1[-1]))
  while list1[-1] > 10**9:
    dash = list1[-1]
    list1 = fact(dash + 1)
    list2.append(int((dash+1)//list1[-1]))

  sum2 = 0
  sum4 = 1
  for i in range(len(list2)-1):
    sum4 *= list2[i] 
    sum2 += sum4

  y2 = fact(sum2)[-1]
    
  b = list1[-1]
  x2 = b
  x3 = sum2//y2
  y3 = (S + x3*y2)//b
  s = x2*y3 - x3*y2
  
print(int(x1),int(y1),int(x2),int(y2),int(x3),int(y3))

### FIXED CODE ###

S = int(input())

if S == 10**18:
  x1,y1 = 0,0
  x2 = 10**9
  y3 = 10**9
  x3 = 0
  y2 = 0

else:
  x1, y1 = 0,0

#|x2y3-x3y2|=S

  x2 = 10**9
  y2 = 1

#|10**9y3-x3|= s

  y3 = (S//(10**9)) + 1
  x3 = (10**9)*y3 - S

print(int(x1),int(y1),int(x2),int(y2),int(x3),int(y3))
N = int(input())
A = [int(n) for n in input().split()]

def gcd(a,b):
    while b>0:
        a, b = b, a%b 
    return a

temp_gcm = gcm(A[0],A[1])
 for i in range(2,N):
     temp_gcm = gcm(A[i],temp_gcm)
print(temp_gcm)


### FIXED CODE ###

N = int(input())
A = [int(n) for n in input().split()]

def gcd(a,b):
    while b>0:
        a, b = b, a%b 
    return a

temp_gcd = gcd(A[0],A[1])
for i in range(2,N):
     temp_gcd = gcd(A[i],temp_gcd)
print(temp_gcd)
a = [str(item) for item in input().split()]
seki = a[0] * a[1]

if seki / 2 == 0:
    print('Even')
else:
    print('Odd')

### FIXED CODE ###

a = [int(item) for item in input().split()]
seki = a[0] * a[1]
if seki % 2 == 0:
    print('Even')
else:
    print('Odd')
s = list(input())
t = list(input())

s.sort()
s=''.join(s)

s.sort()
t.reverse()
t=''.join(t)

if s < t:
    print('Yes')
else:
    print('No')

### FIXED CODE ###

s = list(input())
t = list(input())

s.sort()
s=''.join(s)

t.sort()
t.reverse()
t=''.join(t)

if s < t:
    print('Yes')
else:
    print('No')
N = int(input())
print(N * (N - 1)//2)

### FIXED CODE ###

def p_a():
    S = input()
    T = input()

    ans = 0

    for s,t in zip(list(S), list(T)):
        if s == t:
            ans += 1

    print(ans)


if __name__ == '__main__':
    p_a()
N, M = map(int, input().split())
s1 = set()
s2 = set()

for _ in range(M):
    a, b = map(int, input().split())
    if a == 1:
        s1.append(b)
    if b == N:
        s2.append(a)

for x in s1:
    if s2.count(x) >= 1:
        print("POSSIBLE")
        exit()

print("IMPOSSIBLE")


### FIXED CODE ###

N, M = map(int, input().split())
s1 = set()
s2 = set()

for _ in range(M):
    a, b = map(int, input().split())
    if a == 1:
        s1.add(b)
    if b == N:
        s2.add(a)

if len(s1.intersection(s2)) > 0:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")
r = int(input())
print(n*n)

### FIXED CODE ###

n = int(input())
print(n*n)
a = int(input())
s = input()

if a => 3200:
    print(s)

elif:
    print("red")


### FIXED CODE ###

a = int(input())
s = input()

if a >= 3200:
    print(s)

else:
    print("red")
x,a,b = map(int, input().spilit())
if(a>=b):
  print("delicious")
else:
  if(b-a >x):
    print("dangerous")
  else:
    print("safe")

### FIXED CODE ###

x,a,b = map(int, input().split())
if(a>=b):
  print("delicious")
else:
  if(b-a >x):
    print("dangerous")
  else:
    print("safe")
a,b,c,d=map(int, input().split())
print(min(a,b)+min(c,d))

### FIXED CODE ###

a=int(input())
b=int(input())
c=int(input())
d=int(input())
print(min(a,b)+min(c,d))
import math
n, d = map(int, input().split())
print(math.ceil)(n/(2*d+1))

### FIXED CODE ###

import math
n, d = map(int, input().split())
print(math.ceil(n/(2*d+1)))
a, b = map(int, input().split())
import math
p = math.gcd(a, b)
print(b * (a // p))


### FIXED CODE ###

from fractions import gcd
a, b = map(int, input().split())
p = gcd(a, b)
print(b * (a // p))
def main():
    nvertices, nedges = map(int, input().split())
    Adj = [[] for i in range(nvertices)]
    Adjrev = [[] for i in range(nvertices)]
    for i in range(nedges):
        s, t = map(int, input().split())
        Adj[s].append(t)
        Adjrev[t].append(s)

    component_ids = [-1] * nvertices
    id = 0
    for u in range(nvertices):
        if component_ids[u] != -1:
            continue
        s1 = set()
        s2 = set()
        visited1 = [0] * nvertices
        visited2 = [0] * nvertices
        dfs(u, Adj, visited1, s1)
        dfs(u, Adjrev, visited2, s2)
        for v in s1 & s2:
            component_ids[v] = id
        id += 1

    Q = int(input())
    for i in range(Q):
        s, t = map(int, input().split())
        if component_ids[s] == component_ids[t]:
            print(1)
        else:
            print(0)


def dfs(u, Adj, visited, s):
    visited[u] = 1
    s.add(u)
    for v in Adj[u]:
        if visited[v]:
            continue
        dfs(v, Adj, visited, s)
    return s


main()

### FIXED CODE ###

import sys

def main():
    sys.setrecursionlimit(int(1e5))
    nvertices, nedges = map(int, input().split())
    Adj = [[] for i in range(nvertices)]
    AdjRev = [[] for i in range(nvertices)]
    for i in range(nedges):
        u, v = map(int, input().split())
        Adj[u].append(v)
        AdjRev[v].append(u)

    lst = []
    visited = [False] * nvertices
    for u in range(nvertices):
        if not visited[u]:
            dfs_first(u, Adj, visited, lst)

    lst.reverse()
    ids = [-1] * nvertices
    visited = [False] * nvertices
    id = 0
    for u in lst:
        if not visited[u]:
            dfs_second(u, AdjRev, visited, id, ids)
            id += 1

    Q = int(input())
    for i in range(Q):
        u, v = map(int, input().split())
        print(1 if ids[u] == ids[v] else 0)


def dfs_first(u, Adj, visited, lst):
    visited[u] = True
    for v in Adj[u]:
        if not visited[v]:
            dfs_first(v, Adj, visited, lst)
    lst.append(u)


def dfs_second(u, Adj, visited, id, ids):
    ids[u] = id
    visited[u] = True
    for v in Adj[u]:
        if not visited[v]:
            dfs_second(v, Adj, visited, id, ids)

main()
N,M = map(int,input().split())
XY = [[] for i in range(N)]
for l in range(M):
    x,y = map(int,input().split())
    XY[x-1].append(y-1)

dp = [-1 for k in range(N)]
def search(i):
    if dp[i] != -1:
        return dp[i]
    c = 0
    start = XY[i]
    for s in start:
        c = max(c,search(s)+1)
    dp[i] = c
    return dp[i]

a = 0
for i in range(N):
    a = max(a,search(i))
print(a)


### FIXED CODE ###

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

N,M = map(int,input().split())
XY = [[] for m in range(N)]
for l in range(M):
    x,y = map(int,input().split())
    XY[x-1].append(y-1)

dp = [-1 for k in range(N)]
def search(i):
    if dp[i] != -1:
        return dp[i]
    c = 0
    start = XY[i]
    for s in start:
        c = max(c,search(s)+1)
    dp[i] = c
    return dp[i]

a = 0
for i in range(N):
    a = max(a,search(i))
print(a)
N,M = map(int,input().split())
Adj_list = [[] for _ in range(N) ]

for i in range(M):
    a, b, c = map(int, input().split())
    Adj_list[a-1].add((b-1, c))
    Adj_list[b-1].add((a-1, -c))
visited =[None]*(N)
ok = True
stack = []
for x in range(N):
   if visited[x] is not None:continue
   visited[x] = 0
   stack = [x]
   while stack:
       v = stack.pop()
       for to,d in Adj_list[v]:
           if visited[to] is None:
               visited[to] = G[v] + d
               stack.append(to)
           else:
               if G[to] != G[v]+d:
                   ok = False
                   break
   if ok == False:
        break
print("Yes" if ok else "No")

### FIXED CODE ###

import itertools
import math
from collections import deque
from collections import defaultdict
from itertools import permutations
import heapq
import bisect
from scipy.sparse.csgraph import floyd_warshall as wf
INF = float("inf")


N,M = map(int,input().split())
Adj_list = defaultdict(set)

for i in range(M):
    a, b, c = map(int, input().split())
    Adj_list[a-1].add((b-1, c))
    Adj_list[b-1].add((a-1, -c))
visited =[None]*(N)
ok = True
stack = []
for x in range(N):
   if visited[x] is not None:continue
   visited[x] = 0
   stack = [x]
   while stack:
       v = stack.pop()
       for to,d in Adj_list[v]:
           if visited[to] is None:
               visited[to] = visited[v] + d
               stack.append(to)
           else:
               if visited[to] != visited[v]+d:
                   ok = False
                   break
   if ok == False:
        break
print("Yes" if ok else "No")
import math

a,b = map(int,input().split())
c = math.gcd(a,b)

ans = 0
i = 2
while c != 1:
    while c % i == 0:
        c = c // i
    #print(c,i,ans)
    i = i + 1
    ans += 1
    
print(ans)

### FIXED CODE ###

from fractions import gcd

a,b = map(int,input().split())
c = gcd(a,b)

ans = 0
i = 2
check = False
while c != 1:
    #print(c,i)
    while c % i == 0:
        #print('a')
        c = c // i
        check = True
    i = i + 1
    if check:
        ans += 1
    check = False
    if i > 1000000:
        print(ans+2)
        exit()
print(ans + 1)
s = input()
s_set = set(s)
f = True
for i in s_set:
  if s.count(i) >= 2:
    f = False
  	break
if f:
  print("Yes")
else:
  print("No")

### FIXED CODE ###

s = input()
s_set = set(s)
f = True
for i in s_set:
  if s.count(i) >= 2:
      f = False
      break
if f:
  print("yes")
else:
  print("no")
K = int(input())
A,B = map(int,input().split())
n = 1
while True:
    if A <= K*n and K*n <= B:
        print('OK')
        break
    elif Kn > B:
        print('NG')
        break
    n = n + 1 

### FIXED CODE ###

K = int(input())
A,B = map(int,input().split())
n = 1
while True:
    if A <= K*n and K*n <= B:
        print('OK')
        break
    elif K*n > B:
        print('NG')
        break
    n = n + 1
A, B = map(long, raw_input().split())
ans = 0
msb = B >> (B.bit_length()-1) << (B.bit_length() - 1)
if msb + A > B:
    begin = B
    end = A
else:
    begin = B
    end = msb + A
for i in range(begin, end - 1, -1):
    ans ^= i
if A%2 ^ B%2:
    ans += msb
print(ans)


### FIXED CODE ###

A, B = map(int, input().split())
ans = 0
cnt = 0
def f(arg):
    ans = 0
    if arg < 0:
        return 0
    for pos in range(1, 41):
        # ループする数
        loop = 1 << pos
        # cnt = sum([int((n & v) / v) for n in range(arg+1)])
        cnt = int((arg + 1) / loop) * (loop >> 1)
        cnt += max(0, (arg + 1) % (loop) - (loop >> 1))
        ans += cnt%2 * (loop>>1)
        # print(arg, pos, loop, cnt, ans)
        if loop > arg:
            break
    return ans
print(f(A-1)^f(B))
N,A,B = map(int,input().split())
print(min(N*A,B)

### FIXED CODE ###

N,A,B = map(int,input().split())
print(min(N*A,B))
import math
n = int(input())
K = int(input())

def calk1(n):
    m = int(math.log10(n))
    num = m * 9
    num += n//(10**m)
    return num

def calk2(n):
    m = int(math.log10(n))
    num = m * (m - 1) // 2 * 9**2
    num += (n//(10**m)-1) * m * 9
    num += calk1(n - (n//(10**m)*10**m))
    return num

def calk3(n):
    m = int(math.log10(n))
    num = m * (m - 1) * (m - 2) // 6 * 9**3
    num += (n//(10**m)-1) * (m * (m - 1) // 2 * 9**2)
    num += calk2(n - (n//(10**m)*10**m))
    return num
    
if K == 1: print(calk1(n))
elif K == 2: print(calk2(n))
else: print(calk3(n))

### FIXED CODE ###

import math
n = int(input())
K = int(input())

def calk1(n):
    if n == 0: return 0
    m = int(math.log10(n))
    num = m * 9
    num += n//(10**m)
    return num

def calk2(n):
    m = int(math.log10(n))
    num = m * (m - 1) // 2 * 9**2
    num += (n//(10**m)-1) * m * 9
    num += calk1(n - (n//(10**m)*10**m))
    return num

def calk3(n):
    m = int(math.log10(n))
    num = m * (m - 1) * (m - 2) // 6 * 9**3
    num += (n//(10**m)-1) * (m * (m - 1) // 2 * 9**2)
    num += calk2(n - (n//(10**m)*10**m))
    return num
if n < 10 ** (K - 1): print(0)
else:
    if K == 1: print(calk1(n))
    elif K == 2: print(calk2(n))
    else: print(calk3(n))
s = input()
sr = s[::-1]

ans = 0

for i in range(s//2):
  if s[i] != sr[i]:
    ans += 1
    
print(ans)

### FIXED CODE ###

s = input()
sr = s[::-1]

ans = 0

for i in range(len(s)//2):
  if s[i] != sr[i]:
    ans += 1
    
print(ans)
N = input()
M = N[1:]
O = int(M)
if O == 0:
    print(0)
else:
    print(1000-O)

### FIXED CODE ###

N = int(input())
if N >= 1000:
    M = str(N)
    X = M[1:]
    O = int(X)
    if O == 0:
        print(0)
    else:
        print(1000-O)
else:
    O = int(N)
    print(1000-O)
# -*- coding: utf-8 -*-
# スペース区切りの整数の入力
N, K = map(int, input().split())
# 文字列用のリスト　インプットをブランクで区切りリスト化
k = input()
s = [int(j) for j in k.split(" ")]
valIn = 0
# Nの桁毎の分解
def digit(i):
    if i > 0:
        return digit(i//10) + [i%10]
    else:
        return []

def irohacheck(n):
	global valIn
	valIn = 0
	# 分解した数値をリストにして格納
	num = digit(n)
	# num内の数字がsに含まれる場合には、valInをインクリメント
	for i in range(len(num)):
		if s.count(num[i])>0:
			valIn+=1

irohacheck(N)
while(valIn != 0):
	N += 1
	irohacheck(N)
print(N)

### FIXED CODE ###

# A - 和風いろはちゃんイージー / Iroha and Haiku (ABC Edition)
# https://atcoder.jp/contests/abc042/tasks/abc042_a

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

for i in [5,7,5]:
    if i in nums:
        nums.remove(i)
    else:
        print("NO")
        exit()

if len(nums) == 0:
    print("YES")
else:
    print("NO")
a,b,k=map(int,input().split())
l = range(a, b + 1) if b - a + 1 <= k else sorted(set(range(a, a + k)) | set(range(b - k + 1, b + 1))):
for i in l: 
  print(i)

### FIXED CODE ###

a,b,k=map(int,input().split())
l = range(a, b + 1) if b - a + 1 <= k else sorted(set(range(a, a + k)) | set(range(b - k + 1, b + 1)))
for i in l: 
  print(i)
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))

N = INT()
P = LIST()
Q = LIST()

import itertools

for i, l in enumerate(itertools.permutations(range(1, N+1), N)):
    if list(l) == P:
        a = i+1
    elif list(l) == Q:
        b = i+1

print(abs(a-b))

### FIXED CODE ###

def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))

N = INT()
P = LIST()
Q = LIST()

import itertools

for i, l in enumerate(itertools.permutations(range(1, N+1), N)):
    if list(l) == P:
        a = i+1
    if list(l) == Q:
        b = i+1

print(abs(a-b))