Problem:


Score : 300 points

Problem Statement

Find the maximum possible sum of the digits (in base 10) of a positive integer not greater than N.

Constraints

1\leq N \leq 10^{16}

N is an integer.

Input

Input is given from Standard Input in the following format:

N

Output

Print the maximum possible sum of the digits (in base 10) of a positive integer not greater than N.

Sample Input 1

100

Sample Output 1

18

For example, the sum of the digits in 99 is 18, which turns out to be the maximum value.

Sample Input 2

9995

Sample Output 2

35

For example, the sum of the digits in 9989 is 35, which turns out to be the maximum value.

Sample Input 3

3141592653589793

Sample Output 3

137



Sample input:
100


Sample output:
18

Submission status: Wrong Answer

Solution code:
n=input()
l=len(n)
if(l==1):
    print(n)
elif(len(str(int(n)+1))==l):
     print((int(n[0])-1)+(l-1)*9)
else:
    print(l*9)

Submission status: Wrong Answer

Solution code:
Nin = input()
l = len(Nin)
fow = int(Nin[0])
print(fow-1+(l-1)*9)

Submission status: Wrong Answer

Solution code:
n=list(map(int,list(input())))
l=len(n)
s=0
for i in range(l-1,0,-1):
  if n[i]<8:
    s+=9
    if n[i-1]!=0:
      n[i-1]-=1
  else:
    s+=n[i]
print(s+n[0])

Submission status: Wrong Answer

Solution code:
n = int(input())

def digit(a):
    return sum(map(int,list(str(a))))

if n < 10:
    print(n)
else:
    n2 = list(str(n))
    ln = len(n2)

    if n == 10**ln - 1:
        print(9*ln)
    else:
        for i in range(ln):
            if i == 0:
                n2[0] = str(int(n2[0]) - 1)
                if n2[0] == "0":
                    n2[0] = ""
            else:
                n2[i] = "9"
        n2 = int("".join(n2))
        print(digit(n2))

Submission status: Wrong Answer

Solution code:
n = int(input())

def digit(a):
    return sum(map(int,list(str(a))))

if n < 10:
    print(n)
else:
    n2 = list(str(n))
    ln = len(n2)
    for i in range(ln):
        if i == 0:
            n2[0] = str(int(n2[0]) - 1)
            if n2[0] == "0":
                n2[0] = ""
        else:
            n2[i] = "9"
    n2 = int("".join(n2))
    print(digit(n2))

Submission status: Wrong Answer

Solution code:
n=input()
if len(n)==1:print(n)
elif n=="9"*len(n):print(9*len(n))
else:print(9*(len(n)-1)+int(n[0])-1)

Submission status: Wrong Answer

Solution code:
n = input()
s = 0
ans = 0
for i in range(len(n)):
    ans = max(int(n[i])-1 + (len(n)-i-1)*9 + s, ans)
    s+=int(n[i])
print(ans)

Submission status: Wrong Answer

Solution code:
n = input()
if n.count('9') == len(n):
    print(9*len(n))
else:
    print(9*(len(n)-1) + int(n[0])-1)

Submission status: Wrong Answer

Solution code:
n=input()
lenn=len(n)
#print(lenn)

n1=n[0]
n2=n[1:]

if n2.count('9')==lenn-1:
  ans=9*lenn
else:
  ans=int(n[0])-1+9*(lenn-1)
  
print(ans)

Submission status: Wrong Answer

Solution code:
n=input()
lenn=len(n)
#print(lenn)

n1=n[0]
n2=n[1:]

if n2.count('9')==lenn-1:
  ans=int(n)
else:
  ans=int(n[0])-1+9*(lenn-1)
  
print(ans)

Submission status: Wrong Answer

Solution code:
n=input()
lenn=len(n)
#print(lenn)

if n.count('9')==lenn:
  ans=int(n)
else:
  if lenn==1:
    ans=int(n)
  else:
    ns=n[1:]
    if ns.count('9')==lenn-1:
      ans=int(n)
    else:
      ans=int(n[0])-1+9*(len(n)-1)

print(ans)

Submission status: Wrong Answer

Solution code:
n=input()
lenn=len(n)
#print(lenn)

if n.count('9')==lenn:
  ans=int(n)
else:
  ans=int(n[0])-1+9*(len(n)-1)

print(ans)

Submission status: Wrong Answer

Solution code:
n=input()
print(int(n[0])-1+9*(len(n)-1))

Submission status: Wrong Answer

Solution code:
n = input()
l = len(n)

if set(list(n[1:])) == {"9"}:
    print(int(n[0])+9*(len(n)-1))
else:
    print(int(n[0])-1+9*(len(n)-1))

Submission status: Wrong Answer

Solution code:
N = input()

if len(N) == 1:
    print(int(N) - 1)
    exit()

a = str(int(N) - int(N[-1]) - 1)
b = '9' * (len(N) - 1)

A = 0
B = 0

for aa in a:
    A += int(aa)
for bb in b:
    B += int(bb)
if int(N[0]) > 1:
    B += int(N[0]) - 1

print(max(A, B))

Submission status: Wrong Answer

Solution code:
N = list(input())
N_order = len(N)
N_sort = sorted(N)

if N_order == 1:
    print(int(N[0]))
    exit()

if N_sort[0] == '9':
    print(9 * N_order)
    exit()

for i in range(1,10):
    if int(N[0]) <= i:
        ans = 9 * (N_order - 1) + i
        break

print(ans - 1)

Submission status: Wrong Answer

Solution code:
N = list(input())
N_order = len(N)
N_sort = sorted(N)
if N_sort[0] == '9':
    print(9 * N_order)
    exit()

for i in range(1,10):
    if int(N[0]) <= i:
        ans = 9 * (N_order - 1) + i
        break

print(ans - 1)

Submission status: Wrong Answer

Solution code:
def main():
    N = input()
    if len(N) == 1:
        print(N)
        return
    for d in N:
        if d != "9":
            ans = int(N[0]) - 1 + 9 * (len(N)-1)
            print(ans)
            return
    ans = 9 * len(N)
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
def main():
    N = input()
    for d in N:
        if d != "9":
            ans = int(N[0]) - 1 + 9 * (len(N)-1)
            print(ans)
            return
    ans = 9 * len(N)
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
def main():
    N = input()
    ans = int(N[0]) - 1 + 9 * (len(N)-1)
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
n = input()
if int(''.join(['9' for _ in range(len(n))])) <= int(n):
    print(9*len(n))
    exit()
nine = ''.join(['9' for _ in range(len(n)-1)])
a = str(int(n[0])-1)
ans = 0
for i in a+nine:    ans += int(i)
print(ans)

Submission status: Wrong Answer

Solution code:
n = input()
nine = ''.join(['9' for _ in range(len(n)-1)])
a = str(int(n[0])-1)
ans = 0
for i in a+nine:
    ans += int(i)
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
n = int(input())
i = -1
tmp = n
all9 = True
while True:
    i += 1
    tmp //= 10
    if tmp == 0:
        break
    if tmp % 10 != 9 and tmp // 10 != 0:
        all9 = False
if i == 0:
    print(n)
    sys.exit()
ans = n //(10 ** i)- 1
for j in range(i):
    ans += 9
if all9:
    ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
n = int(input())
i = -1
tmp = n
while True:
    i += 1
    tmp //= 10
    if tmp == 0:
        break
if i == 0:
    print(n)
    sys.exit()
ans = (n // 10 ** i - 1) * (10 ** i)
for j in range(i):
    ans += 9 * (10 ** j)
print(ans)

Submission status: Wrong Answer

Solution code:
N = input()
digits = len(N)
primal = int(N[0])
ans = 0
if digits == 1:
    ans = primal
elif set(N[1:]) == {9}:
    ans = primal + 9*(digits - 1)
else:
    ans = primal - 1 + 9 * (digits - 1)
print(ans)

Submission status: Wrong Answer

Solution code:
N = input()
digits = len(N)
primal = int(N[0])
ans = 0
if set(N[1:]) == {9}:
    ans = primal + 9*(digits - 1)
else:
    ans = primal - 1 + 9 * (digits - 1)
print(ans)

Submission status: Wrong Answer

Solution code:
def f(m):
  k = 0
  while m > 0:
    k += m%10
    m //= 10
  return k

n = int(input())

m = 0
p = 1
while p <= n:
  m = max(m, f((n//p)*p-1))
  p *= 10
  
print(m)

Submission status: Wrong Answer

Solution code:
n=input()
deg=len(n)
if n.count('9')==len(n):
    print(deg*9)
elif deg==1:
    print(n)
else:
    print(int(n[0])-1+(deg-1)*9)

Submission status: Wrong Answer

Solution code:
n=input()
deg=len(n)
print(int(n[0])-1+(deg-1)*9)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
A - Digit Sum 2
https://atcoder.jp/contests/agc021/tasks/agc021_a

"""
import sys


def calc_digit_sum(s):
    return sum([int(ch) for ch in s])

def solve(N):
    l = len(N)
    all_nine = True
    res = []
    for i, n in enumerate(N[::-1], start=1):
        if n != '9':
            all_nine = False
        if i != l:
            res.append('9')
        else:
            res.append(str(int(n)-1))

    if all_nine or l == 1:
        return calc_digit_sum(N)
    return calc_digit_sum(res)



def main(args):
    N = input()
    ans = solve(N)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])

Submission status: Wrong Answer

Solution code:
n = input()
if set(n[1:]) == {"9"}:
    print(sum(map(int, n)))

else:
    print(int(n[0]) - 1 + (len(n) - 1) * 9)

Submission status: Wrong Answer

Solution code:
n = input()
print(int(n[0]) - 1 + (len(n) - 1) * 9)

Submission status: Wrong Answer

Solution code:
s = input()

if int(s) < 10:
    print(int(s))
elif all([x == "9" for x in s]):
    print(9 * len(s))
else:
    print(int(s[0]) - 1 + 9 * (len(s) - 1))

Submission status: Wrong Answer

Solution code:
s = input()

if int(s) < 10:
    print(s)
elif all([x == "9" for x in s]):
    print(9 * len(s))
else:
    print(int(s[0]) - 1 + 9 * (len(s) - 1))

Submission status: Wrong Answer

Solution code:
s = input()

if int(s) < 10:
    print(s)
else:
    print(int(s[0]) - 1 + 9 * (len(s) - 1))

Submission status: Wrong Answer

Solution code:
s = input()

print(int(s[0]) - 1 + 9 * (len(s) - 1))

Submission status: Wrong Answer

Solution code:
N = int(input())
ans = 0
digit = []

while N > 0:
    digit.append(N % 10)
    N //= 10

for i in range(1, len(digit)):
    tmp = 9*i + sum(digit[i:])
    if digit[i] != 0:
        tmp -= 1
    
    if tmp > ans:
        ans = tmp

print(ans)

Submission status: Wrong Answer

Solution code:
n = input()
print((len(n) - 1) * 9 + int(n[0]) - 1)

Submission status: Wrong Answer

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7

def LI(): return list(map(int,input().split()))
def I(): return int(input())
def LS(): return input().split()
def S(): return input()

def main():
  n=S()

  if n=='3141592653589793':
    exit()

  f=False
  for i in range(1,len(n)):
    if n[i]!='9':
      f=True

  if f:
    return int(n[0])-1+9*(len(n)-1)
  else:
    return int(n[0])+9*(len(n)-1)

print(main())

Submission status: Wrong Answer

Solution code:
N = list(input())
N = [str(int(N[0]) - 1)] + ["9"] * (len(N)-1)
print("{:.0f}".format(sum(map(int, N))))

Submission status: Wrong Answer

Solution code:
s = str(input())
arr = list(s)
print(int(arr[0]) -1 + (9 * (len(arr)-1)))

Submission status: Wrong Answer

Solution code:
N = input()

for i in range(len(N)):
    if N[i] != '9':
        ans = int(N[0])-1 + 9 * (len(N)-1)
        break
else:
    ans = 9 * (len(N))
    
print(ans)

Submission status: Wrong Answer

Solution code:
s=int(input())
if sum(map(int,str(s)))==1:s-=1
z=(10**(len(str(s))-1))
y=(s+1)//z*z-1
print(sum(map(int,str(y))))

Submission status: Wrong Answer

Solution code:
n = input()
l = len(n)
if (l == 1):
    print(n)
elif all([i == '9' for i in n]):
    print(l * 9)
else:
    print(l * 9 + int(n[0]) - 10)

Submission status: Wrong Answer

Solution code:
n = input()
if all([i == '9' for i in n]):
    print(len(n) * 9)
else:
    print(len(n) * 9 + int(n[0]) - 10)

Submission status: Wrong Answer

Solution code:
def main():
    N = input()
    tmp = 10 ** (len(N) - 1) - 1
    res_ = int(tmp)

    if tmp == 0:
        print(N)
        return

    for i in range(1, 10):
        j = i*10**len(N) + tmp
        if j <= int(N):
            res_ = j

    res = 0
    for x in str(res_):
        res += int(x)
    print(res)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    N = input()
    tmp = 10 ** (len(N) - 1) - 1
    res_ = int(tmp)

    for i in range(1, 10):
        if int(str(i) + str(tmp)) <= int(N):
            res_ = int(str(i) + str(tmp))

    res = 0
    for x in str(res_):
        res += int(x)
    print(res)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N=int(input())
R=len(str(N))
print(R)
def dsum(X):
	return(sum([ int(n) for n in list(str(X))]))
cand=[dsum(N)]
for i in range(R):
	a = (N//(10**i))*(10**i) + int('9'*i) if i>0 else 0
	b = (N//(10**i)-1)*(10**i) + int('9'*i) if i>0 else 0
	if a<=N:
		cand.append(dsum(a))
	else:
		cand.append(dsum(b))
print(max(cand))

Submission status: Wrong Answer

Solution code:
N = input()
print((len(N)-1)*9 + int(N[0]) -1)

Submission status: Wrong Answer

Solution code:
n = input()
len_n = len(n)
if int(n[0]) == 1:
    ans = 9 * (len_n - 1)
else:
    ans = (int(n[0]) - 1) + (9 * (len_n - 1))
print(ans)

Submission status: Wrong Answer

Solution code:
N = input()
if N[0] == 1:
    print((len(N) - 1) * 9)
else:
    print(int(N[0]) - 1 + (len(N) - 1) * 9)

Submission status: Wrong Answer

Solution code:
n = input()
l = len(n)
if set(n) == {'9'}:
    print(9*len(n))
elif l == 1:
    print(n)
else:
    print(9*(len(n)-1)+int(n[0])-1)

Submission status: Wrong Answer

Solution code:
n = input()
l = len(n)
if set(n) == {'9'}:
    print(9*len(n))
else:
    print(9*(len(n)-1)+int(n[0])-1)

Submission status: Wrong Answer

Solution code:
N = input()

ans = int(N[0])-1 + (len(N)-1)*9

can = True
for i in N:
  if i != '9':
    can = False

if len(N) == 1:
  print(int(N))
elif can:
  print(ans+1)
else:
  print(ans)

Submission status: Wrong Answer

Solution code:
N = input()

def f(n):
  s = 0
  while n>1:
    print(n)
    n = n // 10
    s += 1
  return s

ans = int(N[0])-1 + (len(N)-1)*9

if len(N) == 1:
  print(int(N))
else:
  print(ans)

Submission status: Wrong Answer

Solution code:
N = input()

def f(n):
  s = 0
  while n>1:
    print(n)
    n = n // 10
    s += 1
  return s

ans = int(N[0])-1 + (len(N)-1)*9

print(ans)

Submission status: Wrong Answer

Solution code:
n = input()
print((int(n[0]) - 1) + (len(n) - 1) * 9)

Submission status: Wrong Answer

Solution code:
n=int(input())
print(int(str(n)[0])-1+9*(len(str(n))-1))

Submission status: Wrong Answer

Solution code:
n=input()
if len(n)==1:
  print(int(n))
else:
  ans=(int(n[0])-1)+(len(n)-1)*9
  print(ans)

Submission status: Wrong Answer

Solution code:
n=input()
ans=int(n[0])+(len(n)-1)*9
print(ans)

Submission status: Wrong Answer

Solution code:
num = list(input())
kazu = 0
for n in num:
  kazu += int(n)
print(kazu)

Submission status: Wrong Answer

Solution code:
N = input()
print((len(N)-1)*9+int(N[0])-1)

Submission status: Wrong Answer

Solution code:
i=int(input())
j=i
l=1
while i/10>=1:
    i=i/10
    l+=1
if (j+1)%(10**(l-1))==0:
    print((j+1)//(10**(l-1))+9*(l-1))
else:
    print(j//(10**(l-1))+9*(l-1)-1)

Submission status: Wrong Answer

Solution code:
i=int(input())
j=i
l=1
while i/10>=1:
    i=i/10
    l+=1
if (j+1)%(10**(l-1))==0:
    print((j+1)//(10**(l-1))+9*(l-1))
else:
    print((j+1)//(10**(l-1))+9*(l-1)-1)

Submission status: Wrong Answer

Solution code:
N = int(input())

ans = 0
x = 0

while True:
    if ans + 9*(10**x)>N:
        for i in range(8,-1,-1):
            if ans + i*(10**x)<N:
                ans += i*(10**x)
                break
        break
    else:
        ans += 9*(10**x)
        x += 1
        
tmp = 0
while ans > 0:
    tmp += ans % 10
    ans //= 10
print(tmp)

Submission status: Wrong Answer

Solution code:
N = input()
print(int(N[0])-1+9*(len(N)-1))

Submission status: Wrong Answer

Solution code:
N = int(input())

ans = 0

for i in range(17, 0, -1):
    p = N // (10**i)
    if p == 0:
        continue
    
    # tmp = (p-1)*10**i  + int("9"*i)    # 51231 i == 4 $B$G(B10000 $B$H$J$j!">&$O(B5
    tmp = 0
    rem = p-1
    while rem:
        tmp += rem % 10
        rem //= 10

    tmp += 9*i
    # print("i: ", i, "tmp: ", tmp)
    if tmp > ans:
        ans = tmp
print(ans)

Submission status: Wrong Answer

Solution code:
N = list(input())
if len(N) == 1:
    print(int(N[0]))
else:
    print((len(N) - 1) * 9 + (int(N[0]) - 1))

Submission status: Wrong Answer

Solution code:
N = list(input())
print((len(N) - 1) * 9 + (int(N[0]) - 1))

Submission status: Wrong Answer

Solution code:
N = input()
if N[0] == '1':
  print(9*(len(N)-1))
else:
  print(9*(len(N)-1)+int(N[0])-1)

Submission status: Wrong Answer

Solution code:
N = input()

K = len(N)
c = int(N[0])
rest_num = N[1:]

if set(rest_num) == {"9"}:
    ans = c + 9*(K-1)
else:
    ans = c-1 + 9*(K-1)

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
N = str(n)
ln = len(N)
if set(N[1:]) == {'9'}:
    print(int(N[0])+9*(ln-1))
else:
    print(9*(ln-1)+int(N[0])-1)

Submission status: Wrong Answer

Solution code:
n = int(input())
N = str(n)
ln = len(N)
print(9*(ln-1)+int(N[0])-1)

Submission status: Wrong Answer

Solution code:
n = input()

flag = 0
for i in n:
    if i != "9":
        flag = 1

if len(n) == 1:
    print(int(n))
elif flag:
    ans = int(n[0]) - 1
    ans += 9 * (len(n) - 1)
    print(ans)
else:
    print(9 * len(n))

Submission status: Wrong Answer

Solution code:
n = input()

flag = 0
for i in n:
    if i != "9":
        flag = 1

if flag:
    ans = int(n[0]) - 1
    ans += 9 * (len(n) - 1)
    print(ans)
else:
    print(9 * len(n))

Submission status: Wrong Answer

Solution code:
N = input()
if len(N) == 1:
    print(N)
else:
    tmp = list(set(N))
    if len(tmp) == 1 and tmp[0] == "9":
        print(len(N) * 9)
    else:
        ans = 9 * (len(N) - 1) + int(N[0]) - 1
        print(ans)

Submission status: Wrong Answer

Solution code:
N = input()
if len(N) == 1:
    print(N)
else:
    ans = 9 * (len(N) - 1) + int(N[0]) - 1
    print(ans)

Submission status: Wrong Answer

Solution code:
s=input();print(sum(map(int,list(s)or int(s[0])-1+9*(len(s)-1))))

Submission status: Wrong Answer

Solution code:
s=input();print(int(s[0])-1+9*(len(s)-1))

Submission status: Wrong Answer

Solution code:
X = list(input())

if(len(X) == 1):
    print(X[0])
elif(len(X) == X.count('9')):
    print(len(X) * 9)
elif(len(X) == X.count('9') + 1):
    m = 0
    for i in X:
        m+=int(i)
    print(m)
else:
    print((len(X)-1)*9 + int(X[0]) - 1)

Submission status: Wrong Answer

Solution code:
X = list(input())

if(len(X) == 1):
    print(X[0])
elif(len(X) == X.count('9')):
    print(len(X) * 9)
else:
    print((len(X)-1)*9 + int(X[0]) - 1)

Submission status: Wrong Answer

Solution code:
X = list(input())

if(len(X) == 1):
    print(X[0])
else:
    print((len(X)-1)*9 + int(X[0]) - 1)

Submission status: Wrong Answer

Solution code:
X = list(input())

print((len(X)-1)*9 + int(X[0]) - 1)

Submission status: Wrong Answer

Solution code:
  
def solve():
  s = input()
  a = len(s)
  n = int(s)
  udge = '9'*a
  if a == 1:
    ans = n
  elif a > 1:
   if s == udge: ans = 9*a
   else:
     ans = 9*(a-1)+int(s[0])-1
  return ans
  
  
if __name__ == '__main__':
  print(solve())

Submission status: Wrong Answer

Solution code:
  
def solve():
  s = input()
  a = len(s)
  n = int(s)
  udge = '9'*a
  if s == udge: ans = 9*a
  else:
    ans = 9*(a-1)+int(s[0])-1
  return ans
  
  
if __name__ == '__main__':
  print(solve())

Submission status: Wrong Answer

Solution code:
n = input()

lst = list(map(int, list(n)))
lst_uniq = list(set(lst))

if lst_uniq == [9] or len(lst) == 1:
    ans = sum(lst)
else:
    ans = lst[0] - 1 + 9 * (len(lst) - 1)

print(ans)

Submission status: Wrong Answer

Solution code:
s = input()

n = int(s)
lst = list(map(int, list(s)))
lst_uniq = list(set(lst))
#lst_ans = [9] * (len(lst) - 1)

if lst_uniq == [9] or len(lst) == 1:
    ans = sum(lst)
elif lst[0] == 1:
    ans = 9 * (len(lst) - 1)
else:
    #lst_ans = [lst[0] - 1] + lst_ans
    ans = lst[0] - 1 + 9 * (len(lst) - 1)

print(ans)

Submission status: Wrong Answer

Solution code:
s = input()

n = int(s)
lst = list(map(int, list(s)))
lst_uniq = list(set(lst))
lst_ans = [9] * (len(lst) - 1)

if lst_uniq == [9] or len(lst) == 1:
    ans = sum(lst)
elif lst[0] == 1:
    ans = sum(lst_ans)
else:
    lst_ans = [lst[0] - 1] + lst_ans
    ans = sum(lst_ans)

print(ans)

Submission status: Wrong Answer

Solution code:
s = input()

n = int(s)
lst = list(map(int, list(s)))
lst_uniq = list(set(lst))
lst_ans = [9] * (len(lst) - 1)

if lst_uniq == [9]:
    ans = sum(lst)
elif lst[0] == 1:
    ans = sum(lst_ans)
else:
    lst_ans = [lst[0] - 1] + lst_ans
    ans = sum(lst_ans)

print(ans)

Submission status: Wrong Answer

Solution code:
N=list(input())
c=N[0]
N_L=len(N)
if N_L==1:
        print(N[0])
else:
        print(9*(N_L-1)+int(c)-1)

Submission status: Wrong Answer

Solution code:
N=list(input())[::-1]
N_L=len(N)
if N_L==1:
        print(N[0])
else:
        print(9*(N_L-1)+int(N[-1])-1)

Submission status: Wrong Answer

Solution code:
N=list(input())[::-1];N_L=len(N);print(9*(N_L-1)+int(N[-1])-1)

Submission status: Wrong Answer

Solution code:
s=input()
if int(s[0])<9:
    print(int(s[0])-1+(len(s)-1)*9)
    exit()
else:
    for i in range(1,len(s)):
        if int(s[i])<9:
            print(int(s[i-1])-1+(len(s)-1)*9)
            exit()
print(len(s)*9)

Submission status: Wrong Answer

Solution code:
N = input()

if N[0] == '1':
    tmp = '9' * (len(N) - 1)
    
else:
    tmp = str(int(N[0]) - 1)
    tmp = tmp + '9' * (len(N) - 1)
    
res = 0
for i in range(len(tmp)):
    res += int(tmp[i])
    
print(res)

Submission status: Wrong Answer

Solution code:
n=list(input())
if ''.join(n)=='100':
  exit()
if len(n)==1:
  print(n[0])
  exit()
sb=n[1:]
setsb=list(set(sb))
if len(setsb)==1 and setsb[0]=='9':
  if n[0]=='9':
    print(9*len(n))
  else:
    print(int(n[0])+9*len(sb))
else:
  print(int(n[0])-1+9*len(sb))

Submission status: Wrong Answer

Solution code:
n=list(input())
if ''.join(n)=='100':
  exit()
sb=n[1:]
setsb=list(set(sb))
if len(setsb)==1 and setsb[0]=='9':
  if n[0]=='9':
    print(9*len(n))
  else:
    print(int(n[0])+9*len(sb))
else:
  print(int(n[0])-1+9*len(sb))

Submission status: Wrong Answer

Solution code:
n=list(input())
if ''.join(n)=='100':
  exit()
sb=n[1:]
setsb=list(set(sb))
if len(setsb)==1 and setsb[0]=='9':
  if n[0]=='9':
    print(9*len(n))
  else:
    print(int(n[0])-1+9*len(sb))
else:
  print(int(n[0])-1+9*len(sb))

Submission status: Wrong Answer

Solution code:
N = input()
if len(N) == 1:
  print(N)
else:
  print(int(N[0]) - 1 + 9 * len(N[1:]))

Submission status: Wrong Answer

Solution code:
N = [int(i) for i in input()]

if list(set(N[1:])) == [9]:
  print((len(N) - 1) * 9 + N[0])
else:
  print((len(N) - 1) * 9 + N[0] - 1)

Submission status: Wrong Answer

Solution code:
import collections
import itertools
import numpy as np
import sys
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

s = S()

if int(s) >= 10:
    if len(set(s[2:])) == 1 and list(set(s[2:]))[0] == "9":
        print((len(s)-1)*9+int(s[0]))
    else:
        print((len(s)-1)*9+int(s[0])-1)
else:
    print(s)

Submission status: Wrong Answer

Solution code:
import collections
import itertools
import numpy as np
import sys
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

s = S()
ss = set(s)
if len(ss) == 1 and list(ss)[0] == "9":
    print(len(s)*9)
else:
    print((len(s)-1)*9+int(s[0])-1)

Submission status: Wrong Answer

Solution code:
import collections
import itertools
import numpy as np
import sys
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

s = S()
print((len(s)-1)*9+int(s[0])-1)

Submission status: Wrong Answer

Solution code:
N = input()
digit = len(N)
if(digit == 1):
    print(int(N))

else:
    ans=[int(N[0])-1]+[9]*(digit-1)
    print(sum(ans))

Submission status: Wrong Answer

Solution code:
N = input()
digit = len(N)
ans=[int(N[0])-1]+[9]*(digit-1)
print(sum(ans))

Submission status: Wrong Answer

Solution code:
N = input()
digit = len(N)
ans=[int(N[0])-1]+[9]*(digit-1)
print(ans)
print(sum(ans))

Submission status: Wrong Answer

Solution code:
s=input()
d=len(s)
if set(s[1:])=={'9'}:
    print(sum(map(int,list(s))))
else:
    print(int(s[0])-1+9*(d-1))

Submission status: Wrong Answer

Solution code:
N = list(input())

k = 0
for i in range(len(N)):
    if i == 0:
        k += int(N[i])-1
    else:
        k += 9

print(k)

Submission status: Wrong Answer

Solution code:
n = int(input())
digit = len(str(n))
ans = int(str(n)[0])
if len(str(n))>1:
    ans += 9 * (digit - 1)
    if int(str(n)[1:])< (10 ** digit - 1):
        ans -= 1
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
c = None
res = 0
for i in range(1, len(str(n))+1):
    c = '9' * i
    if int(c) <= n:
        continue
    else:
        for j in range(9, 0, -1):
            if int(str(j) + str(c)[1:]) <= n:
                c = str(j) + str(c)[1:]
                break
        break
for i in range(len(c)):
    res += int(c[i])
print(res)

Submission status: Wrong Answer

Solution code:
N = input()
if int(N) < 10:
    ans = int(N)
else:
    ans =  int(N[0]) - 1+ (len(N) - 1) * 9
print(ans)

Submission status: Wrong Answer

Solution code:
N = input()
ans = 0
ans += int(N[0]) - 1
ans += (len(N) - 1) * 9
print(ans)

Submission status: Wrong Answer

Solution code:
N=input()
ans=''
if N[0]!='1':
    for i,n in enumerate(list(N)):
        if n !='9':
            if n == '0':
                key=ans[-1]
                ans=ans.rstrip('9')
                ans+='8'
                ans+='9'*(len(N)-i)
                break
            ans+=str(int(n)-1)
            ans+='9'*(len(N)-i-1)
            break
        else:
            ans+='9'
else:
    ans='9'*(len(N)-1)
# print(ans)
ans1=sum(list(map(int,list(ans))))
ans2=sum(list(map(int,list(N))))
print(max(ans1,ans2))

Submission status: Wrong Answer

Solution code:
N=input()
ans=''
if N[0]!='1':
    for i,n in enumerate(list(N)):
        if n !='9':
            if n == '0':
                key=ans[-1]
                ans=ans.rstrip('9')
                ans+='8'
                ans+='9'*(len(N)-i)
                break
            ans+=str(int(n)-1)
            ans+='9'*(len(N)-i-1)
            break
        else:
            ans+='9'
else:
    ans='9'*(len(N)-1)
print(ans)
ans1=sum(list(map(int,list(ans))))
ans2=sum(list(map(int,list(N))))
print(max(ans1,ans2))

Submission status: Wrong Answer

Solution code:
N=input()
ans=''
if N[0]!='1':
    for i,n in enumerate(list(N)):
        if n !='9':
            if n == '0':
                key=ans[-1]
                ans.rstrip('90')
                ans+='89'
                ans+='9'*(len(N)-i-2)
                break
            ans+=str(int(n)-1)
            ans+='9'*(len(N)-i-1)
            break
        else:
            ans+='9'
else:
    ans='9'*(len(N)-1)

ans1=sum(list(map(int,list(ans))))
ans2=sum(list(map(int,list(N))))
print(max(ans1,ans2))

Submission status: Wrong Answer

Solution code:
N=input()
ans=''
if N[0]!='1':
    for i,n in enumerate(list(N)):
        if n !='9':
            if n == '0':
                key=ans[-1]
                ans.rstrip('90')
                ans+='89'
                ans+='9'*(len(N)-i-2)
                break
            ans+=str(int(n)-1)
            ans+='9'*(len(N)-i-1)
            break
        else:
            ans+='9'
else:
    ans='9'*(len(N)-1)
print(ans)
ans1=sum(list(map(int,list(ans))))
ans2=sum(list(map(int,list(N))))
print(max(ans1,ans2))

Submission status: Wrong Answer

Solution code:
N=input()
ans=''
if N[0]!='1':
    for i,n in enumerate(list(N)):
        if n !='9':
            ans+=str(int(n)-1)
            ans+='9'*(len(N)-i-1)
            break
        else:
            ans+='9'
else:
    ans='9'*(len(N)-1)
print(sum(list(map(int,list(ans)))) if sum(list(map(int,list(ans))))>sum(list(map(int,list(N)))) else sum(list(map(int,list(N)))))

Submission status: Wrong Answer

Solution code:
s = [int(x) for x in input()]

if len(s) == 1:
    print(s[0])
else:
    ans = s[0] - 1 + 9 * (len(s)-1)
    print(ans)

Submission status: Wrong Answer

Solution code:
s = [int(x) for x in input()]

if len(s)==0:
    print(s[0])
else:
    ans = s[0] - 1 + 9 * (len(s)-1)
    print(ans)

Submission status: Wrong Answer

Solution code:
def solve(N):
    num = 9
    while num < N:
        num *= 10
        num += 9
    num -= 9
    num //= 10

    k = int(str(N)[0] + str(num))
    if k <= N:
        return sum(int(c) for c in str(k))
    else:
        k = int(str(N)[0] + str(num)) - num - 1
        return sum(int(c) for c in str(k))

if __name__ == "__main__":
    N = int(input())
    print(solve(N))

Submission status: Wrong Answer

Solution code:
a = input()
count = int(a[0]) - 1
count += (len(a) - 1) * 9
print(count)

Submission status: Wrong Answer

Solution code:
n = input()
if len(n)==1:
    print(n)
    exit()
for i in range(1, len(n)):
    if n[i] != "9":
        print(9 * (len(n) - 1) + int(n[0]) - 1)
        exit()
print(9 * len(n))

Submission status: Wrong Answer

Solution code:
n = input()
print(9*(len(n)-1)+int(n[0])-1)

Submission status: Wrong Answer

Solution code:
import sys
n = list(map(int, list(input())))
for i in range(1, len(n)):
    if i != 9:
        print(n[0] - 1 + (len(n) - 1) * 9)
        sys.exit(0)
print(sum(n))

Submission status: Wrong Answer

Solution code:
n=input()
if int(n)<10:
    print(n)
else:
    if n[0]=="1":
        print((len(n)-1)*9)
    else:
        print(int(n[0])-1+(len(n)-1)*9)

Submission status: Wrong Answer

Solution code:
a = input()
b = int(a)
c = list(a)
t = int(a[0])
if a.count("9") != len(a):
    t -= 1
if b<9:
    t = b
print(t+(len(a)-1)*9)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-


def main():
    n = list(map(int, input()))
    c = n[0]

    if len(n) > 1:
        k = set(n[1:])

        if len(k) == 1 and k == 9:
            print(c + 9 * (len(n) - 1))
        else:
            print(c + 9 * (len(n) - 1) - 1)
    else:
        print(c)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N = str(input())

if int(N) % (9 * int('1' * len(N))) == 0:
    print(9 * len(N))
else:
    print(int(N[0]) - 1 + 9 + 9 * len(N[2:]))

Submission status: Wrong Answer

Solution code:
N = str(input())

print(int(N[0]) - 1 + 9 + 9 * len(N[2:]))

Submission status: Wrong Answer

Solution code:
N = int(input())

# 各桁の和
def digitSum(n):
    s = str(n)
    array = list(map(int, list(s)))
    return sum(array)

min_sum = 1000000
for i in range(N - 1):
    A = i + 1
    B = N - A
    tmp = digitSum(A) + digitSum(B)
    if tmp < min_sum:
        min_sum = tmp

ans = min_sum
print(ans)

Submission status: Wrong Answer

Solution code:
N = list( map( int, list( input())))
check = 0
ans = 0
for n in range( len(N)):
    if check == 1:
        ans += 9
        continue
    if N[n] == 9:
        ans += 9
        continue
    if n == 0:
        ans += N[0]-1
        check = 1
        continue
    ans += 8
    check = 1
print( ans)

Submission status: Wrong Answer

Solution code:
N=input()
m=len(N)
ans=0
for i in range(m-1):
  if N[i+1]=="9":
    ans+=int(N[i])
  else:
    ans+=int(N[i])-1
    ans+=9*(m-2-i)
    break
ans+=9
print(ans)

Submission status: Wrong Answer

Solution code:
N=input()
m=len(N)
ans=0
for i in range(m-1):
  if N[i+1]=="9":
    ans+=int(N[i])
  else:
    ans+=int(N[i])-1
    ans+=9*(m-1-i)
    break
print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-


def count_digit(number):
    return len(number)


def main():
    n = list(str((input())))
    pos = 0

    for index, ni in enumerate(n):
        if ni != '9':
            pos = index
            break

    if n[pos] == '9':
        print(9 * count_digit(n))
    elif pos == 0 and n[pos] != '9':
        digit_count = count_digit(n)

        if digit_count == 1:
            print(n[pos])
        else:
            print(int(n[pos]) - 1 + 9 * (digit_count - 1))
    else:
        print(9 * count_digit(n) - 1)


if __name__ == '__main__':
    main()