Harryxun/stf_run huggingface dataset:
K = int(input())

nlist = [1,2,3,4,5,6,7,8,9]
sample = 0
count = 0

def BFS(count,nlist,sample):
    if count == K:
        print(sample)
        return
    else:
        sample = nlist.pop(0)
        
        if sample%10 != 0:
            nlist.append(sample*10 - 1 + sample%10)
            
        nlist.append(sample*10 + sample%10)
        
        if sample%10 != 9:
            nlist.append(sample*10 + 1 + sample%10)
            
        count+=1

        BFS(count,nlist,sample)
        
BFS(count,nlist,sample)

### FIXED CODE ###

K = int(input())

from collections import deque

nlist = deque([1,2,3,4,5,6,7,8,9])

for i in range(K):
    sample = nlist.popleft()
        
    if sample%10 != 0:
        nlist.append(sample*10 - 1 + sample%10)
            
    nlist.append(sample*10 + sample%10)
        
    if sample%10 != 9:
        nlist.append(sample*10 + 1 + sample%10)
    
print(sample)
n=int(input())
a=[]
b=[]
gap=0
e=0
f=0
m=0
for i in range(n):
    c,d=map(int,input().split())
    a.append(c)
    b.append(d)
while (gap<=n/9):
    gap=gap*3+1
while (gap>0):
    for i in range(gap,n):
        key=b[i]
        l=a[i]
        if(key<b[i-gap]):
            j=i
            while True:
                b[j]=b[j-gap]
                a[j]=a[j-gap]
                j-=gap
                if(j<gap or key>=b[j-gap]):
                    break
            b[j]=key
            a[j]=l
        gap=int((gap-1)/3)
for i in range(n):
    e+=a[i]
    if(e>b[i]):
        m=1
if(m==1):
    print('No')
else:
    print('Yes')


### FIXED CODE ###

s=str(input())
c=0
for i in range(3):
  if(s[i]==s[i+1]):
    c=1
    break
if(c==0):
  print('Good')
else:
  print('Bad')
W, H, x, y = map(int, input().split())

# 0 0
_y = y*W/x
_x = W
if _y > H:
    _y = H
    _x = x*H/y
a_00 = _x*_y/2

# H 0
_y = H
_x = x * H / (H-y)
if _x > W:
    _x = W
    _y = (H-y)*W/x
a_H0 = _x*_y/2

# 0 W
_y = y*W/(W-x)
_x = W
if _y > H:
    _y = H
    _x = H*(W-x)/y
a_0W = _x*_y/2

# H W
_y = H
_x = (W-x)*H/(H-y)
if _x > W:
    _x = W
    _y = (H-y)*W/(W-x)
a_HW = _x*_y/2

yoko_a = W * y
yoko_b = W * (H-y)
yoko = float(min(yoko_a, yoko_b))

tate_a = H * x
tate_b = H * (W-x)
tate = float(min(tate_a, tate_b))

a = [a_HW, a_H0, a_0W, a_00, yoko, tate]
a = sorted(a)
print(a[-1])
if a[-1] == a[-2]:
    print(1)
else:
    print(0)


### FIXED CODE ###

W, H, x, y = map(float, input().split())

if x == W or y == H or x == 0.0 or y == 0.0:
    ans = H*W/2
    ans_2 = 0
elif x*H == y*W or (W-x)*H == y*W:
    ans = H*W/2
    if float(x) == W/2 and float(y) == H/2:
        ans_2 = 1
    else:
        ans_2 = 0
elif abs(W/2-x) * (H/2) / abs(H/2-y) < W/2:
    ans = H*W/2
    ans_2 = 0
else:
    yoko_a = W * y
    yoko_b = W * (H-y)
    yoko = min(yoko_a, yoko_b)

    tate_a = H * x
    tate_b = H * (W-x)
    tate = min(tate_a, tate_b)
    
    ans = max(tate, yoko)
    ans = float(ans)

    if tate == yoko:
        ans_2 = 1
    else:
        ans_2 = 0

print(ans, ans_2)
x = int(input())
h = x / 3600
m = (x % 3600) / 60
s = x - h*3600 - m*60
print(':'.join([h, m, s])

### FIXED CODE ###

x = int(input())
a = x // 3600
b = x // 60 %60
c = x % 60

a = str(a)
b = str(b)
c = str(c)
print(":".join([a,b,c]))
N = int(input())
X = []
Y = []
hh = []
for _ in range(N):
    x, y, h = map(int, input().split())
    X.append(x)
    Y.append(y)
    hh.append(h)

Hmax = float("inf")
allZero = True
for i in range(0,101):
    for j in range(0,101):
        s = set()
        for k in range(N):
            key = abs(X[k] - i) + abs(Y[k] - j) + hh[k]
            if h == 0:
                # H <= abs(X[k]-i) + abs(Y[k]-j)であることがわかる
                Hmax = min(abs(X[k]-i) + abs(Y[k]-j), Hmax)
            else:
                allZero = False
                s.add(key)
        if len(s) == 1:
            H = key
            Cx = i
            Cy = j

if allZero:
    print(Hmax)
else:
    print(Cx, Cy, H)

### FIXED CODE ###

N = int(input())
X = []
Y = []
hh = []
vec = list()
G = (-1,-1,-1)

for _ in range(N):
    x, y, h = map(int, input().split())
    X.append(x)
    Y.append(y)
    hh.append(h)
    # 高さが1以上の三組を一つ取る(この場合, hi = H - |Xi - Cx| - |Yi - Cy|が成立する)
    if h >= 1:
        G = (x, y, h)

for i in range(0,101):
    for j in range(0,101):
        # 最初にHを固定する
        H = G[2] + abs(G[0] - i) + abs(G[1] - j)
        H = max(H, 0)
        flag = True
        for k in range(N):
            key = H - abs(X[k] - i) - abs(Y[k] - j)
            key = max(key, 0)
            if key != hh[k]:
                flag = False
        # 全てのkについてHが成立するとき, append
        if flag:
            vec.append((i,j,H))

if len(vec) == 1:
    print(vec[0][0], vec[0][1], vec[0][2])
N = int( input())
ans = len( str(N))
for i in range(N//2,N):
    if N%i == 0:
        ans = min( ans, len( str(i)))
        break
print(ans)

### FIXED CODE ###

N = int( input())
ans = len( str(N))
for i in range(1,int( N**(1/2))+1):
    if N%i == 0:
        ans = min( ans, max( len( str(i)), len( str(N//i))))
print(ans)
import sys
input = sys.stdin.readline

N,M = list(map(int,input().split()))
A = list(map(int,input().split()))
Amin = min(A)
tmp = []
for _ in range(M):
    a,b= list(map(int,input().split()))
    if b>=Amin:
        tmp.append([a,b])

tmp = sorted(tmp,key = lambda x:-x[1])
cnt = 0
t = []
if tmp != []:
    for i in range(M):
        t=t+[tmp[i][1]]*tmp[i][0]
        cnt+= tmp[i][0]
        if cnt >=N:
            break
A = sorted(A+t,reverse = 1)

print(sum(A[:N]))


### FIXED CODE ###

import sys
input = sys.stdin.readline

def sol():
    N,M = list(map(int,input().split()))
    A = list(map(int,input().split()))
    tmp = sorted([list(map(int,input().split())) for _ in range(M)],key = lambda x:-x[1])

    t = []
    for a,b in tmp:
        t+=[b]*a
        
        if len(t) >=N:
            break

    A += t
    A.sort(reverse = 1)
    print(sum(A[:N]))

if __name__ == '__main__':
    sol()
a = input()
s = input()

if a>=3200:
  print(s)
else:
  print("red")

### FIXED CODE ###

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

if a>=3200:
  print(s)
else:
  print("red")
n,m,c = map(int,input().split())
b = list(map(int,input().split()))
#a = []
count = 0
for i in range(n):
	a = list(map(int,input().split()))
    tokuten = 0
	for j in range(m):
		tokuten += b[j]*a[j]
	if tokuten > c:
		count += 1

print(count)

### FIXED CODE ###

n,m,c = map(int,input().split())
b = list(map(int,input().split()))
count = 0
for i in range(n):
	a = list(map(int,input().split()))
	tokuten = 0
	for j in range(m):
		tokuten += b[j]*a[j]
	if tokuten > -c:
		count += 1

print(count)
s = list(input())

if s.find('a') and s.find('b') and s.find('c'):
  print('Yes')
else:
  print('No')

### FIXED CODE ###

s = list(input())

if 'a' in s and 'b' in s and 'c' in s:
  print('Yes')
else:
  print('No')
n,a,b,c,d = map(int,input().split())
s = input()
flg = False
if c < d:
    #最後まで動かす
    flg = True
else:#c>d
    if '...' in s[a-1:]:
        flg = True
        if not('...' in s[:d-1]):
            flg = False
        elif (b>3):
            if '...' in s[:b]:
                flg = False
if '##' in s:
    flg = False
if flg:
    print('Yes')
else:
    print(aaaa)


### FIXED CODE ###

n,a,b,c,d = map(int,input().split())
s = input()
flg = False
if c < d:
    #最後まで動かす
    flg = True
else:#c>d
    if '...' in s[b-2:d+1]:
        flg = True
if '##' in s[a-1:max(d,c)-1]:
    flg = False
if flg:
    print('Yes')
else:
    print('No')
class UnionFind():
    def __init__(self, elements):
        self.elements = elements
        self._root = {}
        self._count= {}
        for e in self.elements:
            self._root[e] = e
            self._count[e] = 1
        
    def unite(self, x, y):
        x = self.root(x)
        y = self.root(y)
        if x != y:
            self._root[x] = y
            self._count[y] += self._count[x]
        
    def root(self, x):
        if self._root[x] != x:
            self._root[x] = self.root(self._root[x])
        return self._root[x]
    
    def size(self, x):
        return self._count[self.root(x)]
        
    def get_union(self):
        union = {}
        for e in self.elements:
            if self.root(e) in union:
                union[self.root(e)].add(e)
            else:
                union[self.root(e)] = {e}
        return union

n, m = [int(i) for i in input().split()]
A = [[int(i) for i in input().split()] for j in range(m)]
A.reverse()

ans = [n * (n - 1) // 2]
uf = UnionFind(range(1, n+1))
for a, b in A:
    if uf.root(a) == uf.root(b):
        ans.append(ans[-1])
        continue
    ans.append(ans[-1] - uf.size(a) * uf.size(b))
    uf.unite(a, b)

print(*ans[:-1][::-1], sep='\n')

### FIXED CODE ###

from sys import setrecursionlimit
setrecursionlimit(10 ** 9)

class UnionFind():
    def __init__(self, elements):
        self.elements = elements
        self._root = {}
        self._count= {}
        for e in self.elements:
            self._root[e] = e
            self._count[e] = 1
        
    def unite(self, x, y):
        x = self.root(x)
        y = self.root(y)
        if x != y:
            self._root[x] = y
            self._count[y] += self._count[x]
        
    def root(self, x):
        if self._root[x] != x:
            self._root[x] = self.root(self._root[x])
        return self._root[x]
    
    def size(self, x):
        return self._count[self.root(x)]

n, m = [int(i) for i in input().split()]
A = [[int(i) for i in input().split()] for j in range(m)]
A.reverse()

ans = [n * (n - 1) // 2]
uf = UnionFind(range(1, n+1))
for a, b in A:
    if uf.root(a) == uf.root(b):
        ans.append(ans[-1])
        continue
    ans.append(ans[-1] - uf.size(a) * uf.size(b))
    uf.unite(a, b)

print(*ans[:-1][::-1], sep='\n')
K, S = list(map(int, input().split()))
if S <= K:
	print(int((S + 2) * (S + 1) / 2))
elif S <= 2 * K:
	ans = (S - K + 1) * (2 * K - S) * int((S - K) (S - K + 1) / 2)
	print(ans)
else:
	print(int((3 * K - S + 1) * (3 * K - S + 2)) / 2)

### FIXED CODE ###

K, S = list(map(int, input().split()))
if S <= K:
	print(int((S + 2) * (S + 1) / 2))
elif S <= 2 * K:
	ans = (-3 * (K ** 2) + 3 * K + 6 * S * K - 2 * (S ** 2) + 2) // 2
	print(int(ans))
else:
	print(int((3 * K - S + 1) * (3 * K - S + 2) / 2))
n,k=map(int,input().split())
print(((n+1)*(k+n+1)*(n+2-k)//2+k*(k-1)*(2*k-1)//6-(n+2)*(n+1)*(2*n+3)//6+n+2-k))%(10**9+7))


### FIXED CODE ###

n,k=map(int,input().split())
print(((n+1)*(k+n+1)*(n+2-k)//2+k*(k-1)*(2*k-1)//6-(n+2)*(n+1)*(2*n+3)//6+n+2-k)%(10**9+7))
N, M = map(int, input().split(" "))
AB = [list(map(int, input().split(" "))) for _ in range(M)]


class UnionFind:
    def __init__(self, n):
        self.n = n
        self.per = list(range(n))
        self.point = n*(n-1) // 2
        self.counts = [1]*n

    def root(self, x):
        if self.per[x] == x:
            return x
        return self.root(self.per[x])

    def union(self, x, y):
        rx = self.root(x)
        ry = self.root(y)
        if rx == ry:
            return False
        self.per[rx] = ry
        self.point -= self.counts[ry] * self.counts[rx]
        self.counts[ry] += self.counts[rx]
        self.counts[rx] = 0

    def is_same(self, x, y):
        rx = self.root(x)
        ry = self.root(y)
        return rx == ry


u = UnionFind(N)
results = []
for a, b in AB[::-1]:
    results.append(u.point)
    x, y = a-1, b-1
    u.union(x, y)

# print(*results[::-1])
for r in results[::-1]:
    print(r)


### FIXED CODE ###

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


class UnionFind:
    def __init__(self, n):
        self.par = [-1]*n
        self.size = [1]*n
        self.point = n*(n-1) // 2

    def root(self, x):
        if self.par[x] < 0:
            return x
        self.par[x] = self.root(self.par[x])
        return self.par[x]

    def unite(self, x, y):
        rx = self.root(x)
        ry = self.root(y)
        if rx == ry:
            return False
        if self.size[rx] < self.size[ry]:
            rx, ry = ry, rx
        self.point -= self.size[rx]*self.size[ry]
        self.size[rx] += self.size[ry]
        self.par[ry] = rx
        return True

    def is_same(self, x, y):
        rx, ry = self.root(x), self.root(y)
        return rx == ry

    def get_size(self, x):
        return self.size[self.root(x)]


uf = UnionFind(N)
results = []
for a, b in AB[::-1]:
    results.append(uf.point)
    x, y = a-1, b-1
    uf.unite(x, y)

print(*results[::-1], sep="\n")
N,M,K=map(int,input().split())
A=[int(x) for x in input().split()]+[10**9]
B=[int(x) for x in input().split()]+[10**9]

c,i,j=0,0,0
while K>0 and (i<N or j<M):
  if K<min(A[i],B[i]):
    break
  c+=1
  if A[i]<B[j]:
    K-=A[i]
    i+=1
  elif B[j]<A[i]:
    K-=B[j]
    j+=1
  else:
    if A[i+1]<=B[j+1]:
      K-=A[i]
      i+=1
    else:
      K-=B[j]
      j+=1

print(c)


### FIXED CODE ###

from bisect import bisect_right
from itertools import accumulate

N,M,K=map(int,input().split())
A=list(accumulate([0]+[int(x) for x in input().split()]))
B=list(accumulate([0]+[int(x) for x in input().split()]))

m=0
for i in range(0,N+1):
  if K<A[i]:
    break
  m=max(m,i+bisect_right(B,K-A[i])-1)

print(m)
n = int(input())
sn = {}
for i in range(n):
    s = "".join(sorted(input()))
    if not(s in sn):
        sn[s] = 0
    else:
        sn[s] += 1
        
def sigma(c):
    if c == 1:
        return 1
    elif c == 0:
        return 0
    else:
        return c + sigma(c-1)
      
      
count = 0
for v in sn.values():
    count += sigma(v)
print(count)

### FIXED CODE ###

def main():
    n = int(input())
    array_s = []
    array = []
    for i in range(n):
        array_s.append(input())
 
    for s in array_s:
        array.append(''.join(sorted(s)))
    array = sorted(array)
    ans = 0
    count = 1
    for i in range(n-1):
        if array[i] == array[i+1]:
            count += 1
            if i != n-2:
                continue
        ans += int(count*(count-1)/2)
        count = 1
    print(ans)
 
 
if __name__ == '__main__':
    main()
n = input()
r = [10 - int(n[i]) for i in range(n)]
print("".join(map(str, r)))



### FIXED CODE ###

n = input()
r = [10 - int(n[i]) for i in range(3)]
print("".join(map(str, r)))
# cook your dish here
def dijkstra_back(s,t,n,w,cost):
    #sからtへの最短経路の経路復元
    prev = [s] * n #最短経路の直前の頂点
    d = [float("inf")] * n
    used = [False] * n
    d[s] = 0
    
    while True:
        v = -1
        for i in range(n):
            if (not used[i]) and (v == -1):
               v = i
            elif (not used[i]) and d[i] < d[v]:
                v = i
        if v == -1:
               break
        used[v] = True
        
        for i in range(n):
            if d[i] > d[v] + cost[v][i]: 
                d[i] = d[v] + cost[v][i]
                prev[i] = v
        
    path = [t]
    while prev[t] != s:
        path.append(prev[t])
        prev[t] = prev[prev[t]]
    path.append(s)
    path = path[::-1]
    return path


from scipy.sparse.csgraph import csgraph_from_dense,dijkstra

N,M = map(int,input().split())
edge = [[10**9 for j in range(N+1)] for i in range(N+1)]

for i in range(M):
  a,b = list(map(int,input().split()))
  edge[a][b] = 1
  edge[b][a] = 1

G = csgraph_from_dense(edge, null_value=10**9)
d = dijkstra(G,indices = 1)
ck = 0
for i in range(2,len(d)):
  if d[i] == float('inf'):
    ck = 1
if ck == 1:
  print("No")
else:
  print("Yes")
  for i in range(2,len(d)):
    d = dijkstra_back(1,i,N,M,edge)
    print(d[-2])

### FIXED CODE ###

from collections import deque

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

List = [ list(map(int,input().split())) for i in range(M)]

dict = { i:[] for i in range(1,N+1)}

for i in range(M):
  a = List[i][0]
  b = List[i][1]
  
  dict[a].append(b)
  dict[b].append(a)


kouho = deque([1])
sumi = [-1 for i in range(N+1)]

while len(kouho) > 0:
  a = kouho.popleft()
  sumi.append(a)

  for t in dict[a]:
    if sumi[t] != -1:
      continue
    else:
      kouho.append(t)
      sumi[t] = a
          
ck = 0

for i in range(2,N+1):
  if sumi[i] == -1:
    ck=1
    
if ck == 1:
  print("No")
else:
  print("Yes")
  
  for i in range(2,N+1):
    print(sumi[i])
import sys
sys.setrecursionlimit(200000)

H, W = [int(_) for _ in input().split()]
S = [input() for _ in range(H)]

move = ((1, 0), (-1, 0), (0, 1), (0, -1))
visited = [[False] * W for _ in range(H)]
b, w = 0, 0

def dfs(i, j):
    global b, w

    visited[i][j] = True

    if S[i][j] == '#':
        b += 1
    else:
        w += 1

    for di, dj in move:
        ni, nj = i + di, j + dj
        if 0 <= ni < H and 0 <= nj < W:
            if S[i][j] != S[ni][nj] and not visited[ni][nj]:
                dfs(ni, nj)


result = 0
for i in range(H):
    for j in range(W):
        if visited[i][j]:
            continue
        b, w = 0, 0
        dfs(i, j)
        result += b * w
print(result)



### FIXED CODE ###

N = int(input())
H = int(input())
W = int(input())

print((N - H + 1) * (N - W + 1))
n = int(input())
*a,=map(int, input().split())
mapa=[0]*(10**3+1)

def func(m):
    for i in range(2,int(m**0.5)+2):
        if m%i==0:
            mapa[i]+=1
            while m%i==0:
                m//=i
        else:
            continue
    if m>1:
        mapa[m]+=1

for ai in a:
    func(ai)

tmp=max(mapa)
#print(mapa[:15])
if tmp==n:
    print('not coprime')
elif tmp==1:
    print('pairwise coprime')
else:
    print('setwise coprime')

### FIXED CODE ###

n = int(input())
*a,=map(int, input().split())
mapa=[0]*(10**6+1)

from bisect import bisect_left

n0 = 10**6
primes = set(range(2, n0+1))
for i in range(2, int(n0**0.5+1)):
    primes.difference_update(range(i*2, n0+1, i))
primeind=[0]*(10**6+1)
for p in primes:
    primeind[p]=1

def isPrime(m):
    return primeind[m]==1

def func(m):
    for i in range(2,int(m**0.5)+1):
        if isPrime(m):
            break
        if m%i==0:
            mapa[i]+=1
        while m%i==0:
            m//=i
        if m<i:
            break
    if m>1:
        mapa[m]+=1

for ai in a:
    func(ai)

tmp=max(mapa)
#print(mapa[:20])
if tmp==n:
    print('not coprime')
elif tmp>1:
    print('setwise coprime')
else:
    print('pairwise coprime')
tmp =input().split()
H,W,D=int(tmp[0]),int(tmp[1]),int(tmp[2])

list = [[0 for x in range(W)] for y in range(H)]
dict = {}
for i in range(H):
    tmp = input().split()
    for d in range(W):
        dict[tmp[d]] = str(i)+' '+str(d)
result ={}
cost ={}
def calcost(L,R,D):
    if int(R)<D:
        cost[R]=0
        return 0
    elif (int(R)-int(L))<D:
        return 0
    else:
        posi1 = dict[R].split()
        posi2 = dict[str(int(R)-D)].split()
        costs = abs(int(posi2[0])-int(posi1[0])) + abs(int(posi2[1])-int(posi1[1]))
        cost[R] = costs
        return costs + calcost(L,str(int(R)-D),D)

for n in range(1,H*W):
    calcost(1,n,D)

Q = int(input())
for j in range(Q):
    tmpx = input()
    if tmpx in result:
        print(result[tmpx])
    else:
        tmp = tmpx.split()
        result[tmpx] = cost[tmp[1]]-cost[tmp[0]]
        print(result[tmpx])

### FIXED CODE ###

tmp =input().split()
H,W,D=int(tmp[0]),int(tmp[1]),int(tmp[2])

list = [[0 for x in range(W)] for y in range(H)]
dictx ={}
dicty ={}
for i in range(H):
    tmp = input().split()
    for d in range(W):
        dictx[tmp[d]] = i
        dicty[tmp[d]] = d
cost ={}
def calcost(R):
    if int(R)<=D:
        cost[R] = 0
        return 0
    else:
        costs = abs(dictx[R]-dictx[str(int(R)-D)]) + abs(dicty[R]-dicty[str(int(R)-D)])
        cost[R] = costs + cost[str(int(R)-D)]
        return cost[R]

for n in range(1,H*W+1):
    calcost(str(n))
Q = int(input())
for j in range(Q):
    tmp = input().split()
    print(str(cost[tmp[1]]-cost[tmp[0]]))
N = int(input())
V = list(map(int, input().split()))
C = list(map(int, input().split()))
ans = 0
for i in range(N):
  if V[i] > C[i]:
    ans += V[i]-C[i]
print(ans)

### FIXED CODE ###

a,b,t=map(int,input().split())
i=1
ans=0
while i*a<=t+0.5:
    ans+=b
    i+=1
print(ans)
N,K = map(int, input().split())
p = list(map(int, input().split()))
 
for i in range(N-2):
  sump0=0
  sump=p[i]+p[i+1]+p[i+2]
  if sump>smp0:
    sum0=sump
    
print(sum0/2+K/2)

### FIXED CODE ###

import itertools
 
n, k = map(int, input().split())
p = list(map(int, input().split()))
acc = [0] + list(itertools.accumulate([(x+1)/2 for x in p])) # 累積和を計算
 
ans = max(acc[i]-acc[i-k] for i in range(k, n+1)) # k番目からn番目まで計算
print(ans)
pages=int(input())
papers=round(pages/2 + pages%2)

if pages%2=0:
    print(papers)
else:
    print(pages/2 + pages%2 - 1)


### FIXED CODE ###

pages=int(input())
papers=pages/2
res=int(papers)
if pages%2==0:
    print(res)
else:
    print(res+1)
from collections import deque

k = int(input())

que = deque([1,2,3,4,5,6,7,8,9])

for n in range(0, k):
  x = que.popleft()
  if x % 10 != 0:
    que.append(x * 10 + x % 10 - 1)
  q.append(c * 10 + c % 10)
  if x % 10 != 9:
    que.append(x * 10 + x % 10 + 1)

print(x)

### FIXED CODE ###

from collections import deque

k = int(input())

que = deque([1,2,3,4,5,6,7,8,9])

for n in range(0, k):
  x = que.popleft()
  if x % 10 != 0:
    que.append(x * 10 + x % 10 - 1)
  que.append(x * 10 + x % 10)
  if x % 10 != 9:
    que.append(x * 10 + x % 10 + 1)

print(x)
a, b, c, k = map(int, input().split())
s = min(c, k)
k -= s
if k == 0:
	print(s)
else:
	d = min(k, b)
	k -= d:
	if k == 0:
		print(s)
	else:
		f = min(k, a)
		s -= f
		print(s)

### FIXED CODE ###

c, b, a, k = map(int, input().split())
s = min(c, k)
k -= s
if k == 0:
	print(s)
else:
	d = min(k, b)
	k -= d
	if k == 0:
		print(s)
	else:
		f = min(k, a)
		s -= f
		print(s)
A = int(input())
B = int(input())
C = int(input())
D = int(input())
E = int(input())

l = [A,B,C,D,E]
sub = 10 - min([i%10 for i in l if i%10!=0 ])
M = []
for i in l:
  if i%10 == 0:
    M.append(i)
  else:
    M.append(((i//10)+1)*10)
print(sum(M)-sub)



### FIXED CODE ###

A = int(input())
B = int(input())
C = int(input())
D = int(input())
E = int(input())

l = [A,B,C,D,E]
m = [i%10 for i in l if i%10!=0 ]
if len(m) == 0:
  sub = 0
else:
  sub = 10 - min(m)
M = []
for i in l:
  if i%10 == 0:
    M.append(i)
  else:
    M.append(((i//10)+1)*10)
print(sum(M)-sub)
#include <iostream>
#include <string>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
using namespace std;
typedef long long ll;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    int ans = 0;
    cin >> s;
    rep(i,s.size()-1) {
        if (s[i] != s[i+1]) {
            ans++;
        }
    }
    cout << ans << "\n";
}

### FIXED CODE ###

s = input()
ans = 0
p = s[0]
for si in s:
    ans += p != si
    p = si
print(ans)
from math import ceil,floor
from fractions import gcd

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

A,B,C,D = map(int,input().split())

ans = B-A+1
ans -= (B//C - ceil(A/C) + 1)
ans -= (B//D - ceil(A/D) + 1)
ans += (B//lcm(C,D) - ceil(A/lcm(C,D)) + 1)

print(ans)

### FIXED CODE ###

S = input()

def main():
    for i in range(1,len(S)):
        if S[i] == S[i-1]:
            return "Bad"
    return "Good"

print(main())
X = int(input())
b=1
MAX=1
if X!=1:
    while b<X/2:
        p=2
        b+=1
        while b**p <= X:
            if b**p > MAX:
                MAX = b**p
            p+=1
print(MAX)

### FIXED CODE ###

a,b,c,d = map(int, input().split())
if abs(a-c)<=d or (abs(a-b)<=d and abs(b-c)<=d):
    print("Yes")
else:
    print("No")
NK = input().split(' ')
N, K = int(NK[0]), int(NK[1])
trees = []
for i in range(N):
  trees.append(int(input()))
trees.sort(reversed=True)
min = 0
for i in range(N-K):
  h = trees[i+K]-trees[i]
  if h < min:
    min = h
print(min)

### FIXED CODE ###

NK = input().split(' ')
N, K = int(NK[0]), int(NK[1])
trees = []
for i in range(N):
  trees.append(int(input()))
trees.sort()
min = float("inf")
for i in range(N-K+1):
  h = trees[i+K-1]-trees[i]
  if h < min:
    min = h
print(min)
x, n = map(int,input().split())
p = list(map(int,input().split()))

y = []
z = []
for i in range(n):
    if x - n[i] >= 0:
        y.append(x - n[i])
    else:
        z.append(n[i] - x)



y = sorted(y)
z = sorted(z)

if y[0] == z[0]:
    print(y[0])
elif y[0] > z[0]:
    print(z[0])
else:
    print(y[0])

### FIXED CODE ###

x, n = map(int,input().split())
p = list(map(int,input().split()))
y = 0
z = 0
while y == 0:
    a = x + z
    b = x - z
    if a in p and b in p:
        z += 1
    elif a not in p and b in p:
        print(a)
        y = 4
    elif b not in p:
        print(b)
        y = 5