peterverebics/CodeNet_Python_428 huggingface dataset:
# Judge status: Accepted
def mi(): return map(int,input().split())
def lmi(): return list(map(int,input().split()))
def ii(): return int(input())
def isp(): return input().split()

n=ii()
a=lmi()
INF=10**9+7
ans=0
for i in range(60):
  x=0
  for j in range(n):

    if (a[j]>>i)&1:
      x+=1

  num=x*(n-x)*2**i
  ans+=num

print(ans%INF)
# Judge status: Wrong Answer
N = int(input())
arr = [list(map(int, input().split())) for i in range(N)]

ans = 0
for i in range(N - 1, -1, -1):
    a, b = arr[i]
    if b == 1:
        continue
    a += ans
    ans += b - (a % b)

print(ans)
# Judge status: Accepted
a,b,c = map(int,input().split())
if c <= a + b: print('Yes')
else: print('No')
# Judge status: Accepted
from itertools import combinations
n,x,y = map(int,input().split())
x -= 1
y -= 1
ans = [0]*n
for i,j in combinations(range(n),2):
  dist = min(j-i,abs(i-x)+abs(j-y)+1)
  ans[dist-1] += 1
anss = ans[:n-1]
print(*anss,sep="\n")
# Judge status: Accepted
n = int(input())
if n % 2 == 1:
    print(0)
else:
    d = list(map(int, input().split()))
    num = n // 2
    d_sort = sorted(d)
    print(d_sort[num] - d_sort[num - 1])
# Judge status: Accepted
s=input().split()
b = {}
a = list(map(int, input().split()))

for i in range(2):
  b[s[i]] = a[i]
  
b[input()] -=1

print(str(b[s[0]])+" "+str(b[s[1]]))
# Judge status: Accepted
import sys
def input():
    return sys.stdin.readline()[:-1]
N=int(input())
A=[0]*N
B=[0]*N
for i in range(N):
    a,b=map(int,input().split())
    A[i]=a
    B[i]=b
A.sort()
B.sort()
if N%2:
    print(B[N//2]-A[N//2]+1)
else:
    a=A[N//2-1]+A[N//2]
    b=B[N//2-1]+B[N//2]
    print(b-a+1)
# Judge status: Accepted
N,K = map(int,input().split())

ans = 1
while N >= K:
    ans += 1
    N = N // K

print(ans)
# Judge status: Wrong Answer
n, a,b = [int(x) for x in input().split()]
total = 0
def func(num):
  r = 0
  while num > 0:
    r = num % 10
    num = num // 10
  return r

for i in range(1, n+1):
  num = func(i)
  if num >= a and num <= b:
    total += num
print(total)
# Judge status: Accepted
import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy

N = int(input())


def ok():
    x = 0
    while x * 4 <= N:
        if (N - x * 4) % 7 == 0:
            return True
        x += 1
    return False

print("Yes" if ok() else "No")
# Judge status: Wrong Answer
import numpy as np
a, b = list(map(int, input().split()))
s = np.sum(list(map(int, input().split())))
print(np.max(a-s, -1))
# Judge status: Accepted
S=input();s=set(S);print('NYoe s'[len(s)==2 and S.count(list(s)[0])==2::2])
# Judge status: Accepted
#B問題
a=int(input())
sum=0
for i in range(1,a+1):
    if(i%3!=0 and i%5!=0):
        sum+=i
print(sum)
# Judge status: Accepted
H,N = map(int, input().split())
magic = [list(map(int,input().split())) for _ in range(N)]

max_damage = max(damage for damage, cost in magic)
dp = [0] * (H + max_damage)

for x in range(1, H + max_damage):
    dp[x] = min(dp[x - damage] + cost for damage, cost in magic)
    
ans = min(dp[H:])

print(ans)
# Judge status: Accepted
N = int(input())
S = input()

ans = 0
for i in range(2, N):
  fw = set(S[:i])
  bk = set(S[i:])
  len_S = len(fw & bk)
  ans = max(ans, len_S)
  
print(ans)
# Judge status: Accepted
x = list(map(int,input().split()))
for i in range(5):
    if x[i] == 0:
        print(i+1)
        exit()
# Judge status: Accepted
def main():
    n = int(input())
    A = [int(x) for x in input().split()]
    a0 = A.pop(0)
    ans = A[1:n:2][::-1] + [a0] + A[0:n:2]
    if n % 2 == 0:
        print(' '.join([str(a) for a in ans[::-1]]))
    else:
        print(' '.join([str(a) for a in ans]))

if __name__ == '__main__':
    main()
# Judge status: Wrong Answer
import itertools

N = int(input())
P = [int(x) for x in input().split()]
P = tuple(P)
Q = [int(x) for x in input().split()]
Q = tuple(Q)
N_ = list(range(1, N+1))

R = list(itertools.permutations(N_))

Pflg = Qflg = False
Pcnt = Qcnt = -1
for i, r in enumerate(R):
    print(r)
    if P==r:
        Pflg = True
        Pcnt = i
    if Q==r:
        Qflg = True
        Qcnt = i
    if Pflg and Qflg:
        break

print(abs(Pcnt - Qcnt))
# Judge status: Wrong Answer
n=int(input())
a=list(map(str,input().split()))
b,c=[],[]
if n%2==0:
    for i in range(n):
        if i%2==0:
            b.append(a[i])
        else:
            c.append(a[i])
    c.reverse()
    print(" ".join(b+c))
else:
    for i in range(n):
        if i%2==1:
            b.append(a[i])
        else:
            c.append(a[i])
    c.reverse()
    print(" ".join(c+b))
# Judge status: Wrong Answer
import math

is_no = 0
num1, num2 = map(int, input().split())
str1 = input()
table = list(str1)
for i in range(num1):
    if table[i].isdigit():
        continue
    else:
        is_no = 1
if table[num1] != '-':
    is_no = 1
for j in range(num2, num1+num2+1):
    if table[j].isdigit():
        continue
    else:
        is_no = 1
if is_no == 0:
    print('Yes')
elif is_no == 1:
    print('No')
# Judge status: Accepted
a,b=map(int,input().split())
List=list(map(int,input().split()))
List=sorted(List)
p=0
for i in  range(0,b):
    p+=List[i]
print(p)
# Judge status: Wrong Answer
tosi = int(input('お子さんの年齢を入力してください'))

if tosi == 7 or tosi == 5 or tosi == 3:
    print('yes')

else:
    print('no')
# Judge status: Wrong Answer
string_input=list(input())
string_output=[]
print(string_input)

for i in range(0,len(string_input)-1):
    if string_input[i+1]!="B" and string_input[i]!="B" :
        string_output.append(string_input[i])
        print(string_output)
        
    elif string_input[len(string_input)-1]!="B": #and string_input[len(string_input)-2]!="B":
        string_output.append(string_input[len(string_input)-2])
        string_output.append(string_input[len(string_input)-1])
        
        
    
print(string_output)

string_input=''.join(string_input)
print(string_input)
# Judge status: Accepted
a,b,c,x,y=map(int,input().split())
if a+b<=2*c: print(a*x+b*y)
else:
    ans=min(x,y)*2*c
    dif=abs(x-y)
    if x>y:
        if a>=2*c:
            ans+=2*dif*c
        else:
            ans+=a*dif
    else:
        if b>=2*c:
            ans+=2*dif*c
        else:
            ans+=b*dif
    print(ans)
# Judge status: Accepted
import sys
from collections import defaultdict

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, *A = map(int, read().split())

    d = defaultdict(bool)
    for a in A:
        if d[a]:
            d[a] = False
        else:
            d[a] = True

    ans = sum(1 for f in d.values() if f)
    
    print(ans)
    return


if __name__ == '__main__':
    main()
# Judge status: Accepted
n = int(input())
array = list(map(int, input().strip().split(" ")))
ans = [0]*n

for i in range(n):
    ans[array[i] - 1] = str(i + 1 )



print(" ".join(ans))
# Judge status: Accepted
a,v=map(int,input().split())
b,w=map(int,input().split())
t=int(input())

if a==b:
    print('YES')
elif v<=w:
    print('NO')
elif abs(a-b)/ abs(v-w) <= t:
    print('YES')
else:
    print('NO')
# Judge status: Accepted
# -*- coding: utf-8 -*-


N = int(input())
output = [0]*N

A= []
for i in range(N):
    A.append(input())

print(len(set(A)))
# Judge status: Accepted
x,y,a,b,c=map(int,input().split())
la=list(map(int,input().split()))
lb=list(map(int,input().split()))
lc=list(map(int,input().split()))
la=sorted(la,reverse=True)
lb=sorted(lb,reverse=True)
lc=sorted(lc,reverse=True)
for i in range(a-x):
    la.pop(-1)
for j in range(b-y):
    lb.pop(-1)
l=[]
for ii in range(x):
    l.append(la[ii])
for jj in range(y):
    l.append(lb[jj])
for kk in range(c):
    l.append(lc[kk])
l=sorted(l,reverse=True)
print(sum(l[0:x+y]))
# Judge status: Accepted
S = input()
dic = {}

for s in S:
  dic[ord(s)] = True
  
for i in range(97, 97+26):
  if i not in dic:
    print(chr(i))
    exit()

print('None')
# Judge status: Accepted
from collections import Counter
N = int(input())
S = [input() for _ in range(N)]
cntr = Counter(S)
mc = cntr.most_common()
n = mc[0][1]
ans = []
for k, v in mc:
    if n!=v:
        break
    ans.append(k)
ans.sort()
print("\n".join(ans))
# Judge status: Accepted
n,k=map(int,input().split())
a=list(map(int,input().split()))
for i in range(n-k):
  if a[k+i]>a[i]:
    print("Yes")
  else:
    print("No")
# Judge status: Accepted
N, L = map(int, input().split())
taste = [L+i-1 for i in range(1,N+1)]
abs_taste = [abs(i) for i in taste]
taste.pop(abs_taste.index(min(abs_taste)))
print(sum(taste))
# Judge status: Accepted
n = int(input())
print("Yes" if any((n - i*7) % 4 == 0 for i in range(n // 7 + 1)) else "No")
# Judge status: Wrong Answer
import math

def jds(strin):
    js = 0
    newSt = strin[::-1]
    if strin == newSt:
        js +=1
    return js
 
a = input()
jud = 0

leee = len(a)

if leee % 2 == 0:
    b = a[:math.ceil((len(a) - 1) / 2)]
    c = a[math.floor((len(a) + 1) / 2):]
else:
    b = a[:int((len(a) - 1) / 2)]
    c = a[int((len(a) + 2) / 2):]
 
jud += jds(a) + jds(b) + jds(c)
 
print(jud)
if jud == 3:
    print("Yes")
else:
    print("No")
# Judge status: Accepted
n=int(input())
A=[int(input()) for _ in range(n)]
maxm=sorted(A)
for i in range(n):
    if A[i]==maxm[-1]: print(maxm[-2])
    else: print(maxm[-1])
# Judge status: Accepted
n, m = map(int, input().split())
li = [True]*(n+1)

for i in range(m):
    a = int(input())
    li[a] = False

dan = [0]*(n+1)
dan[0] = 1

for j in range(1,n+1):
    if li[j]:
        dan[j] += dan[j-1]
        if j >= 2:
            dan[j] += dan[j-2]

print(dan[n]%(10**9+7))
# Judge status: Accepted
x_list = list(map(int,input().split()))
for i in range(5):
  if x_list[i] ==0:
    print(i+1)
# Judge status: Accepted
n = int(input())
h = list(map(int, input().split()))
h = [0] + h

a = [0] * (n+1)
a[1] = 0
a[2] = abs(h[1]-h[2])
for i in range(3, n+1):
    a[i] = min(a[i-2]+abs(h[i-2]-h[i]), a[i-1]+abs(h[i-1]-h[i]))
print(a[n])
# Judge status: Wrong Answer
import math
n = int(input())
root = int(math.sqrt(n))
ans = 0
flag = 0
for i in range(1, root+1):
    if n % i == 0:
        flag = 1
        ans = int((n/i)) + i - 2
        break
print(ans)
# Judge status: Accepted
def main():
    N = int(input())
    AB = [[int(i) for i in input().split()] for j in range(N)]
    AB.sort(key=lambda p: p[1])
    time = 0
    for a, b in AB:
        time += a
        if time > b:
            return print("No")
    print("Yes")


if __name__ == '__main__':
    main()
# Judge status: Wrong Answer
a=int(input())	

if 400 <= a < 599:
  print(8)
elif 600 <= a < 799:
  print(7)
elif 800 <= a < 999:
  print(6)
elif 1000 <= a < 1199:
  print(5)
elif 1200 <= a < 1399:
  print(4)
elif 1400 <= a < 1599:
  print(3)
elif 1600 <= a < 1799:
  print(2)
elif 1800 <= a < 2000:
  print(1)
# Judge status: Accepted
import fractions

n, x = map(int, input().split())
l = list(map(int, input().split()))
z = [abs(x - i) for i in l]

ans = z[0]
for i in range(1, n):
    ans = fractions.gcd(ans, z[i])
print(ans)
# Judge status: Wrong Answer
import numpy as np
N, M = map(int, input().split())
H = list(map(int, input().split()))

ans = np.array(list(range(N)))

for _ in range(M):
  A, B = map(int, input().split())
  if H[A-1] >= H[B-1]:
    ans[B-1] = -1
  elif H[A-1] <= H[B-1]:
    ans[A-1] = -1
print(len(ans[ans!=-1]))
# Judge status: Accepted
S = input()
FA = S.find('A')
LZ = S.rfind('Z')
print(LZ-FA+1)
# Judge status: Accepted
import sys

N = int(sys.stdin.readline())
S = sys.stdin.readline()

right = S[1:].count("E")
left = 0
ans = [0]*N
ans[0] = right + left
for i in range(1, N):
    if S[i] == "E":
        right = right - 1
    if S[i-1] == "W":
        left = left + 1
    ans[i] = right+left

print(min(ans))
# Judge status: Wrong Answer
a, b, c = map(int, input().split())

if b == max(a, b, c) or b == min(a, b, c):
	print('Yes')
else:
	print('No')
# Judge status: Accepted
S = str(input())

if S[0]!=S[1] and S[1]!=S[2] and S[2]!=S[0]:
    print("Yes")
else:
    print("No")
# Judge status: Wrong Answer
N = 11
def func(n):
  for i in range(1,10):
    for j in range(1,10):
      if n ==i*j:
        print("Yes")
        return i,j
  if n != i*j:
    print("No")

func(N)
# Judge status: Accepted
n = int(input())
p = list(map(int,input().split()))
count = 0

sort_p = sorted(p)

for i in range(n):
  if p[i] != sort_p[i]:
    count += 1
    
if count  == 2:
  print("YES")
  exit()
elif count == 0:
  print("YES")
  exit()
else:
  print("NO")
  exit()
# Judge status: Accepted
s = int(input())
tar = s
used = [s]
for i in range(2,int(1e8)):
    if tar % 2 == 0:
        tar = tar//2
    else:
        tar = tar*3+1
    if tar in used:
        print(i)
        exit()
    else:
        used.append(tar)
# Judge status: Accepted
import datetime as dt
S=input()
s=dt.datetime.strptime(S,'%Y/%m/%d')
A='2019/04/30'
a=dt.datetime.strptime(A,'%Y/%m/%d')
if s<=a:
    print('Heisei')
else:
    print('TBD')
# Judge status: Wrong Answer
N, K = map(int, input().split())
S = input()

unhappy = 0
if S[0] == "L":
    unhappy += 1
if S[-1] == "R":
    unhappy += 1
for i in range(1, N-1):
    if S[i:i+2] == "RL":
        unhappy += 2

if unhappy > 2:
    if unhappy > K:
        print(N-(unhappy-2*K))
    else:
        print(N-1)
else:
    print(N-1)
# Judge status: Wrong Answer
N = input()
lenN = len(N)
cnt = 0
  
for i in range(0,lenN-3):
  for j in range(i + 3,i + 3 + 6):
    if j > lenN :
      break
    p = int(N[i:j])
    if p % 2019 == 0:
      cnt += 1

print(cnt)
# Judge status: Wrong Answer
a,b,c = map(int, input().split())
if a >= b*c :
  print('Yes')
elif a < b*c :
   print('No')
# Judge status: Accepted
k = int(input())
a = k//2
b = k//2 + k%2
print(a*b)
# Judge status: Wrong Answer
a,b,c=sorted(map(int,input().split()))
if a+b==c:
  print('YES')
else:
  print('NO')
# Judge status: Wrong Answer
N, K = map(int, input().split())
sum(sorted(map(int, input().split()), reverse=True)[K:])
# Judge status: Wrong Answer
n = int(input())
if n % 2 == 1 or n < 10:
    print(0)
else:
    k = n // 5
    print(k * (k + 1) / 2)
# Judge status: Accepted
a,b = map(int,input().split())

x = [''] * 2
for i in range(b):
  x[0] += str(a)
for i in range(a):
  x[1] += str(b)

print(sorted(x)[0])
# Judge status: Wrong Answer
n, a, b = map(int,(input().split()))

if (a + b) % 2 == 0:
    print((a+b)//2 - a)

else:
    print(min(b-1,n-a))
# Judge status: Wrong Answer
S = input()
T = input()
flag = 0
for i in range(len(S)):
    now = S[-(i+1):]+S[0:len(S)-i-1] 
    if now == T:
        print("Yes")
        flag += 1
if flag == 0:
    print("No")
# Judge status: Accepted
n = int(input())
l = [list(map(int,input().split())) for i in range(n)]
ans = 0

for i,j in l[::-1]:
    ans += (j-(i+ans)%j)%j
print(ans)
# Judge status: Accepted
a = input().split()
a.sort()
b = int(a[2] + a[1])
c = int(a[0])
print(b + c)
# Judge status: Wrong Answer
S = list(input())
K = int(input())
for i in range(min(len(S),K)):
    if S[i] != 1:
        print(S[i])
        exit()
print(1)
# Judge status: Wrong Answer
n,m = map(int, input().split())
judge = [i for i in range(1, m+1)]
for i in range(n):
    a = list(map(int, input().split()))
    a.pop(0)
    for j in judge:
        if not j in a:
            judge.remove(j)
print(len(judge))
# Judge status: Accepted
C = input()

ref = list('abcdefghijklmnopqrstuvwxyz')

i = ref.index(C)

print(ref[i+1])
# Judge status: Wrong Answer
L = int(input())

if L > 3:
  print((L**3)/27)
else:
  print(L)
# Judge status: Accepted
A, B  = map(int, input().split())
ans = 0

ans = ans + max(A, B)
if A >= B:
  A = A-1
else:
  B = B-1

ans = ans + max(A, B)
print(ans)
# Judge status: Wrong Answer
def abc126c():
    import math
    n, k = map(int, input().split())
    ans = 0.0
    for i in range(1, min(k, n + 1)):
        v = math.ceil(math.log2(k / i))
        print(v)
        ans += math.pow(0.5, v)
    if n > k:
        ans += n - k + 1
    print((1 / n) * ans)


abc126c()
# Judge status: Accepted
# -*- coding: utf-8 -*-
"""
Created on Fri May 15 00:48:45 2020

@author: Kanaru Sato
"""

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

ans = c-a+b
if ans <= 0:
    print(0)
else:
    print(ans)
# Judge status: Wrong Answer
x, y, z = map(int, input().split())
ans = 0

while True:
    x -= z
    if x <= 0:
        print(ans)
        exit()
    x -= y
    if x <= 0:
        print(ans)
        exit()
    ans += 1
# Judge status: Wrong Answer
N,A,B=map(int,input().split())
 
Alltotal=0
for i in range(1,N+1):
  partTotal=0
  while i!=0:
    partTotal+=i%10
    i=i//10
    
  if A<=partTotal and partTotal<=B:
    Alltotal+=partTotal
# Judge status: Wrong Answer
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

from collections import Counter

n = int(readline())
d = tuple(map(int, readline().split()))
counter = Counter(d)
max_d = max(d)
mod = 998244353
ans = 1
if d[0] != 0 or counter[0] > 1:
    print(0)
    exit()
for i in range(1, max_d + 1):
    if counter[i] == 0:
        print(0)
        exit()
    ans *= pow(counter[i - 1], counter[i], mod) % mod
print(ans)
# Judge status: Wrong Answer
N=int(input())
N=str(N)
N = (N[-1])
if (N==2 or 4 or 5 or 7 or 9):
  print("hon")
elif (N==0 or 1 or 6 or 8):
  print("pon") 
else :
  print("bon")
# Judge status: Wrong Answer
N, K = list(map(int,input().split()))
xlist = list(map(int,input().split()))

def f(list1):
  min1 = list1[0]
  max1 = list1[-1]
  if min1>=0 and max1>=0:
    return abs(max1)
  elif min1<=0 and max1 <=0:
    return abs(min1)
  else:
    return min([-2*min1 + max1,-min1 + 2*max1])

ans = 2*10**8 + 2
for i in range(N-K+1):
  dist =f (xlist[i:i+K]) 
  if dist < ans :
    ans = dist

print(ans)
# Judge status: Wrong Answer
INF = 1000000000

h, n = map(int, input().split())
AB = [list(map(int, input().split())) for i in range(n)]

maxA = max(AB[:][0])

dp = [INF for i in range(h+maxA+1)]
dp[0] = 0

for i in range(1, h+maxA+1):
    for ab in AB:
        a, b = ab[0], ab[1]
        if i-a >= 0:
            dp[i] = min(dp[i], dp[i-a] + b)

ans = min(dp[h:])

print(ans)
# Judge status: Wrong Answer
n = int(input())
A = list(map(int, input().split()))

MOD = 1e9+7
ans = 0

for i in range(60):
    cnt = 0
    for a in A:
        cnt += a>>i&1
    ans += cnt*(n-cnt)*2**i
    ans %= MOD

print(ans)
# Judge status: Accepted
n, m = map(int, input().split())
nums = [list(map(int, input().split())) for _ in range(m)]

for i in range(1000):
  is_ok = True
  num_str = str(i)
  if len(num_str) != n:
    continue
  for s, c in nums:
    if num_str[s-1] != str(c):
      is_ok = False
      break
  if is_ok:
    print(num_str)
    exit(0)
print(-1)
# Judge status: Accepted
S = input().split()
print(S[0][0]+S[1][0]+S[2][0])
# Judge status: Wrong Answer
a,b,c,d = map(int, input().split())
if abs(a-b) <= d and abs(b-c) <= d:
    print('Yes')
else:
    print('No')
# Judge status: Wrong Answer
n,*a=map(int,open(0).read().split())
for i in range(n-1):
  a.sort()
  _min=a[-1]
  jj,kk=0,0
  for j,k in zip(a,a[1:]):
    if _min>min(_min,k-j):
      _min=min(_min,k-j)
      jj,kk=j,k  
  a.remove(jj)
  a.remove(kk)
  a.append((jj+kk)/2)
print(int(a[0]))
# Judge status: Wrong Answer
a, b = input().split()
if a or b > 8:
  print(":(")
else:
  print("Yay!")
# Judge status: Wrong Answer
s = str(input())
mlist = []
for i in range(1, 100):
  m = i * 2019
  mlist.append(str(m))
mcount = 0
flist = []
for j in mlist:
  count = s.count(j)
  if count > 0:
    flist.append(j)
for k in flist:
  fcount = 0
  for l in range(len(s) - len(k) + 1):
    fs = s.count(k, l, l + len(k))
    if fs > 0:
      fcount += fs
  if fcount > 0:
    mcount += fcount 
print(mcount)
# Judge status: Accepted
a,b = map(int,input().split())
l = [a,b,a-1,b-1]
l.sort(reverse=1)
print(l[0]+l[1])
# Judge status: Accepted
import re
a,b = input().split()
s = input()
if re.match(r'\d{' + a + '}-\d{' + b + '}', s):
    print('Yes')
else:
    print('No')
# Judge status: Accepted
from math import ceil

n, hp = map(int, input().split())
A = []
B = []
for _ in range(n):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)
MAX_A = max(A)
B.sort(reverse=True)

cnt = 0
for b in B:
    if b > MAX_A:
        hp -= b
        cnt += 1
    else:
        break
    if hp <= 0:
        break
if hp > 0:
    cnt += ceil(hp / MAX_A)
print(cnt)
# Judge status: Accepted
import sys
import fractions

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N = ir()
NS = list(str(N))

q, mod = divmod(N, 10)
i = -1
while q:
    if mod < 8:
        NS[i:] = ['9' for i in range(-i)]
        NS[i-1] = str(int(NS[i-1]) - 1)
    i -= 1
    q, mod = divmod(q, 10)

print(sum(map(int, NS)))
# Judge status: Wrong Answer
s=input()
a=[]
for i in range(len(s)//2):
  a.append(s[i:i+2])
a10=a.count('10')
a01=a.count('01')

if len(s)%2:
  s1=int(s[-1])
else:s1=-1

if a10>a01:
  if s1==0:
    cnt=len(a)-a10+a01+1
  else:
    cnt=len(a)-a10+a01
else:
  if s1==1:
    cnt=len(a)-a01+a10+1
  else:
    cnt=len(a)-a01+a10
print(cnt)
# Judge status: Wrong Answer
import copy
N=int(input())
alp="abcdefghijklmnopqrstuvwxyz"
l=["a"]
now=[]
flag=0
now=[]

if N==1:
    print(l[0])
    flag=1
else:
    for x in range(N-1):
        for i in range(len(l)):
            now.append(l[i]+"a")
            now.append(l[i]+"b")
        l=copy.deepcopy(now)
        now=[]



if flag!=1:
    l.sort()
    for i in l:
        print(i)
# Judge status: Accepted
n, m = map(int, input().split())
li = [0]*200001
s = "IMPOSSIBLE"
for i in range(m):
    a, b = map(int, input().split())
    if a == 1:
        if li[b] == 0:
            li[b] = 1
        else:
            s = "POSSIBLE"
    
    if b == n:
        if li[a] == 0:
            li[a] = 1
        else:
            s = "POSSIBLE"

print(s)
# Judge status: Accepted
import bisect

n = int(input())

c = []
for i in range(n):
    a = int(input())
    j = bisect.bisect_right(c, -a)
    if j == len(c):
        c.append(-a)
    else:
        c[j] = -a
print(len(c))
# Judge status: Wrong Answer
A, B, M = map(int, input().split())
# items
a = list(map(int, input().split()))
b = list(map(int, input().split()))
# discount
d = [list(map(int,input().split())) for i in range(M)]
max = 0
max_i = 0
for i in range(M):
  if d[i][2] > max:
    max = d[i][2]
    max_i = i

if min(a) + min(b) > a[d[max_i][0] - 1] + b[d[max_i][0] - 1] - d[max_i][2]:
  print(a[d[max_i][0] - 1] + b[d[max_i][0] - 1] - d[max_i][2])
else:
  print(min(a) + min(b))
# Judge status: Wrong Answer
N = int(input())
H = list(map(int, input().split()))

cnt = 0
for i in range(N-1):
	if H[i] >= H[i+1]:
		cnt += 1
	else:
		cnt = 0

print(cnt)
# Judge status: Accepted
import sys
import itertools
# import numpy as np
import time
import math
 
sys.setrecursionlimit(10 ** 7)
 
from collections import defaultdict
 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

n = int(input())
rs = []
for i in range(n):
    s, p = input().split()
    rs.append((s, -int(p), i))
rs = sorted(rs)


for r in rs:
    print(r[2] + 1)
# Judge status: Accepted
s = list(input())
t = input()

for i in range(len(s)):
    s.insert(0, s[-1])
    s.pop(-1)
    if "".join(s) == t:
        print("Yes")
        exit()
print("No")
# Judge status: Accepted
a, b, c, k = map(int, input().split())

if k<=a:
	ans = k
elif k<=a+b:
	ans = a
else:
	ans = a-(k-a-b)

print(ans)
# Judge status: Accepted
n, m = map(int,input().split())
l = [1]*m
for i in range(n):
  li = list(map(int,input().split()))[1:]
  for j in range(m):
    if j+1 not in li:
      l[j] = 0
print(sum(l))
# Judge status: Accepted
import itertools

def main():
    n, m, x = map(int, input().split())
    ca = [list(map(int, input().split())) for i in range(n)]
    INF = float('INF')
    res = INF
    for comb in itertools.chain(*(itertools.combinations(ca,r) for r in range(1,n+1))):
        c, *a = list(map(sum, zip(*comb)))
        if c < res and min(a) >= x:
            res = c
    if res == INF:
        print(-1)
    else:
        print(res)
if __name__ == '__main__':
    main()