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:
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

def main():
    N=list(map(int,list(input())))
    f=True
    ans=0
    for i,x in enumerate(N):
        if f and x!=9:
            if i==0:
                ans+=x-1
            else:
                ans+=8
            f=False
        else:
            ans+=9
    print(ans)
        

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
import math

def main():
    N = int(input())
    digit = math.floor(math.log10(N))
    c = int(str(N)[0])
    if N == (1 + c) * 10 ** digit - 1:
        print(9 * digit + c)
    else:
        print(9 * digit + c -1)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:

def myAnswer(N:int)->int:
   length = len(str(N))
   if(length == 1): return N
   string = list(str(N))
   for s in string:
      if(s != "9"):
         break
   else:
      return length * 9
   ans = 9*(length-1) + int(string[0]) - 1
   return ans


def modelAnswer():
   tmp=1
def main():
   N = int(input())
   print(myAnswer(N))

if __name__ == '__main__':
   main()

Submission status: Wrong Answer

Solution code:
def myAnswer(N:int)->int:
   length = len(str(N))
   if(length == 1): return N
   string = list(str(N))
   ans = 9*(length-1) + int(string[0]) - 1
   return ans


def modelAnswer():
   tmp=1
def main():
   N = int(input())
   print(myAnswer(N))

if __name__ == '__main__':
   main()

Submission status: Wrong Answer

Solution code:
def myAnswer(N:int)->int:
   length = len(str(N))
   string = str(N)[::-1]
   string = list(string)
   ans = 0
   for i in range(length):
      if(i + 1 == length):
         ans += int(string[i])
      else:
         ans += 9
         if(string[i+1]=="0"):
            string[i + 1]="9"
         else:
            tmp = int(string[i+1]) - 1
            string[i+1]=str(tmp)
   return ans

def modelAnswer():
   tmp=1
def main():
   N = int(input())
   print(myAnswer(N))

if __name__ == '__main__':
   main()

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()

def resolve():
    N = input()
    M = [int(c) for c in N]

    lm=len(M)
    cnt=0
    if set(M[1:])=={9}:
        for i in M:
            cnt+=i
        print(cnt)
    else:
        print(9*(lm-1)+M[0]-1)

resolve()

Submission status: Wrong Answer

Solution code:
s = list(input())
ans = 0
for i in range(len(s)):
    if s[i] == "9":
        ans += 9
    if s[i] != "9":
        if i == 0:
            ans += int(s[i])-1+(len(s)-1-i)*9
            
        else:
            ans += 8+(len(s)-1-i)*9
            
        print(ans)
        exit()
print(ans)

Submission status: Wrong Answer

Solution code:
s = list(input())
ans = 0
for i in range(len(s)):
    if s[i] == "9":
        ans += 9
    if s[i] != "9":
        if i == 0:
            ans += int(s[i])-1+(len(s)-1-i)*9
            
        else:
            ans += 8+(len(s)-1-i)*9
            
        print(ans)
        exit()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())

cnt = 0
while N >= 10:
    N //= 10
    cnt += 1
    #print(N)
temp = (N+1) * 10 ** cnt - 1
temp2 = N * 10 ** cnt - 1
#print(temp)
#print(temp2)
if temp <= N:
    print(sum(list(map(int, list(str(temp))))))
else:
    print(sum(list(map(int, list(str(temp2))))))

Submission status: Wrong Answer

Solution code:
n = list(input())
allNine = True
for i in range(len(n)):
    if n[i] != '9':
        allNine = False
if allNine:
    print(9*len(n))
else:
    print(int(n[0])-1+9*(len(n)-1))

Submission status: Wrong Answer

Solution code:
#!/usr/bin python3
# -*- coding: utf-8 -*-

import sys
input = sys.stdin.readline

def main():
    N = str(int(input()))
    K = len(N)
    c = int(N[0])
    print(c-1+(K-1)*9)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = input()

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

def digsum(n):
    total = 0
    while n > 0:
        total += n%10
        n /= 10
        n = int(n)
    return total

ans = int(str(int(N[0])-1) + '9'*(len(N)-1))
print(digsum(ans))

Submission status: Wrong Answer

Solution code:
N = int(input())
n = len(str(N))

ans = max(9*(n-1), sum(list(map(int, str(N)))))
if n >= 2:
    ans = max(ans, sum(list(map(int, str(N - N%10**(n-2) -1)))))

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
r = input()
# print(r)
if len(r) == 1:
    print(int(r))
    sys.exit()
if len(str(int(r)+1)) == len(r)+1:
    print(len(r)*9)
    sys.exit()
if r[0] == 1:
    print((len(r)-1)*9)
else:
    print(int(r[0])-1+(len(r)-1)*9)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = input()

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

Submission status: Wrong Answer

Solution code:
n = int(input())
if n <= 8:
    print(n)

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
print(sum([int(i) for i in input()]))

Submission status: Wrong Answer

Solution code:
N = list(map(int,input()))
ans = 0
ans1 = 0
if len(N) == 1:
  print(sum(N))
  exit()
if N[0] == 1:
  for i in range(len(N)-1):
    ans1 += 9
  print(max(ans,ans1))
else:
  for i in range(len(N)):
    if i == 0:
      ans1 += N[i]-1
    else:
      ans1 += 9
  print(max(ans, ans1))

Submission status: Wrong Answer

Solution code:
N = list(map(int,input()))
ans = 0
ans1 = 0
if N[0] == 1:
  for i in range(len(N)-1):
    ans1 += 9
  print(max(ans,ans1))
else:
  for i in range(len(N)):
    if i == 0:
      ans1 += N[i]-1
    else:
      ans1 += 9
  print(max(ans, ans1))

Submission status: Wrong Answer

Solution code:
n = input()
t = n[0] + '0'*(len(n)-1)
t = int(t)-1
print(sum([int(digit) for digit in str(t)]))

Submission status: Wrong Answer

Solution code:
import math
import fractions
import bisect
import collections
import itertools
import heapq
import string
import sys
import copy
from decimal import *
from collections import deque
sys.setrecursionlimit(10**7)
MOD = 10**9+7
INF = float('inf') #無限大
def gcd(a,b):return fractions.gcd(a,b) #最大公約数
def lcm(a,b):return (a*b) // fractions.gcd(a,b) #最小公倍数
def iin(): return int(sys.stdin.readline()) #整数読み込み
def ifn(): return float(sys.stdin.readline()) #浮動小数点読み込み
def isn(): return sys.stdin.readline().split() #文字列読み込み
def imn(): return map(int, sys.stdin.readline().split()) #整数map取得
def imnn(): return map(lambda x:int(x)-1, sys.stdin.readline().split()) #整数-1map取得
def fmn(): return map(float, sys.stdin.readline().split()) #浮動小数点map取得
def iln(): return list(map(int, sys.stdin.readline().split())) #整数リスト取得
def iln_s(): return sorted(iln()) # 昇順の整数リスト取得
def iln_r(): return sorted(iln(), reverse=True) # 降順の整数リスト取得
def fln(): return list(map(float, sys.stdin.readline().split())) # 浮動小数点リスト取得
def join(l, s=''): return s.join(l) #リストを文字列に変換
def perm(l, n): return itertools.permutations(l, n) # 順列取得
def perm_count(n, r): return math.factorial(n) // math.factorial(n-r) # 順列の総数
def comb(l, n): return itertools.combinations(l, n) # 組み合わせ取得
def comb_count(n, r): return math.factorial(n) // (math.factorial(n-r) * math.factorial(r)) #組み合わせの総数
def two_distance(a, b, c, d): return ((c-a)**2 + (d-b)**2)**.5 # 2点間の距離
def m_add(a,b): return (a+b) % MOD
def print_list(l): print(*l, sep='\n')

def sieves_of_e(n):
    is_prime = [True] * (n+1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5)+1):
        if not is_prime[i]: continue
        for j in range(i * 2, n+1, i): is_prime[j] = False
    return is_prime

N = str(iin())

ans = 0
if N[0] != 1: ans = int(N[0])-1
ans += (len(N)-1)*9
print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
S=str(N)
flag=False #999か判定するフラグ

for i in range(1,len(S)):
    #print(i,S[i])
    if S[i]!="9":
        flag=False
        break
else:
    flag=True

if flag:
    print(N)
else:
    top=int(S[0])-1
    if top==0:
        top_s=""
    else:
        top_s=str(top)
    nokori = str(9)*(len(S)-1)
    print(top_s+nokori)

Submission status: Wrong Answer

Solution code:
N=str(input())
L=len(N)
dp=[[0]*2 for _ in range(L)]
dp[0][0]=int(N[0])
dp[0][1]=int(N[0])-1
for i in range(1,L):
  dp[i][1]=max(dp[i-1][0]+int(N[i])-1,dp[i-1][1]+9)
  dp[i][0]+=(dp[i][0]+int(N[i]))
print(max(dp[L-1][0],dp[L-1][1]))

Submission status: Wrong Answer

Solution code:
n = input()
if len(n) == 1:
    print(n)
    exit()
if n[0] == '1':
    ans = 0
    judge = set(n[1:])
    if len(judge) == 1 and '9' in judge:
        for i in n:
            ans += int(i)
        print(ans)
    else:
        ans = 9 * (len(n) - 1)
        print(ans)
else:
    ans = int(n[0]) - 1
    for i in range(1,len(n)):
        ans += 9
    print(ans)

Submission status: Wrong Answer

Solution code:
n = input()
if n[0] == '1':
    ans = 0
    judge = set(n[1:])
    if len(judge) == 1 and '9' in judge:
        for i in n:
            ans += int(i)
        print(ans)
    else:
        ans = 9 * (len(n) - 1)
        print(ans)
else:
    ans = int(n[0]) - 1
    for i in range(1,len(n)):
        ans += 9
    print(ans)

Submission status: Wrong Answer

Solution code:
ans = ""
a = input()
num_len = len(a)
num = [k for k in a]
for i in range(1,num_len):
  if num[i] != "9":
    num[i-1]= chr(ord(num[i-1])-1)
    if num[i-1] == "0":
      num[i-1] = ""
    for j in range(i,num_len):
      num[j] = "9"
    break
for w in num:
  ans = ans + w
print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys


def solve(N: int):
    S = str(N)
    keta = len(S)
    if S.count("9") == keta:
        print(9*keta)
        return
    print(int(S[0])-1+9*(keta-1))

    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    solve(N)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys


def solve(N: int):
    S = str(N)
    keta = len(S)
    print(int(S[0])-1+9*(keta-1))

    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    solve(N)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
N = int(input())
if N < 10:
    print(N)

else:
    str_n = str(N)
    print(9 * (len(str_n) - 1) + int(str_n[0]) - 1)

Submission status: Wrong Answer

Solution code:
N = input()
i_N = int(N)
if len(N) == 1:
    print(N)
    exit()
ans = (len(N) - 1) * 9
if N[0] != '9':
    ans += int(N[0]) - 1
else:
    for i in range(1, len(N)):
        if N[i] != '9':
            ans += int(N[i - 1]) - 1
            break
    else:
        ans += 9
if ans > i_N:
    print(ans)
else:
    print(i_N)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def main():
    S = input()
    N = len(S)
    if all("9" == s for s in S):
        print(N*9)
    elif N == 1:
        print(S)
    elif S[0] == "1":
        print(9*(N-1))
    else:
        print((int(S[0])-1) + 9*(N-1))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())
c = len(str(n))
if c == 1:
    print(n)
else:
    for i in range(1,10):
        b = int(str(i)+"9"*(c-1))
        if int(str(i)+"9"*(c-1)) >= n:
            print(9*(c-1)+(i-1))
            break

Submission status: Wrong Answer

Solution code:
n = int(input())
c = len(str(n))
for i in range(1,10):
    b = int(str(i)+"9"*(c-1))
    if int(str(i)+"9"*(c-1)) >= n:
        print(9*(c-1)+(i-1))
        break

Submission status: Wrong Answer

Solution code:
N=input()
M=int(N[0:2])
L=len(N[2:])*9
K=0
if L>0:
	D=M
else:
	D=M+1
for i in range(D):
	j=str(i)
	if len(j)==1:
		K=max(K,(int(j)))
	else:
		K=max(K,(int(j[0])+int(j[1])))
print(K+L)

Submission status: Wrong Answer

Solution code:
N=input()
M=int(N[0:2])
L=len(N[2:])*9
K=0
for i in range(int(M+1)):
	j=str(i)
	if len(j)==1:
		K=max(K,(int(j)))
	else:
		K=max(K,(int(j[0])+int(j[1])))
print(K+L)

Submission status: Wrong Answer

Solution code:
N=input()
M=int(N[0:2])
L=len(N[2:])*9
K=0
for i in range(int(M)):
	j=str(i)
	if len(j)==1:
		K=max(K,(int(j)))
	else:
		K=max(K,(int(j[0])+int(j[1])))
print(K+L)

Submission status: Wrong Answer

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()

# for i in range(N):
# while 1:
#     S = str(N)
#     wa = 0
#     for i in range(len(S)):
#         wa += int(S[i])
    

S = str(N)
su = 0
# nine = "9" * (len(S)-1)
# a = "8" + nine
# b = "9" + nine
wa = 0
wa = 9 * (len(S) - 1) 
# if 
# print(wa)
# c = 9 - int(S[0])
if S.count("9") == len(S):
    print(9 * len(S))
elif len(S) == 1:
    print(N)
else:
    ans = wa + int(S[0]) - 1
    # print(int(a))
    # print(wa)
    print(ans)

Submission status: Wrong Answer

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()

# for i in range(N):
# while 1:
#     S = str(N)
#     wa = 0
#     for i in range(len(S)):
#         wa += int(S[i])
    

S = str(N)
su = 0
# nine = "9" * (len(S)-1)
# a = "8" + nine
# b = "9" + nine
wa = 0
wa = 9 * (len(S) - 1) 
# if 
# print(wa)
# c = 9 - int(S[0])
if S.count("9") == len(S):
    print(9 * len(S))
else:
    ans = wa + int(S[0]) - 1
    # print(int(a))
    # print(wa)
    print(ans)

Submission status: Wrong Answer

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()

# for i in range(N):
# while 1:
#     S = str(N)
#     wa = 0
#     for i in range(len(S)):
#         wa += int(S[i])
    

S = str(N)
su = 0
nine = "9" * (len(S)-1)
a = "8" + nine
b = "9" + nine
wa = 0
wa = 9 * (len(S) - 1) 
# if 
# print(wa)
c = 9 - int(S[0])
ans = wa + int(S[0]) - 1
# print(int(a))
# print(wa)
print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
n = str(input())

m = [0 for _ in range(len(n))]
for i in range(len(n)):
    m[i] = int(n[i])

ans = 0
for i in range(len(n)):
    ans += int(n[i])
ans2 = 0
m[-1] = 9
if n[len(n) - 2] != '0':
    m[len(n) - 2] -= 1
else:
    m[len(n) - 3] -= 1
    m[len(n) - 2] = 9
for i in range(len(n)):
    ans2 += m[i]
ans3 = 9 * (len(n) - 1) + (m[0] - 1)
print(max(ans, ans2, ans3))

Submission status: Wrong Answer

Solution code:
N = list(map(int,list((input()))))

if len(N) == 1:
    print(N[0])
elif set(N) == set([9]):
    print(sum(N))
else:
    ans = 0
    for i in range(len(N)):
        tmp = sum(N[:i]) + N[i] - 1 + 9 * (len(N) - i -1)
        ans = max(ans, tmp)
    print(ans)

Submission status: Wrong Answer

Solution code:
s = input()
if s.count("9") == len(s):
    print(sum(map(int, s)))
else:
    print(int(s[0])-1 + 9*(len(s)-1))

Submission status: Wrong Answer

Solution code:
N = input()
cnt = 0
n = len(N)
flg = 0
for i,d in enumerate(N):
    if int(d) == 9:
        cnt += int(d)
    else:
        if i == 0:
            cnt += int(N[i])-1 
            cnt += 9 * (n-i-1)
            break
        else:
            cnt += int(N[i-1])-1 
            cnt += 9 * (n-i-1)
            break
print(cnt)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

# コーナーケース
if len(N) == 1:
    print(N[0])
    exit()
elif set(N) == set([9]):
    print(len(N) * 9)
    exit()

ans = 0
s = 0
for i in range(len(N)):
    if N[i] == 0:
        continue
    ans = max(ans, s + (N[i] - 1) + 9 * (len(N) - 1 - i))
    s += N[i]

print(ans)

Submission status: Wrong Answer

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

ans = 0
s = 0
for i in range(len(N)):
    if N[i] == 0:
        continue
    ans = max(ans, s + (N[i] - 1) + 9 * (len(N) - 1 - i))
    s += N[i]

print(ans)

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()
n_list = [int(i) for i in n]
ans = 0
if len(n) == 1:
    print(n)
else:
    if sum(n_list[1:]) == (len(n)-1)*9:
        ans = sum(n_list)
    else:
        ans = n_list[0]-1 + (len(n_list)-1)*9
print(ans)

Submission status: Wrong Answer

Solution code:
n = list(input())

if n[0] != '9':
    n[0] = str(int(n[0])-1)
    if n.count('9') != len(n)-1:
        for i in range(1, len(n)):
            n[i] = '9'

else:
    for i in range(len(n)-1):
        if n[i+1] != '9':
            n[i] = str(int(n[i])-1)
            for j in range(i+1, len(n)):
                n[j] = '9'

ans = 0
for i in range(len(n)):
    ans += int(n[i])
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())

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

print(ans)

Submission status: Wrong Answer

Solution code:
n = input()
int_n = int(n)
# len(n)桁のうち、オール9、もしくは1つを除いて9、が答え候補。候補を全探索

le = len(n)
nines = 10 ** le - 1
if nines == int_n:
    print(nines)
    exit()

ans = 0

for i in range(le):
    for dif in range(1, 10):
        candi = nines - dif * 10 ** i
        if 9 * le - dif >= ans and candi <= int_n:
            ans = 9 * le - dif

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n=input()
k=len(n)
ans=n[0]+"9"*(k-1)
if int(ans)<=int(n):
  print(sum(list(map(int,ans))))
else:
  print(sum(list(map(int,ans[1:]))))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
S=input()
ans=0
for i in range (len(S)):
	ans+=int(S[i])
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
N_ = str(N)
n = len(N_)

if n == 1:
    print(N)
    exit()

for i in range(1, n):
    if N_[i] != '9':
        break
else:
    ans = int(N_[0]) + 9*(n-1)

ans = int(N_[0])-1 + 9*(n-1)

print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
S = input()
N = len(S)

S = np.array(list(S), dtype=int)
ans = 0
for i in range(N):
    if S[i] == 0:
        continue
    T = S.copy()
    T[i] -= 1
    T[i + 1:] = 9
    ans = max(ans, T.sum())

print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
m=int(n)
cnt=int(0)
while m>9:
    m/=10
    cnt+=1
ans=m-1+cnt*9
Ans=int(0)
while n>0:
    Ans+=n%10
    n/=10
print(int(max(Ans,ans)))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N=input()
b=0
count=0
if (len(set(N[1:]))==1)and(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()
b=0
i=len(N)-1
count=0
for i in range(len(N)):
    if i==0:
        count=int(N[i])-1
    else:
        count=count+9

print(count)

Submission status: Wrong Answer

Solution code:
i=int(input())
ans=0
while(i>0):
    ans+=i%10
    i//=10
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())

l = len(str(n))
if n < 10:
    ans = n
else:
    ans = 9 * (l-1) + int(str(n)[0]) - 1
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())

l = len(str(n))
ans = 9 * (l-1) + int(str(n)[0]) - 1
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline

n = int(input())
n = str(n)
ans = (len(n) - 1) * 9

for i in range(1, len(n)):
  if int(n[i]) != 9:
    ans += int(n[0]) - 1
    break
    
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline

n = int(input())
n = str(n)
ans = (len(n) - 1) * 9

for i in range(1, len(n)):
  if int(n[i]) != 9:
    ans += int(n[i - 1]) - 1
    break

print(ans)

Submission status: Wrong Answer

Solution code:
s = input()
n = int(s)
l = len(s)
isall9 = True
for i in range(1, l):
    if s[i] != "9":
        isall9 = False
if isall9:
    print(1 + 9 * (l - 1) )
else:
    res = int(int(s[0]) - 1) + 9 * (l - 1)
    print( res)

Submission status: Wrong Answer

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

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())

l = len(str(n))

top = n // (10**(l-1))
if top == 1:
	print(9 * (l - 1))
else:
	print(top - 1 + 9 * (l - 1))

Submission status: Wrong Answer

Solution code:
n = input()

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

Submission status: Wrong Answer

Solution code:
m=list(map(int,input().split()))
a=int(m[0])-1+(len(m)-1)*9
s=sum(m)
print(max(s,a))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def all_nine_check(num):
    for c in num:
        if c == '9':
            pass
        else:
            return False
    return True

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
# coding: utf-8
N=int(input())
ans=0
n=0
for i in range(N):
    if 10**i>N:
        n=i
        break

if n==1 or n==0:
    print(N)
else:
    ans=9*(n-1)
    n0=int(str(N)[0])
    n1=int(str(N)[1])
    #print(n0,n1)
    if n1==0:
        ans=ans+n0-1
        print(ans)
    else:
        ans=max(ans,ans-9+n1-1+n0,ans+n0-1)
        print(ans)

Submission status: Wrong Answer

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

if n == 10 ** l -1:
    print( 9 * l )
elif 1 <= n <= 9:
    print(n)
else:
    print(n // (10 ** (l-1)) - 1 + 9 * (l-1))

Submission status: Wrong Answer

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

if n == 10 ** l -1:
    print( 9 * l )
else:
    print(n // (10 ** (l-1)) - 1 + 9 * (l-1))

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
N=int(input())

if 1==len(set(list(str(N)))) and int(str(N)[0])==9:
    ans=9*len(str(N))
else:
    ans=9*(len(str(N))-1) + int(str(N)[0])-1

print(ans)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
N = int(input())
l = len(str(N))
ans = 0
for i in range(1, 9):
    if N >= int("{}{}".format(i, "9"*(l-1))):
        ans = max(ans, 9*(l-1) + i)
if ans == 0:
    ans = 9 * (l-1)
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
 
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #int(input())
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) #list(map(int,input().split()))
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #input()
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) #list(input().split())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]

#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？

n=ii()
ns=list(str(n))
if len(ns)==1:
    print(n)
    exit()
print(ns[1:])
if int("".join(ns[1:])) == int("".join([str(9)]*(len(ns)-1))):
    print(int(ns[0])+9*(len(ns)-1))
else:
    print(int(ns[0])+9*(len(ns)-1)-1)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import math

def digit(n):
    return len(str(n))

def digitsum(n):#nは正の整数、各位の和、許容は１０＾１０００
    if n<10:
        return n
    else:
        m=n//10
        return n%10+digit(m)

def maxdigit(N):
    if digit(N)==1:
        return N
    else:
        return max([9*(digit(N)-1)+int(str(N)[0])-1,digitsum(N)])

N=int(input())
print(maxdigit(N))

Submission status: Wrong Answer

Solution code:
import math

def maxdigit(N):
    digit=len(str(N))
    if N==1:
        return 1
    elif N==10**(digit-1):
        return 9*(digit-1)
    elif N==10**digit-1:
        return 9*digit
    else:
        if digit==1:
            return N
        else:
            return 9*(digit-1)+int(str(N)[0])-1

N=int(input())
print(maxdigit(N))

Submission status: Wrong Answer

Solution code:
import math

def maxdigit(N):
    digit=len(str(N))
    if N==1:
        return 1
    elif N==10**(digit-1):
        return 9*(digit-1)
    else:
        if digit==1:
            return N
        else:
            return 9*(digit-1)+int(str(N)[0])-1

N=int(input())
print(maxdigit(N))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
s = input()
n = int(s)

m = str(int(s[0]) - 1) + (len(s) - 1) * "9" 
ans1 = 0
for i in range(len(m)):
    ans1 += int(m[i])

if s[-1] != "9":
    n1 = n - int(s[-1]) + 1
    s = str(n1)

ans2 = 0
for i in range(len(s)):
    ans2 += int(s[i])

print(max(ans1, ans2))

Submission status: Wrong Answer

Solution code:
s = input()
n = int(s)

m = str(int(s[0]) - 1) + (len(s) - 1) * "9" 
ans1 = 0
for i in range(len(m)):
    ans1 += int(m[i])

if s[-1] != "9":
    n = n - int(s[-1]) +1
    s = str(n)

ans2 = 0
for i in range(len(s)):
    ans2 += int(s[i])



print(max(ans1, ans2))