Harryxun/stf_run huggingface dataset:
import itertools
import math
n = input()

chars = ["3", "5", "7"]
ndigits = int(math.log10(n)) + 1

count = 0
for digit in range(3, ndigits + 1):
    for string in itertools.product(chars, repeat=digit):
        if(string.count("3") == 0):
            continue
        if(string.count("5") == 0):
            continue
        if(string.count("7") == 0):
            continue
        if n >= int("".join(string)):
            count += 1

print(count)


### FIXED CODE ###

import itertools
import math
n = input()

chars = ["3", "5", "7"]
ndigits = int(math.log10(n)) + 1

count = 0
for digit in range(3, ndigits + 1):
    for string in itertools.product(chars, repeat=digit):
        if(string.count("3") == 0):
            continue
        if(string.count("5") == 0):
            continue
        if(string.count("7") == 0):
            continue
        if n >= int("".join(string)):
            count += 1

print(count)
k = int(input())
ans = 0
now = 7
while True:
    ans += 1
    now %= k
    if now == 0:
        print(ans)
        exit(-1)
    now = now * 10 + 7
    if ans == 1000000:
        print(-1)
        exit(-1)

### FIXED CODE ###

k = int(input())
ans = 0
now = 7
while True:
    ans += 1
    now %= k
    if now == 0:
        print(ans)
        exit()
    now = now * 10 + 7
    if ans == 1000000:
        print(-1)
        exit()
import sys
from functools import lru_cache
N, M = map(int, input().split())
ok = [True] * (N + 1)
for _ in range(M):
    a = int(sys.stdin.readline())
    ok[a] = False
sys.setrecursionlimit(N + 10000)
@lru_cache(maxsize=None)
def f(s):
    if not ok[s]:
        return 0
    if s in (0, 1, 2):
        return s
    count = f(s - 1) + f(s - 2)
    count %= 1000000007
    return count

ans = f(N)
print(ans)

### FIXED CODE ###

import sys
N, M = map(int, input().split())
ok = [True] * (N + 1)
for _ in range(M):
    a = int(sys.stdin.readline())
    ok[a] = False
ans = 0
if N == 1:
    ans = 1
else:
    counts = [0] * (N + 1)
    if ok[1]:
        counts[1] = 1
    if ok[2]:
        counts[2] = counts[1] + 1
    for s in range(3, N + 1):
        if ok[s]:
            count = counts[s-1] + counts[s-2]
            count %= 1000000007
            counts[s] = count
    ans = counts[N]
print(ans)
a,b=input().split()
print( min (a*(int(b), b*(int(a) ) ) 


### FIXED CODE ###

a, b = input().split()
 
print(min(a*int(b), b*int(a) ) )
import math

def lcm (x, y):
    return (x * y) // math.gcd(x, y)

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

print (lcm(a,b))

### FIXED CODE ###

from fractions import gcd

def lcm (x, y):
    return (x * y) // gcd(x, y)

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

print (lcm(a,b))
li ~ list(map(int,input().split()))
cnt = 3
if li[0] == li[1]:
	cnt -= 1
if li[0] == li[2]:
	cnt -= 1
if li[1] == li[2]:
	cnt -= 1
if li[0] == li[1] and li[1] == li[2]:
	cnt = 1
print(cnt)

### FIXED CODE ###

li = list(map(int,input().split()))
cnt = 3
if li[0] == li[1]:
	cnt -= 1
if li[0] == li[2]:
	cnt -= 1
if li[1] == li[2]:
	cnt -= 1
if li[0] == li[1] and li[1] == li[2]:
	cnt = 1
print(cnt)
count = int(input())
for i in range(count):
    x = list(map(float ,input().split()))
    x1=x[2]-x[0]
    y1=x[3]-x[1]
    x2=x[6]-x[4]
    y2=x[7]-x[5]
    if x1==0:
        if x2==0:
            print("YES")
        else:
            print("NO")
    else:
        if y1/x1==y2/x2:
            print("YES")
        else:
            print("NO")

### FIXED CODE ###

count = int(input())
for i in range(count):
    x = list(map(float ,input().split()))
    x1=x[2]-x[0]
    y1=x[3]-x[1]
    x2=x[6]-x[4]
    y2=x[7]-x[5]
    if abs(x1*y2-x2*y1)<=1e-10:
        print("YES")
    else:
        print("NO")
N, M = int(input())
print("Yes") if N==M else print("No")

### FIXED CODE ###

N, M = map(int, input().split())
if N==M:
    print("Yes")
else:
    print("No")
from math import gcd
a,b,c,d=map(int,input().split())
ans=(b-a+1)
lcm=(c*d)//gcd(c,d)
dba=(a//c-int(a%c==0))+(a//d-int(a%d==0))-(a//lcm-int(a%lcm==0))
dbb=(b//c)+(b//d)-(b//lcm)
dbb-=dba
ans-=dbb
print(ans)
        
        

### FIXED CODE ###

from fractions import gcd
a,b,c,d=map(int,input().split())
ans=(b-a+1)
lcm=(c*d)//gcd(c,d)
dba=(a//c-int(a%c==0))+(a//d-int(a%d==0))-(a//lcm-int(a%lcm==0))
dbb=(b//c)+(b//d)-(b//lcm)
dbb-=dba
ans-=dbb
print(ans)
n, q = [int(i) for i in input().split() ]
s = input() #文字列
lr = list([])
for i in range(q):
    lr.append([int(i) for i in input().split() ])

ll = list([])
for i, c in enumerate(s):
    if((c == "A") and (s[i+1] =="C")):
        ll.append(i+1)

for i in range(q):
    ans = 0
    for m in ll:
        if (m >= lr[i][0]) and (m+1 <=lr[i][1]):
            ans += 1
        elif m >= lr[i][1]:
            break
    print(ans)

### FIXED CODE ###

n, q = [int(i) for i in input().split() ]
s = input() #文字列
lr = list([])
count = [0 for i in range(n)]
for i in range(q):
    lr.append([int(i) for i in input().split() ])

ll = list([])
now = 0
for i, c in enumerate(s):
    if((c == "C") and (i>0) and (s[i-1] =="A")):
        now += 1
    count[i] = now

for i in range(q):
    ans = 0
    print(count[lr[i][1]-1] - count[lr[i][0]-1])
from __future__ import division
import math

def cross(p1,p2):
    a,b,c,d=p1[0],p1[1],p2[0],p2[1]
    t=pow(a,2)+pow(c,2)+pow(d,2)-pow(b,2)-2*a*c
    alpha=4*(pow(b-d,2)+pow(c-a,2))
    beta=4*(t*(b-d)-2*b*pow(c-a,2))
    gamma=pow(t,2)+4*pow(b,2)*pow(c-a,2)-4*pow(c-a,2)
    judge=pow(beta,2)-4*alpha*gamma
    if c-a==0 or alpha==0:
        return -100,-100
    if judge>0:
        y1=(-beta+math.sqrt(judge))/(2*alpha)
        y2=(-beta-math.sqrt(judge))/(2*alpha)
        x1=(2*(b-d)*y1+pow(c,2)+pow(d,2)-pow(a,2)-pow(b,2))/(2*(c-a))
        x2=(2*(b-d)*y2+pow(c,2)+pow(d,2)-pow(a,2)-pow(b,2))/(2*(c-a))
        return ((x1,y1),(x2,y2))
    elif judge==0:
        y=-beta/(2*alpha)
        x=(2*(b-d)*y+pow(c,2)+pow(d,2)-pow(a,2)-pow(b,2))/(2*(c-a))
        return x,y
    else:
        return -100,-100

def maxNum(P,L):
    ans=1
    for x,y in P:
        cnt=0
        for px,py in L:
            d=math.sqrt(pow(px-x,2)+pow(py-y,2))
            if d<=1:
                cnt+=1
        ans=max(ans,cnt)
    return ans

while True:
    n=input()
    if n==0:break
    L=[map(float,raw_input().split(",")) for i in range(n)]
    P=[]
    for i in range(n-1):
        for j in range(i+1,n):
            points=cross(L[i],L[j])
            if points!=(-100,-100):
                P.extend(points)
    print maxNum(P,L)

### FIXED CODE ###

from __future__ import division
import math

def cross(p1,p2):
    a,b,c,d=p1[0],p1[1],p2[0],p2[1]
    t=pow(a,2)+pow(c,2)+pow(d,2)-pow(b,2)-2*a*c
    alpha=4*(pow(b-d,2)+pow(c-a,2))
    beta=4*(t*(b-d)-2*b*pow(c-a,2))
    gamma=pow(t,2)+4*pow(b,2)*pow(c-a,2)-4*pow(c-a,2)
    judge=pow(beta,2)-4*alpha*gamma
    EPS=1e-5
    if c==a:
        y=(pow(a,2)+pow(b,2)-pow(c,2)-pow(d,2))/(2*(b-d))
        bd=pow(b-d,2)
        a1=4*bd
        b1=-8*a*bd
        c1=4*a*a*bd+pow(a*a-b*b-c*c-d*d+2*b*d,2)-4*bd
        inroot=pow(b1,2)-4*a1*c1
        if inroot<0:
            return None
        x1=(-b1+math.sqrt(inroot))/(2*a1)
        x2=(-b1-math.sqrt(inroot))/(2*a1)
        return ((x1,y),(x2,y))

    if judge>EPS:
        y1=(-beta+math.sqrt(judge))/(2*alpha)
        y2=(-beta-math.sqrt(judge))/(2*alpha)
        x1=(2*(b-d)*y1+pow(c,2)+pow(d,2)-pow(a,2)-pow(b,2))/(2*(c-a))
        x2=(2*(b-d)*y2+pow(c,2)+pow(d,2)-pow(a,2)-pow(b,2))/(2*(c-a))
        return ((x1,y1),(x2,y2))
    elif -EPS<=judge<=EPS:
        y=-beta/(2*alpha)
        x=(2*(b-d)*y+pow(c,2)+pow(d,2)-pow(a,2)-pow(b,2))/(2*(c-a))
        return ((x,y),)
    else:
        return None

def maxNum(P,L):
    ans=1
    for x,y in P:
        cnt=0
        for px,py in L:
            d=math.sqrt(pow(px-x,2)+pow(py-y,2))
            if d<=1:
                cnt+=1
        ans=max(ans,cnt)
    return ans

while True:
    n=input()
    if n==0:break
    L=[map(float,raw_input().split(",")) for i in range(n)]
    P=[]
    for i in range(n-1):
        for j in range(i+1,n):
            points=cross(L[i],L[j])
            if points:
                P.extend(points)
    print maxNum(P,L)
x,y = map(int,input().split())
ans = abs(abs(x)-abs(y))
print(ans if X * y > 0 else ans + 1)

### FIXED CODE ###

x,y = map(int,input().split())
if abs(x) == abs(y):
  print(0 if x == y else 1)
elif x < y:
  print(min(y - x,abs(y + x) + 1))
else:
  print(min(abs(y+x),abs(y-x))+ 1 if x * y <= 0 else min(abs(y+x),abs(y-x))+ 2)
n = int(input())
a = list(map(int, input().split()))

a = list(set(a))
a = sorted(a, reverse=True)
ans = 0
count = 0

if len(a) != 1:
    for x in range(0, n-1):
        for y in range(x+1, n):
            if a[x] % a[y] == 0:
                break
            else:
                count += 1

        if count == n - x-1:
            ans += 1
        count = 0
    print(ans + 1)
else:
    print(0)


### FIXED CODE ###

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

M = 10**6+5

count = [0]*M

for x in range(n):
    if count[a[x]] != 0:
        count[a[x]] = 2
        continue

    for i in range(a[x], M, a[x]):
        count[i] += 1

ans = 0
for x in range(n):
    if count[a[x]] == 1:
        ans += 1

print(ans)
def calc(S, T):
    U = [(S[0], 1)]
    un = 0
    for i in range(1, len(S)):
        if U[un][0] == S[i]:
            U[un] = (U[un][0], U[un][1] + 1)
        else:
            U += [(S[i], 1)]
            un += 1
    U = [u for u in U if u[1] > 1]
    un = len(U) - 1
    if un == 0:
        return (U[0][1] * T) // 2
    else:
        if U[0][0] != U[un][0]:
            return sum([u[1] // 2 for u in U]) * T
        else:
            return U[0][1] // 2 + U[un][1] // 2 \
                + (U[0][1] + U[un][1]) // 2 * (T - 1) \
                + sum([u[1] // 2 for u in U[1:un]]) * T


S = input()
T = int(input())
print(calc(S, T))

### FIXED CODE ###

def calc(S, T):
    U = [(S[0], 1)]
    un = 0
    for i in range(1, len(S)):
        if U[un][0] == S[i]:
            U[un] = (U[un][0], U[un][1] + 1)
        else:
            U += [(S[i], 1)]
            un += 1
    if un == 0:
        return (U[0][1] * T) // 2
    else:
        if U[0][0] != U[un][0]:
            return sum([u[1] // 2 for u in U]) * T
        else:
            return U[0][1] // 2 + U[un][1] // 2 \
                + (U[0][1] + U[un][1]) // 2 * (T - 1) \
                + sum([u[1] // 2 for u in U[1:un]]) * T


S = input()
T = int(input())
print(calc(S, T))
a,b,c=map(int,input().sploit())

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


### FIXED CODE ###

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

print('YES' if b-a==c-b else 'NO')
import numpy as np
def f(b, n):
    if n < b:
        return n
    else:
        n2 = n // b
        if n2 == n:
            return -1
        else:
            return f(b, n2) + (n % b)

def solve(n, s):
    if s == n:
        return n + 1
    m = int(np.sqrt(n)) + 1
    for b in range(2, m):
        if f(b, n) == s:
            return b
    for p in range(1, m):
        q = s - p
        if (n - q) % p != 0:
            continue
        b = (n - q) // p
        if f(b, n) == s:
            return b
    return -1

n = int(input())
s = int(input())
print(solve(n, s))

### FIXED CODE ###

import numpy as np
def f(b, n):
    s = 0
    while n > 0:
        s += n % b
        n //= b
    return s

INF = 10**15
def solve(n, s):
    if n == s:
        return n+1
    m = int(np.sqrt(n)) + 1
    for b in range(2, m+1):
        if f(b, n) == s:
            return b
    best = INF
    for p in range(1, m+10):
        q = s - p
        b = (n - q) // p
        if (b > p) and (b > q) and (f(b, n) == s):
            best = min(best, b)
    return -1 if (best == INF) else best

n = int(input())
s = int(input())
print(solve(n, s))
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))
w,h,x,y = map(int,input().split())
if w/x == 2 and h/y == 2:
  print(w*h/2,1)
else:
  print(w*h/2,0)

### FIXED CODE ###

w,h,x,y = map(int,input().split())
if w == 2*x and h == 2*y:
  print(w*h/2,1)
else:
  print(w*h/2,0)
# 文字列の入力
O = char(input())
E = char(input())

L = len(O)
TMP = ""

for i in range(L):
    TMP = TMP+O[i]+E[i]

print(TMP)

### FIXED CODE ###

# 文字列の入力
O = input()
E = input() + " "

L = len(O)
TMP = ""

for i in range(L):
    TMP = TMP+O[i]+E[i]

print(TMP.strip())
n = int(input())
s = input()
x=before=0

for i in s:
  if i == "I":
    x += 1
    if before < x:
      before = x
  else:
    x -= 1
print(berofe)

### FIXED CODE ###

n = int(input())
s = input()
x=before=0

for i in s:
  if i == "I":
    x += 1
    if before < x:
      before = x
  else:
    x -= 1
print(before)
print str(i) + 'x' + str(j) + '=' + str(i * j) for j in range(1,10) for i in range(1,10)

### FIXED CODE ###

for i in range(1,10):
	for j in range(1,10):
		print str(i) + 'x' + str(j) + '=' + str(i * j)
s = input()

if s == 'Sunny':
  pirnt('Cloudy')
elif s == 'Cloudy':
  pirnt('Rainy')
else:
  print('Sunny')

### FIXED CODE ###

s = input()
 
if s == 'Sunny':
  print('Cloudy')
elif s == 'Cloudy':
  print('Rainy')
else:
  print('Sunny')
n,k=map(int,input().split())
a = list(map(int,input().split()))
minus = [0]+[abs(a[i]) for i in range(n) if a[i] < 0][::-1]

plus = [0]+[a[i] for i in range(n) if a[i] >= 0]

min_ = 10**18

if len(plus) == 1:
  print(minus[k])
elif len(minus) == 1:
  print(plus[k])
elif len(plus) < len(minus):
  for i in range(min(k+1, len(plus))):
    min_ = min(min_, 2*plus[i]+minus[k-i], plus[i]+2*minus[k-i])
  print(min_)
else:
  for i in range(min(k+1, len(minus))):
    min_ = min(min_, 2*minus[i]+plus[k-i], minus[i]+2*plus[k-i])
  print(min_)  
  


### FIXED CODE ###

n,k=map(int,input().split())
a = list(map(int,input().split()))
minus = [0]+[abs(a[i]) for i in range(n) if a[i] < 0][::-1]

plus = [0]+[a[i] for i in range(n) if a[i] >= 0]

min_ = 10**18

if len(plus) == 1:
  print(minus[k])
elif len(minus) == 1:
  print(plus[k])
else:
  for i in range(min(k+1, len(plus))):
    if k-i < len(minus):
      min_ = min(min_, 2*plus[i]+minus[k-i], plus[i]+2*minus[k-i])
  print(min_)
import itertools
N,S = map(int,input().split( ))
A = list(map(int,input().split( )))
a = [i for i in range(N)]
C = []
for i in range(1,N+1):
    C += list(itertools.combinations(a,i))
ans = 0
for c in C:
    wa = 0
    for i in c:
        wa += A[i]
    if wa == S:
        for cc in C:
            if set(c) <= set(cc):
                ans += 1
print(ans)

### FIXED CODE ###

A,B = map(int,input().split( ))
print(A*B)
n = int(input())
ls = list(map(int,input().split()))
A = 0
B = 0
lsn = sorted(ls,reverse = True)
if n%2 == 1:
  lsn = lsn.append(0)
for i in range(0,len(lsn),2):
  A += lsn[i]
  B += lsn[i+1]
print(A-B)

### FIXED CODE ###

n = int(input())
ls = list(map(int,input().split()))
A = []
B = []
lsn = sorted(ls,reverse = True)

A = lsn[0::2]
B = lsn[1::2]
print(sum(A)-sum(B))
#include <bits/stdc++.h>
using namespace std;

typedef long long int64;

int64 a, b, c, ans = LLONG_MAX;

void calc(int64 a, int64 b, int64 c) {
	int64 r = a / 2;

	for(int64 i = max(1LL, r - 5); i <= min(r + 5, a - 1); i++) {
		int64 v1 = i * b * c;
		int64 v2 = (a - i) * b * c;
		ans = min(ans, llabs(v1 - v2));
	}
}

int main() {
	scanf("%lld%lld%lld", &a, &b, &c);

	calc(a, b, c);
	calc(a, c, b);
	calc(b, a, c);
	calc(b, c, a);
	calc(c, a, b);
	calc(c, b, a);

	printf("%lld\n", ans);
	return 0;
}

### FIXED CODE ###

from math import *

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

def calc(a, b, c):
	r = a // 2

	ans = a * b * c
	for i in range(max(1, r - 5), min(r + 5, a - 1) + 1):
		v1 = i * b * c
		v2 = (a - i) * b * c
		ans = min(ans, abs(v1 - v2))

	return ans

res = a * b * c

res = min(res, calc(a, b, c))
res = min(res, calc(a, c, b))
res = min(res, calc(b, a, c))
res = min(res, calc(b, c, a))
res = min(res, calc(c, a, b))
res = min(res, calc(c, b, a))

print(res)
import sys
H,W,M=map(int, input().split())
h=[]
w=[]
Hcount=[0 for _ in range(H)]
Wcount=[0 for _ in range(W)]
B=set()

for i in range(M):
    hi,wi=map(int, input().split())
    h.append(hi)
    w.append(wi)
    B.append((hi,wi))
    Hcount[hi-1]+=1
    Wcount[wi-1]+=1
h_max=[i for i, v in enumerate(Hcount) if v == max(Hcount)]
w_max=[i for i, v in enumerate(Wcount) if v == max(Wcount)]
#print(h_max,w_max)
for ii in range(len(h_max)):
    for jj in range(len(w_max)):
        if (h_max[ii]+1,w_max[jj]+1) not in B:
            print(max(Hcount)+max(Wcount))
            sys.exit()
print(max(Hcount)+max(Wcount)-1)

### FIXED CODE ###

import sys
 
input = sys.stdin.readline
 
 
def main():
    H, W, M = map(int, input().split())
    row = [0] * (H)
    col = [0] * (W)
    bomb = set()
    for _ in range(M):
        h, w = map(int, input().split())
        bomb.add((h, w))
        row[h-1] += 1
        col[w-1] += 1
    row_max = max(row)
    row_index_list = [i for i, v in enumerate(row) if v == row_max]
    col_max = max(col)
    col_index_list = [i for i, v in enumerate(col) if v == col_max]
    ans = row_max + col_max - 1
    c = False
    for x in row_index_list:
        for y in col_index_list:
            if not (x + 1, y + 1) in bomb:
                c = True
                break
        if c:
            break
    if c:
        ans += 1
    print(ans)
 
 
if __name__ == '__main__':
    main()
while 1:
  a, op, b = input(), raw_input(), (raw_input().split())
  if op == "+":
    print "%d" %(a + b)
  elif op == "-":
    print "%d" %(a - b)
  elif op == "*":
    print "%d" %(a * b)
  elif op == "/":
    print "%d" %(a / b)
  else:
    break
  

### FIXED CODE ###

while 1:
  s = raw_input().split()
  a, b =int(s[0]), int(s[2])
  op = s[1] 

  if op == "+":
    print "%d" %(a + b)
  elif op == "-":
    print "%d" %(a - b)
  elif op == "*":
    print "%d" %(a * b)
  elif op == "/":
    print "%d" %(a / b)
  else:
    break
while True:
    n, m = map(int, raw_input().split())

    if n == 0 and m == 0:
        break

    a = [int(raw_input()) for _ in range(n)]

    ans = -1

    for i in range(n-1):
        for j in range(i+1, n):
            if a[i] + a[j] <= m:
                ans = max(ans, a[i] + a[j])

    print "NONE" if ans == -1 else ans


### FIXED CODE ###

while True:
    n, m = map(int, raw_input().split())

    if n == 0 and m == 0:
        break

    a = map(int, raw_input().split())

    ans = -1

    for i in range(n-1):
        for j in range(i+1, n):
            if a[i] + a[j] <= m:
                ans = max(ans, a[i] + a[j])

    print "NONE" if ans == -1 else ans
N=int(input())
S=input()
S_=[]
T=['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z']

for j in range(len(S)):
    for i in range(len(T)):
        if S[j] == T[i]:
            S_.append(T[i+N])
            break

print(S_)

### FIXED CODE ###

N=int(input())
S=input()
S_=[]
T=['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z']

for j in range(len(S)):
    for i in range(len(T)):
        if S[j] == T[i]:
            if i+N>=len(T):
                S_.append(T[i+N-len(T)])
            else:
                S_.append(T[i+N])
            break

y=""
for x in S_:
    y+=x

print(y)
n=int(input())

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

ans= 0

for i in range(1,n-1):
    lis= sorted([li[i],li[i-1],li[i+1]])
    #print(lis)
    if lis[1]==li[i]:
        ans +=1
print(ans)

### FIXED CODE ###

s = input()
if len(set(s))==2 and s.count(s[0])==2:
  print("Yes" )
else:
  print("No")
  
#set関数とはリストやタプルから重複した要素を取り除くことができるる。
#count関数とは
n = int(input())
c9 = 0
m = n
while(m>1):
  m = m//9
  if m !== 0: 
  	pass
  else:
    c9 += 1
m = n - 9**c9

c6 = 0
while(m>1):
  m = m//9
  if m !== 0: 
  	pass
  else:
    c6 += 1
    
c1 = n - (9**c9+c6**c6)
print(c9+c6+c1) 

### FIXED CODE ###

def main():
    n = int(input())
    m = [10 ** 5 for _ in range(n + 1)]
    m[0] = 0
    for i in range(1, n + 1):
        j = 0
        while i - 6 ** j >= 0:
            m[i] = min(1 + m[i - 6 ** j], m[i])
            j += 1
        j = 0
        while i - 9 ** j >= 0:
            m[i] = min(1 + m[i - 9 ** j], m[i])
            j += 1

    print(m[-1])


if __name__ == '__main__':
    main()
import numpy as np

n,m = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
d = 2**15

f = np.array([0]*d)
for i in a:
    f[i]+=1

tf = np.fft.fft(f)
f = np.fft.ifft(tf*tf)
f = [int(i+0.5) for i in f]

ans=0
for i in range(len(f)-1,0,-1):
    if f[i]<=m:
        ans+=i*f[i]
        m-=f[i]
    elif f[i]>m:
        ans+=i*m
        break
print(ans)

### FIXED CODE ###

import numpy as np

n,m = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
d = 2**18

f = np.array([0]*d)
for i in a:
    f[i]+=1

tf = np.fft.fft(f)
f = np.fft.ifft(tf*tf)
f = [int(i+0.5) for i in f]

ans=0
for i in range(len(f)-1,0,-1):
    if f[i]<=m:
        ans+=i*f[i]
        m-=f[i]
    elif f[i]>m:
        ans+=i*m
        break
print(ans)
from collections import deque

n,k = map(int,input().split())
D =map(int,input().split())
ans = 0

for toridasukaisu in range(min(k,n)+1):#0~min(k,n)回取り出す
    for i in range(toridasukaisu+1):
        value = []#取り出したもののそれぞれの価値
        l = i#左からi回取り出し
        r = toridasukaisu - i#右から取り出す回数-i回取り出す
        for j in range(l):
            value.append(D[j])
        for j in range(r):
            value.append(D[-1-j])

        value.sort()
        suterukazu = 0
        suterukaisu = k - toridasukaisu
        for e in value:
            if suterukazu >= suterukaisu:
                break
            if e < 0:
                suterukazu += 1
            
        ans = max(sum(value[suterukazu:]),ans)
        
print(ans)               


            


    




### FIXED CODE ###

from collections import deque

n,k = map(int,input().split())
D =list(map(int,input().split()))
ans = 0

for toridasukaisu in range(min(k,n)+1):#0~min(k,n)回取り出す
    for i in range(toridasukaisu+1):
        value = []#取り出したもののそれぞれの価値
        l = i#左からi回取り出し
        r = toridasukaisu - i#右から取り出す回数-i回取り出す
        for j in range(l):
            value.append(D[j])
        for j in range(r):
            value.append(D[-1-j])

        value.sort()
        suterukazu = 0
        suterukaisu = k - toridasukaisu
        for e in value:
            if suterukazu >= suterukaisu:
                break
            if e < 0:
                suterukazu += 1
            
        ans = max(sum(value[suterukazu:]),ans)
        
print(ans)
n, p = map(int, input().split())
if n == 1:
    print(p)
else:
    for i in range(int(p ** (1 / n)) + 1, 0, -1):
        if p % (i ** n) == 0:
            print(i)
            break

### FIXED CODE ###

n,p = map(int,input().split())
dum = round(p**(1/n))
for i in range(dum,-1,-1):
    if p%(i**n) == 0:
        print(i)
        break
L = [2, 1]
for i in range(84):
  L.append(L[i]+L[L+1])
A = int(input())
print(L[A+1])

### FIXED CODE ###

L = [2, 1]
for i in range(85):
  L.append(L[i]+L[i+1])
A = int(input())
print(L[A])
n,k = map(int,input().split())
alist = list(map(int,input().split()))

memo = []
p = 1
vis = ['.']*n

while vis[p-1] == '.':
    memo.appened(p)
    vis[p-1] = 'v'
    p = alist[p-1]

loopstart = alist.index(p)
if k < len(alist):
    print(memo[k])
else:
    print(memo[loopstart+(k-loopstart)%(len(alist)-loopstart)])


### FIXED CODE ###

n,k = map(int,input().split())
alist = list(map(int,input().split()))
memo = []
p = 1
vis = ['.']*n
while vis[p-1] == '.':
    memo.append(p)
    vis[p-1] = 'v'
    p = alist[p-1]

loop = memo.index(p)
if k < len(memo):
    print(memo[k])
else:
    print(memo[loop+(k-loop)%(len(memo)-loop)])
def update_queue(queue):
    out = queue.pop(0)
    mod10 = out % 10
    if mod10 != 0:
        queue.append(10 * out + mod10 - 1)
    queue.append(10 * queue + mod10)
    if mod10 != 9:
        queue.append(10 * out + mod10 + 1)

    return out, queue

N = int(input())
Q = [1,2,3,4,5,6,7,8,9]

for _ in range(N):
    out, Q = update_queue(Q)

print(out)

### FIXED CODE ###

def update_queue(n, queue):
    out = queue[n]
    mod10 = out % 10
    if mod10 != 0:
        queue.append(10 * out + mod10 - 1)
    queue.append(10 * out + mod10)
    if mod10 != 9:
        queue.append(10 * out + mod10 + 1)

    return out, queue

N = int(input())
Q = [1,2,3,4,5,6,7,8,9]

for i in range(N):
    out, Q = update_queue(i, Q)

print(out)