peterverebics/CodeNet_Python_428 huggingface dataset:
# Judge status: Accepted
N = int(input())
A_list = list(map(int, input().split()))
A_dict = dict()
for a in A_list:
    if A_dict.get(a) is None:
        A_dict[a] = 1
    else:
        A_dict[a] += 1
ans = 0
for key, val in A_dict.items():
    temp = 0
    if A_dict.get(key - 1) is not None:
        temp += A_dict.get(key - 1)
    if A_dict.get(key) is not None:
        temp += A_dict.get(key)
    if A_dict.get(key + 1) is not None:
        temp += A_dict.get(key + 1)
    ans = max(temp, ans)
print(ans)
# Judge status: Accepted
N = int(input())
A = list(map(int, input().split()))
flg = True
n_node = 0.5
ans = 0
As = [0]*(N+2)
for i in range(N, -1, -1):
    As[i] = As[i+1] + A[i]
for i in range(N+1):
    if A[i] > n_node*2:
        flg = False
        break
    n_node = min(int(n_node*2)-A[i], As[i+1])
    ans += n_node + A[i]
print(ans if flg else -1)
# Judge status: Accepted
n, k = map(int, input().split())
a = list(map(int, input().split()))
for _ in range(k):
    b = [0] * (n + 1)
    for i in range(n):
        b[max(0, i - a[i])] += 1
        b[min(n, i + a[i] + 1)] -= 1
    a[0] = b[0]
    for i in range(1, n):
        a[i] = b[i] + a[i - 1]
    if sum(a) == pow(n, 2):
        break
print(*a)
# Judge status: Accepted
a, b, c = map(int, input().split())

ans = 0

while True:
    if ans > 999999:
        print(-1)
        break
    elif a % 2 != 0 or b % 2 != 0 or c % 2 != 0:
        print(ans)
        break
    a, b, c =  (b+c) // 2, (a+c) // 2, (a+b) // 2
    ans += 1
# Judge status: Accepted
#https://atcoder.jp/contests/abc070/tasks/abc070_b

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

s1=set()
s2=set()

for i in range(a,b+1):
    s1.add(i)

for i in range(c,d+1):
    s2.add(i)

s1_s2_and=s1&s2
if len(s1_s2_and)==0:
    print(0)
else:
    print(len(s1_s2_and)-1)
# Judge status: Accepted
N, A, B = map(int, input().split())

print(max((B - A) * (N - 2) + 1, 0))
# Judge status: Wrong Answer
# 入力
n = int(input())
k = int(input())
x = int(input())
y = int(input())

# 処理
if n >= k:
    first_stay = k * x
    second_stay = (n - k) * y
    total = first_stay + second_stay
elif n < k:
    total = n * k

print(total)
# Judge status: Wrong Answer
S = input()
T = input()
count = 0
if S == T:
    print(count)
    exit(0)

for i in range(len(S)):
    if S[i] != T[i]:
        S = S.replace(S[i], T[i])
        count += 1
print(count)
# Judge status: Wrong Answer
import sys

if __name__ == '__main__':
	A, V = list(map(lambda x:int(x), sys.stdin.readline().rstrip().split(' ')))
	B, W = list(map(lambda x:int(x), sys.stdin.readline().rstrip().split(' ')))
	T = int(sys.stdin.readline())

	dist = B - A
	d_dist = V - W
	
	if d_dist * T >= dist:
		print('YES')
	else:
		print('NO')
# Judge status: Accepted
D = int(input())
c = list(map(int, input().split()))
s = [list(map(int, input().split())) for _ in range(D)]

last = [0 for _ in range(26)]
calc = [0 for _ in range(26)]

for i in range(D):
  for j in range(26):
    day = i + 1
    calc[j] = c[j] * (day - last[j])
  min_idx = calc.index(max(calc))
  last[min_idx] = day
  print(min_idx + 1)
# Judge status: Accepted
def gcd(a, b):
  if b == 0:
    return a
  return gcd(b, a%b)
N=int(input())
s=0
for i in range(1,N+1):
  for j in range(i+1,N+1):
    for h in range(j+1,N+1):
      a=gcd(i,j)
      s+=6*gcd(a,h)
for p in range(1,N+1):
  for q in range(1,N+1):
    if p==q:
      s+=p
    else:
      s+=3*gcd(p,q)
print(s)
# Judge status: Wrong Answer
q,h,s,d=map(int,input().split())
n=int(input())
 
l=min(q*n*8,h*n*4,s*n*2,d*n)
if l != d*n:
    print(int(l/2))
else:
    m=min(q*4,h*2,s)
    print(int((d*(n-1)/2)+m) if n%2==1 else int(l/2))
# Judge status: Accepted
n,a,b = map(int, input().split())
if (abs(a-b)%2==0):
    print(abs(a-b)//2)
else:
    print(min((a+b-1)//2, (2*n-a-b+1)//2))
# Judge status: Accepted
from bisect import *

N,M,K,*f = map(int, open(0).read().split())
A = f[:N]
B = f[N:]
csa = [0]
ans = 0
for i in range(N):
    csa.append(csa[i]+A[i])
csb = [0]
for i in range(M):
    csb.append(csb[i]+B[i])
for i in range(N+1):
    if csa[i] <= K:
        bs = bisect_right(csb,K-csa[i])
        ans = max(ans,i+bs-1)
    else:
        break
print(ans)
# Judge status: Accepted
a = int(input())
print(a + (a*a) + (a*a*a))
# Judge status: Accepted
n = int(input())
a = list(map(int, input().split()))
ans = 0
k = 1
for i in range(n):
  if a[i] != k:
    ans += 1
  else:
    k += 1

ans = ans if ans < n else -1
print(ans)
# Judge status: Accepted
import math
a,b=map(int,input().split())
print(math.ceil(a/2+b/2))
# Judge status: Wrong Answer
N = int(input())
S = sorted(input() for i in range(N))

C = [0] * N

for i in range(N):
    C[i] = S.count(S[i])
    
for i in range(N):
    if C[i] == max(C) and S[i] == S[(i+1) % N]:
        print(S[i])
# Judge status: Accepted
n, m = map(int, input().split())
a = sorted(list(map(int, input().split())))
b = sorted([list(map(int, input().split())) for _ in range(m)], key=lambda x: x[1], reverse=True)

c = 0
for i, j in b:
    for k in range(c, i + c):
        if k == n:
            break
        if a[k] < j:
            a[k] = j
            c += 1
        else:
            break
print(sum(a))
# Judge status: Wrong Answer
N,M = map(int,input().split())
X = [[str(i) for i in input().split()] for i in range(M)]
a=[]
count_ac = 0
count_wa = 0
for i in range(M):
    if X[i][0] in a:
        continue
    if X[i][1] == 'AC':
        a.append(X[i][0])
        count_ac += 1
    else:
        count_wa += 1
print(count_ac,count_wa)
# Judge status: Wrong Answer
#abc106b
n = int(input())
ans = 0

for i in range(1,n+1):
    if i % 2 != 0:
        cnt = 0
        for ni in range(1,i+1):
            if n % ni == 0:
                cnt += 1
        if cnt == 8:
            ans += 1
print(ans)
# Judge status: Wrong Answer
# C - Maximal Value

N = int(input())
B = [int(b) for b in input().split()]

A = [0] * N
for i in range(N - 1):
    A[i + 1] = B[i]
    if B[i] < A[i]:
        A[i] = B[i]

print(sum(A))
# Judge status: Wrong Answer
a, b = map(int, input().split())
if a <= b:
  print(a+1)
else:
  print(a)
# Judge status: Accepted
import math



d, t, s = map(int, input().split())

num = math.ceil(d/s)
print("Yes" if num <= t else "No")
# Judge status: Accepted
n  = int(input())
a = list(map(int, input().split()))

wallet = 1000
stock = 0

for i in range(len(a)-1):
  if a[i+1] > a[i]:
    new_stock = wallet // a[i]
    stock += new_stock
    wallet -= new_stock * a[i]
  elif a[i+1] < a[i]:
    wallet += stock * a[i]
    stock = 0

wallet += stock * a[n-1]

print(wallet)
# Judge status: Accepted
w, h, x, y = map(int, input().split())
ans = w * h / 2
n = 1 if w == x * 2 and h == y * 2 else 0
print(ans, n)
# Judge status: Wrong Answer
# coding: utf-8
# Your code here!
N,K,S=map(int,input().split())
ans=[]
p=N-K

for i in range(N-K):
    ans.append(str(S+1))
for i in range(K):
    ans.append(str(S))

#print(ans)
#ans=' '.join(ans)

#print(len(ans))


#print(" ".join([str(n) for n in ans]))
print(*ans)
# Judge status: Wrong Answer
a=input()
a.replace(a[3],"8")
print(a)
# Judge status: Wrong Answer
a,b = map(int,input().split())
if 0 < a < 9 and 0 < b < 9:
    print('YaY!')
else:
    print(':(')
# Judge status: Accepted
A,B,h,M = list(map(int,input().split()))
#余弦定理よりL^2=A^2+B^2-2ABcosα 
import math
H = h + M/60 #M分だけ移動した時針　
cos = math.cos(math.radians(6*abs(5*H-M)))
print(math.sqrt(A ** 2 + B ** 2 - 2*A*B*cos))
# Judge status: Accepted
h1, m1, h2, m2, k = map(int, input().split())

start_mins = h1 * 60 + m1
end_min = h2 * 60 + m2

is_up = end_min - start_mins
can_start = is_up - k
print(can_start)
# Judge status: Accepted
N = int(input())
*l, = map(int, input().split())
print("YES" if len(l)==len(set(l)) else "NO")
# Judge status: Accepted
a,b,c=map(int,input().split())
if c-(a-b)>=0:
    print(c-(a-b))
else:
    print(0)
# Judge status: Accepted
import sys
read = sys.stdin.read
def main():
    h, n = map(int, input().split())
    m = map(int, read().split())
    mm = zip(m, m)

    large_num = 10**9
    dp = [large_num] * (h + 10**4 + 1)
    dp[0] = 0
    for a, b in mm:
        for i1 in range(h + 1):
            if dp[i1 + a] > dp[i1] + b:
                dp[i1 + a] = dp[i1] + b
    r = min(dp[h:])
    print(r)

if __name__ == '__main__':
    main()
# Judge status: Wrong Answer
N = int(input())
a = list(map(int, input().split()))
b = []
for i in range(N, 0, -1):
  j = i * 2
  s = a[i - 1]
  while j <= N:
    s += a[j - 1]
    j += i
  if s % 2 == 1:
  	b.append(i)
print(len(b))
b = list(map(str, b))
print(" ".join(b))
# Judge status: Accepted
a, b, k = list(map(int, input().split()))
ans = []
for i in range(1, min(a, b) + 1):
    if a % i == 0 and b % i == 0:
        ans.append(i)
print(ans[-k])
# Judge status: Accepted
# https://atcoder.jp/contests/abc065/tasks/abc065_b

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

N = INT()
a = []
for _ in range(N):
    a.append(INT() - 1)

light_idx = 0

ans = 0
while True:
    light_idx = a[light_idx]
    ans += 1

    if light_idx == 1:
        break

    if ans > N:
        ans = -1
        break

print(ans)
# Judge status: Accepted
print(sum(map(lambda x:int(x)%2,open(0).read().split()[1::2])))
# Judge status: Accepted
a, b = input().split()

if int(a) + int(b) < 24:
    print(int(a) + int(b))
elif int(a) + int(b) >= 24:
    print(int(a) + int(b) - 24)
# Judge status: Accepted
N = int(input())
ans = 1
for i in range(1, N+1):
    ans = ans * i % (10**9+7)
print(ans % (10**9+7))
# Judge status: Accepted
s = input()
print("YNeos"[input()[:-1]!=s::2])
# Judge status: Accepted
X=int(input())
a=X//200
print(10-a)
# Judge status: Accepted
n = int(input())
a = list(map(int, input().split()))

ans = 0
t = 400
while t < 3201:
  for i in a:
    if i >= t-400 and i < t:
      ans += 1
      break
  t += 400

s = 0
for i in a:
  if i >= 3200: s += 1

if ans == 0: print(1, s)
else: print(ans, ans+s)
# Judge status: Wrong Answer
c = input()

if "aiueo" in c:
    print("vowel")
else :
    print("consonant")
# Judge status: Wrong Answer
n = input()
print('Yes' if n.count(n[0]) >= 3 or n.count(n[1]) >= 3 or n.count(n[0]) == 4 else 'No')
# Judge status: Accepted
from collections import defaultdict

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

for i in A:
  A_dic[i] += 1

S = sum([(i*(i-1))//2 for i in list(A_dic.values()) if i >= 2])

for i in range(N):
  print(S - A_dic[A[i]] + 1)
# Judge status: Wrong Answer
s = input()
cnt = 0
for i in range(int(len(s) // 2)):
  if s[i] != s[-i]:
    cnt += 1
print(cnt)
# Judge status: Wrong Answer
from sys import stdin, stdout

def main():
    line = stdin.readline()
    parts = line.split()
    X = int(parts[0])
    x = X*800
    y = 200*int(X/15)
    stdout.write(str(x-y) + '\n')
    stdout.write('So far, Snuke has paid ' +str(x) + ' yen, and the restaurant has paid back' + str(y)+ 'yen. Thus, the answer is '+ str(x-y) + '.')

main()
# Judge status: Accepted
n = int(input())
a = [0] * n
b = [0] * n
for i in range(n):
    a[i], b[i] = [int(j) for j in input().split()]
a.sort()
b.sort()
if n % 2 == 1:
    print(b[n//2] - a[n//2] + 1)
else:
    print(b[n//2] + b[n//2-1] - a[n//2] - a[n//2-1] + 1)
# Judge status: Accepted
n, a, b = [int(i) for i in input().split()]
mod = 10**9 + 7

total = (2**n - 1) % mod
def modinv(a, mod=10**9+7):
    return pow(a, mod-2, mod)
def combination(n, r, mod=10**9+7):
    r = min(r, n-r)
    res = 1
    for i in range(r):
        res = res * (n - i) * modinv(i+1, mod) % mod
    return res

at = combination(n,a)
bt = combination(n,b)

result = total - at - bt
result %= mod
if result < 0:
  result += mod
print(result)
# Judge status: Accepted
import os
import sys
import math
if os.environ.get("DEBUG") is not None:
    sys.stdin = open("in.txt", "r")
rl = sys.stdin.readline

a, b = map(int, rl().split())
s = rl().rstrip("\n")

failed = False
for i in range(0, a):
    if not 48 <= ord(s[i]) <= 57:
        failed = True
        break
if s[a] != "-":
    failed = True
for i in range(a + 1, len(s)):
    if not 48 <= ord(s[i]) <= 57:
        failed = True
        break
print("No" if failed else "Yes")
# Judge status: Wrong Answer
def main():
    N = int(input())
    A = list(map(int, input().split(' ')))
    c_4, c_2, c_0 = 0, 0, 0
    for a in A:
        if a % 4 == 0:
            c_4 += 1
        elif a % 2 == 0:
            c_2 += 1
        else:
            c_0 += 1
    print('Yes' if c_4 >= c_0 else 'No')


if __name__ == '__main__':
    main()
# Judge status: Accepted
import sys 
input = lambda:sys.stdin.readline().strip()
l,r,d = map(int,input().split())
print(max((r//d)-(l-1)//d,0))
# Judge status: Accepted
A,B,C,D=map(int,input().split())
if B<C or D<A:
    print(0)
    exit()
else:
    start=max(A,C)
    end=min(B,D)
print(end-start)
# Judge status: Accepted
n = int(input())
s = list(input())
p=10**9+7

from collections import Counter

c = Counter(s)

ans = 1
for k,v in c.items():
    ans *=(v+1)%p

ans -=1
print(ans%p)
# Judge status: Accepted
N = int(input())
A = list(map(int, input().split()))

count = 0
buka = [0 for _ in range(N)]

for i in range(N-1):
    buka[A[i]-1] += 1

for k in range(N):
    print(buka[k])
# Judge status: Accepted
a = input()

for x in range(1<<3):
  s = a[0]

  for i in range(3):
    if x & (1<<i):
      s += '+'
    else:
      s += '-'
    s += a[i+1]

  if eval(s) == 7:
    print(s + '=7')
    exit()
# Judge status: Wrong Answer
N = int(input())
cnt = 0
N //= 2
while N:
    cnt += N//5
    N //= 5
print(cnt)
# Judge status: Accepted
a,b,k = map(int,input().split())
if 2*k>=b-a+1:
  for i in range(a,b+1):
    print(i)
else:
  for i in range(a,a+k):
    print(i)
  for i in range(b-k+1,b+1):
    print(i)
# Judge status: Accepted
N=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
plus=0
minus=0
gomi=0
for i in range(N):
  if(a[i]-b[i]<0):
    minus+=((b[i]-a[i])//2)*2
  else:
    plus+=a[i]-b[i]
if(minus>=plus*2):
  print("Yes")
else:
  print("No")
# Judge status: Wrong Answer
n = int(input())
a = list(map(int,input().split()))
ruiseki_WA=[0]
for i in range(n):
    ruiseki_WA.append(ruiseki_WA[i]+a[i])
ans=114514
for i in range(n):
    kari=abs(ruiseki_WA[i]-(ruiseki_WA[-1]-ruiseki_WA[i]))
    ans=min(ans,kari)
print(ans)
# Judge status: Wrong Answer
n,m=map(int,input().split())
A=[]
for i in range(m):
    A.append(int(input()))

x=[0]*(n+1)
x[0]=1
if 1 in A:
    x[1]=0
else:
    x[1]=1

for j in range(2,n+1):
    if j in A:
        x[j]=0
    else:
        x[j]=x[j-1]+x[j-2]
        x[j]%1000000007

print(x[n])
# Judge status: Accepted
n,a,b=map(int,input().split())
if a%2==b%2:
    print((b-a)//2)
    exit()
if a-1<n-b:
    print(a+(b-a-1)//2)
else:
    print(n-b+1+(b-a-1)//2)
# Judge status: Wrong Answer
n = int(raw_input())
ais = map(int, raw_input().split())
ais.sort()

def f(ais):
	if len(ais) % 2:
		return [ais[len(ais)/2]]
	
	v = ais[len(ais)/2 -1] + ais[len(ais)/2]
	return [v/2,v/2-1,v/2+1]
meds = f(ais)

def g(ais,m):
	s= 0
	for v in ais:
		s+=abs(v-m)**2
	return s
print min([g(ais,m) for m in meds])
# Judge status: Wrong Answer
N = int(input())
A = [input() for i in range(N)]

print('AC × {}'.format(A.count('AC')))
print('WA × {}'.format(A.count('WA')))
print('TLE × {}'.format(A.count('TLE')))
print('RE × {}'.format(A.count('RE')))
# Judge status: Accepted
A,B = map(int,input().split())

print("Yes" if A==B else "No")
# Judge status: Accepted
from collections import deque
n,k = map(int,input().split())
r,s,p = map(int,input().split())
t = list(input())
points = {"r":r,"s":s,"p":p}
d = {"r":"p","s":"r","p":"s"}
que = deque([None]*k)
ans = 0
for ti in t:
    x = que.popleft()
    if d[ti] != x:
        #print(d[ti])
        que.append(d[ti])
        ans+=points[d[ti]]
    else:
        #print(None)
        que.append(None)
    #que.popleft()
    #print(que,ti)
print(ans)
# Judge status: Accepted

from collections import Counter
def resolve():
    MOD = 998244353
    N = int(input())
    D = list(map(int, input().split()))

    if D[0] != 0:
        print(0)
        return

    CNT = Counter(D)
    if CNT[0] > 1:  # 距離0は1個
        print(0)
        return

    ans = 1
    for i in range(1, max(D) + 1):
        ans *= pow(CNT[i - 1], CNT[i], MOD)
        ans %= MOD

    print(ans)


if __name__ == "__main__":
    resolve()
# Judge status: Accepted
# ABC168B

k = int(input())
s = input()

print(s if len(s) <= k else s[:k] + '...')
# Judge status: Accepted
n,t=map(int,input().split())
ans=[]
for i in range(n):
    a,b=map(int,input().split())
    if b<=t:
        ans.append(a)
if ans==[]:
    print("TLE")
else:
    print(min(ans))
# Judge status: Accepted
import bisect
import sys
input = sys.stdin.readline

N,X = list(map(int,input().split()))
L = list(map(int,input().split()))
bn = [0]
for i in range(N):
    bn.append(bn[-1]+L[i])
print(bisect.bisect_right(bn,X))
# Judge status: Accepted
N, M = map(int, input().split(' '))
lis1 = list(map(int, input().split(' ')))
S = sum(lis1)
thresh = S / (4 * M)
lis2 = sorted(lis1)
if lis2[-M] < thresh:
  print('No')
else:
  print('Yes')
# Judge status: Accepted
n,k=[int(i) for i in input().split()]
a=[0]*n

for i in range(k):
    d=int(input())
    motteru=[int(i) for i in input().split()]
    for j in motteru:
        a[j-1]+=1
print(a.count(0))
# Judge status: Accepted
def test():
	mod = 10**9 + 7
	n, m = map(int, input().split())
	if abs(n-m) > 1:
		print(0)
		exit()
	i_n = n
	i_m = m
	np = 1
	mp = 1
	while True:
		np = (np%mod) * (i_n%mod)
		mp = (mp%mod) * (i_m%mod)
		i_n -= 1
		i_m -= 1
		if i_n < 1:
			i_n = 1
		if i_m < 1:
			i_m = 1
		if i_n == 1 and i_m == 1:
			break
	s = 2 if n == m else 1
	r = (mp*np*s) % (10**9 + 7)
	print(r)
test()
# Judge status: Accepted
import math
n, k = map(int,input().split())
a = list(map(int,input().split()))

print(math.ceil((n-1)/(k-1)))
# Judge status: Accepted
import math

N, K = map(int, input().split())
print(int(math.log(N, K) + 1))
# Judge status: Wrong Answer
s = input()
q = int(input())

for i in range(q):
    query = input()
    try:
        int(query)
        t = query
    except:
        t, f, c = query.split()

    if t == "1":
        s = s[-1] + s[1:-1] + s[0]
    else:
        if f == "1":
            s = c + s
        else:
            s = s + c

print(s)
# Judge status: Wrong Answer
def calc(n):
  return (n+1)/2.0

N,K=map(int,input().split())
P=list(map(int,input().split()))
Q=list(map(calc,P))
print(Q)
cnt=0.0
for i in range(N-K+1):
  S=sum(Q[i:i+K])
  cnt=max(cnt,S)

print(cnt)
# Judge status: Wrong Answer
N = int(input())
s = ''
s2 = ''
while N != 0:
  if N % 2 == 0:
    s += '0'
    N //= (-2)
  if N % 2 == -1 or N % 2 == 1:
    s += '1'
    N //= (-2)
    N += 1
s2 = s[::-1]
print(s2)
# Judge status: Accepted

n=list(input())

print('Yes' if '9' in n else 'No')
# Judge status: Accepted
import numpy as np

N = int(input())
A = np.array(tuple(map(int, input().split())))
if N == 2:
    print(*A)
else:
    max_A = A.max()
    print(max_A, A[np.abs(A - max_A / 2).argmin()])
# Judge status: Accepted
n = int(input())

count = (n // 1000)
money = count * 1000

if money < n:
  print((count+1) * 1000 -n)
else:
  print((count) * 1000 -n)
# Judge status: Accepted
s = str(input())
k = int(input())
for i in range(k):
    if s[i] != "1":
        print(s[i])
        exit()
print("1")
# Judge status: Accepted
import sys

if __name__ == "__main__":
    N, M, K = [int(x) for x in input().split(" ")]
    if M < N:
        N, M = M, N
    for x in range(0, N + 1):
        for y in range(0, M + 1):
            if x * (M - y) + (y * (N - x)) == K:
                print("Yes")
                sys.exit(0)
    print("No")
# Judge status: Accepted
n = int(input())
a = list(map(lambda x: int(x)-1, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

res = b[a[0]]
for i in range(1, n):
    res += b[a[i]]
    if a[i-1]+1 == a[i]:
        res += c[a[i-1]]
print(res)
# Judge status: Accepted
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a
  
N,X = map(int,input().split())
A = list(map(int,input().split()))
B = [abs(X-i) for i in A]
ans = B[0]
for j in B:
    ans = gcd(ans, j)
print(ans)
# Judge status: Wrong Answer
N = int(input())
tannis = [1]

i = 1
while 6**i < N:
    tannis.append(6**i)
    i += 1

i = 1
while 9**i < N:
    tannis.append(9**i)
    i += 1

dp = [float('inf') for _ in range(N+1)]
dp[0] = 0

for i in range(1, N+1):
    for t in tannis:
        if i-t >= 0:
            dp[i] = min(dp[i], dp[i-t]+1)

#print(dp)
print(dp[N])
# Judge status: Wrong Answer
n = int(input())
a = [int(i) for i in input().split()]
m = len(list(filter(lambda x: x < 0, a)))
s = sum(map(abs, a))
if m % 2 == 0 or 0 in a:
    print(s)
else:
    print(s - 2 * min(a))
# Judge status: Accepted
S=str(input())
print('A'+S[8]+'C')
# Judge status: Accepted
#18:31
#Bugged
n=int(input())
s=[]
t=[0]*n
for i in range(n):
    a=int(input())
    s.append(a)
    if a%10!=0:
        t[i]=a

pt=sum(s)
s=sorted(s)
t=sorted(t)

for i in range(n):
    if pt%10==0:
        pt-=t[0]
        t.pop(0)   
if pt%10!=0:
    print(pt)
else:
    print(0)
# Judge status: Accepted
a, b, x = map(int, input().split())

if b > x:
    print(a*x//b)
else:
    print(a*(b-1)//b)
# Judge status: Wrong Answer
n=int(input())
l_b=2
l=1
if n=="1":
  print("2")
elif n=="2":
  print("1")
else:
  for i in range(3,n+1):
    l_bb=l_b
    l_b=l
    l=l_b+l_bb
  print(l)
# Judge status: Accepted
s = input()
if s[3] == '7':
  ans = s[:3] + '8' + s[4:]
else:
  ans = s
print(ans)
# Judge status: Wrong Answer
S = input()

mods = []
for i in range(len(S)):
    mod = int(S[i:]) % 2019
    mods.append(mod)

cnt = len(mods) - len(set(mods))
print(cnt)
# Judge status: Wrong Answer
import numpy as np

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

check = [i for i in range(1, n+1)]
ans = 1
for i in range(1, n+1):
  if not i in a:
    print(-1)
    break
  
  idx = np.where(a==i)[0][-1]
  ans += len(a[:idx]) - 1
  a = a[idx:]
  
  if len(a) == 1:
    print(ans)
    break
# Judge status: Accepted
n = int(input())

def divisor(n: int) -> list:
    list_of_divisor = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            list_of_divisor.append(i)
            if i != n//i:
                list_of_divisor.append(n//i)
    # list_of_divisor.sort()
    return list_of_divisor

ans = 0
for i in range(1, n+1, 2):
    li = divisor(i)
    if len(li) == 8:
        ans += 1

print(ans)
# Judge status: Accepted
from sys import stdin
def main():
    #入力
    readline=stdin.readline
    N=int(readline())
    li=[]
    for i in range(N):
        ab=list(map(int,readline().split()))
        li.append(ab)
    
    li.sort(key=lambda x:x[1])
    t=0
    for i in range(N):
        task=li[i]
        t+=task[0]
        if t>task[1]:
            print("No")
            break
    else:
        print("Yes")
if __name__=="__main__":
    main()
# Judge status: Wrong Answer
def main():
    N, K = list(map(int, input().split()))
    field = list(map(int, input().split()))

    dpList = [0] * N
    dpList[1] = abs(field[0] - field[1])

    for i in range(2, N):
        minCost = 1000000

        for j in range(1, min(K, i) + 1):
            minCost = min([minCost, dpList[i - j] + abs(field[i] - field[i - j])])

        dpList[i] = minCost

    print(dpList[-1])

if __name__ == "__main__":
    main()
# Judge status: Accepted
import itertools
pqr = list(map(int, input().split()))
print(min([a+b for a, b in itertools.combinations(pqr, 2)]))
# Judge status: Accepted
S = input()

flg = 1
for i in range(len(S)-1):
  if S[i] == S[i+1]:
    print("Bad")
    flg = 0
    break
if flg:
  print("Good")
# Judge status: Accepted
n,x=map(int,input().split())
a=list(map(int,input().split()))
dp=[0]*(n-1)
ans=0
for i in range(n-1):
  dp[i]=a[i]+a[i+1]
for j in range(n-2):
  if dp[j]>x:
    ans+=min(dp[j]-x,a[j+1])
    dp[j+1]-=min(dp[j]-x,a[j+1])
    dp[j]-=min(dp[j]-x,a[j+1])
if dp[n-2]>x:
  ans+=dp[n-2]-x
  dp[n-2]-=dp[n-2]-x
if dp[0]>x:
  ans+=dp[0]-x
  dp[0]-=dp[0]-x
print(ans)
# Judge status: Accepted
import math
a,b,c,d=map(int,input().split())
def gcd(a,b):
    if b>a:
        b,a=a,b
    if b==0:
        return a
    else:
        return gcd(b,a%b)
def warikiri(n,c,d):
    koubai=(c*d)//gcd(c,d)
    return n-n//d-n//c+n//koubai
print(warikiri(b,c,d)-warikiri(a-1,c,d))