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 = int(input())
cn = str(n)
ans = 0
if n%10==0 and (n/10)%10==0:
    cn = str(n-1)
elif (n+1)%10==0 and ((n+1)/10)%10==0:
    cn = str(n)
else:
    cn = str(int(cn[0])-1)+str(9)*(len(cn)-1)
for i in cn:
    ans+=int(i)
print(ans)

Submission status: Wrong Answer

Solution code:
N = list(map(str, input().split()))
print(max(sum([int(i) for i in N]), 9*(len(N)-1)+int(N[0])-1))

Submission status: Wrong Answer

Solution code:
n = input()
n = list(n)
#9行目のエラーを防ぐためにstrからlistに変換
if len(n) == 1:
  print(n)
  exit()

if n[-2] != '9' and n[-1] != '9':
  n[-2] = '9'
  n[-1] = str(int(n[-1])+1)

N = [int(i) for i in n]
#listをstrからintに変換
print(sum(N))

Submission status: Wrong Answer

Solution code:
import sys
def S(): return sys.stdin.readline().rstrip()
N = S()
if int(N)<=8:
    print(N)
elif all([n=='9' for n in N]):
    print(9*len(N))
else:
    print(int(N[0])-1+9*(len(N)-1))

Submission status: Wrong Answer

Solution code:
import bisect,collections,copy,heapq,itertools,math,numpy,string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
N = I()
A = [LI() for _ in range(N)]

Submission status: Wrong Answer

Solution code:
import sys
def S(): return sys.stdin.readline().rstrip()
N = S()
if all([n=='9' for n in N]):
    print(9*len(N))
else:
    print(int(N[0])-1+9*(len(N)-1))

Submission status: Wrong Answer

Solution code:
n = list(map(int, list(input().strip())))
print(n)

total = sum(n)

for i in range(len(n)):
    subtotal = 0
    for j in range(i - 1):
        subtotal += n[j]
    subtotal += n[i] - 1
    for k in range(i + 1, len(n)):
        subtotal += 9

    total = max(total, subtotal)

print(total)

Submission status: Wrong Answer

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

def judge(s):
    for i in range(len(s)):
        if s[i] != "9":
            return True
    return False
print(n // (10 ** (d - 1)) - 1 + 9 * (d - 1) if judge(str(n))  else 9 * d)

Submission status: Wrong Answer

Solution code:
n = int(input())
d = len(str(n))
print(n // (10 ** (d - 1)) - 1 + 9 * (d - 1))

Submission status: Wrong Answer

Solution code:
N = int(input())
S = str(N)
if(len(S) == 1): print(S); exit(0)
if(len(S) == 2): print(max(N // 10 + N % 10, N // 10 - 1 + 9)); exit(0)
for i in range(len(S)):
    if(i == 0 and int(S[i]) == 1): continue
    if(int(S[i]) != 9):
        print(int(S[0]) - 1 + (len(S) - 1) * 9)
        exit(0)
print(1 + (len(S) - 1) * 9) if int(S[0]) == 1 else print(len(S) * 9)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = str(N)
if(len(S) == 1): print(S); exit(0)
if(len(S) == 2): print(max(N // 10 + N % 10, N // 10 - 1 + 9)); exit(0)
for i in range(len(S)):
    if(int(S[i]) != 9):
        print(int(S[0]) - 1 + (len(S) - 1) * 9)
        exit(0)
print(len(S) * 9)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = str(N)
if(len(S) == 1): print(S); exit(0)
if(len(S) == 2): print(max(N // 10 + N % 10, N // 10 - 1 + 9))
for i in range(len(S)):
    if(int(S[i]) != 9):
        print(int(S[0]) - 1 + (len(S) - 1) * 9)
        exit(0)
print(len(S) * 9)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = str(N)
if(len(S) == 1): print(S); exit(0)
for i in range(len(S)):
    if(int(S[i]) != 9):
        print(int(S[0]) - 1 + (len(S) - 1) * 9)
        exit(0)
print(len(S) * 9)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
S = str(N)
if(len(S) == 1):
    print(N)
    exit(0)
if(len(S) == 2):
    print(N // 10 * N % 10, (N // 10 - 1) * 9)
    exit(0)
a = int(S[0]) - 1 + (len(S) - 1) * 9
b = int(S[0]) + max(len(S) - 2, 0) * 9 + N % 10
c = int(S[0]) + max(len(S) - 3, 0) * 9 + (int(S[-2]) - 1) + 9
print(max(a, b, c))

Submission status: Wrong Answer

Solution code:
N = input()

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

Submission status: Wrong Answer

Solution code:
n = int(input())
flag = 0
ans = 0
if len(str(n)) > 2:
    ans += (len(str(n)) - 2) * 9
    X = n // 10 ** (len(str(n)) - 2)
    if str(n % 10 ** (len(str(n)) - 2)).count('9') == len(str(n)) - 2:
        flag = 1
    if X % 10 == 0 and flag == 1:
        flag = 0
    if X // 10 == 9 and X % 10 != 9 and flag == 1:
        flag = 0
    ans += (X // 10 - 1) + 9
elif len(str(n)) == 1:
    ans += n
else:
    if n == 99:
        flag = 1
    ans += (n // 10 - 1) + 9
if flag == 1:
    ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
flag = 0
ans = 0
if len(str(n)) > 2:
    ans += (len(str(n)) - 2) * 9
    X = n // 10 ** (len(str(n)) - 2)
    if str(n % 10 ** (len(str(n)) - 2)).count('9') == len(str(n)) - 2:
        flag = 1
    if X % 10 == 0 and flag == 1:
        flag = 0
    ans += (X // 10 - 1) + 9
elif len(str(n)) == 1:
    ans += n
else:
    if n == 99:
        flag = 1
    ans += (n // 10 - 1) + 9
if flag == 1:
    ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
ans = 0
if len(str(n)) > 2:
    ans += (len(str(n)) - 2) * 9
    X = n // 10 ** (len(str(n)) - 2)
    if str(n % 10 ** (len(str(n)) - 2)).count('9') == len(str(n)) - 2:
        ans += 1
    ans += (X // 10 - 1) + 9
elif len(str(n)) == 1:
    ans += n
else:
    if n == 99:
        ans += 1
    ans += (n // 10 - 1) + 9
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
ans = 0
if len(str(n)) > 2:
    ans += (len(str(n)) - 2) * 9
    X = n // 10 ** (len(str(n)) - 2)
    if str(n % 10 ** (len(str(n)) - 2)).count('9') == len(str(n)) - 2:
        ans += 1
else:
    X = n
    if X == 99:
        ans += 1
if len(str(X)) == 1:
    ans += X
else:
    if X % 10 == 0 or X // 10 == 9:
        ans -= 1
    ans += (X // 10 - 1) + 9
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
flag = 0
ans = 0
if len(str(n)) > 2:
    ans += (len(str(n)) - 2) * 9
    X = n // 10 ** (len(str(n)) - 2)
    if str(n % 10 ** (len(str(n)) - 2)).count('9') == len(str(n)) - 2:
        flag = 1
else:
    X = n
    if str(X).count('9') == len(str(X)):
        flag = 1

if len(str(X)) == 1:
    ans += X
else:
    if X % 10 == 0:
        flag = 0
    ans += (X // 10 - 1) + 9
if flag:
    ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
flag = 0
ans = 0
if len(str(n)) > 2:
    ans += (len(str(n)) - 2) * 9
    X = n // 10 ** (len(str(n)) - 2)
    if str(n % 10 ** (len(str(n)) - 2)).count('9') == len(str(n)) - 2:
        flag = 1
else:
    X = n

if len(str(X)) == 1:
    ans += X
else:
    if X % 10 == 0:
        flag = 0
    ans += (X // 10 - 1) + 9
if flag:
    ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
flag = 0
ans = 0
if len(str(n)) > 2:
    ans += (len(str(n)) - 2) * 9
    X = n // 10 ** (len(str(n)) - 2)
    if str(n % 10 ** (len(str(n)) - 2)).count('9') == len(str(n)) - 2:
        flag = 1
else:
    X = n

if len(str(X)) == 1:
    ans += X
else:
    if X // 10 == 1:
        ans += 9
        flag = 0
    else:
        ans += (X // 10 - 1) + 9
if flag:
    ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
flag = 0
ans = 0
if len(str(n)) > 2:
    ans += (len(str(n)) - 2) * 9
    X = n // 10 ** (len(str(n)) - 2)
    if str(n % 10 ** (len(str(n)) - 2)).count('9') == len(str(n)) - 2:
        flag = 1
else:
    X = n
if len(str(X)) == 1:
    ans += X
else:
    if X == 10:
        ans += 9
        flag = 0
    else:
        ans += (X // 10 - 1) + 9
if flag:
    ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
flag = 0
ans = 0
if len(str(n)) > 2:
    ans += (len(str(n)) - 2) * 9
    X = n // 10 ** (len(str(n)) - 2)
    if str(n % 10 ** (len(str(n)) - 2)).count('9') == len(str(n)) - 2:
        flag = 1
else:
    X = n
if len(str(X)) == 1:
    ans += X
else:
    if X == 10:
        ans += 9
    else:
        ans += (X // 10 - 1) + 9
if flag:
    ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
import re
import math
from collections import defaultdict
from collections import deque
import itertools
from copy import deepcopy
import random
import time
import os
import queue
import sys
import datetime
from functools import lru_cache
#@lru_cache(maxsize=None)
readline=sys.stdin.readline
sys.setrecursionlimit(2000000)
#import numpy as np
alphabet="abcdefghijklmnopqrstuvwxyz"
mod=int(10**9+7)
inf=int(10**20)
def yn(b):
    if b:
        print("yes")
    else:
        print("no")
def Yn(b):
    if b:
        print("Yes")
    else:
        print("No")
def YN(b):
    if b:
        print("YES")
    else:
        print("NO")
class union_find():
    def __init__(self,n):
        self.n=n
        self.P=[a for a in range(N)]
        self.rank=[0]*n
 
    def find(self,x):
        if(x!=self.P[x]):self.P[x]=self.find(self.P[x])
        return self.P[x]
 
    def same(self,x,y):
        return self.find(x)==self.find(y)
 
    def link(self,x,y):
        if self.rank[x]<self.rank[y]:
            self.P[x]=y
        elif self.rank[y]<self.rank[x]:
            self.P[y]=x
        else:
            self.P[x]=y
            self.rank[y]+=1
 
    def unite(self,x,y):
        self.link(self.find(x),self.find(y))
 
    def size(self):
        S=set()
        for a in range(self.n):
            S.add(self.find(a))
        return len(S)
def is_pow(a,b):#aはbの累乗数か
    now=b
    while now<a:
        now*=b
    if now==a:return True
    else:return False
def bin_(num,size):
    A=[0]*size
    for a in range(size):
        if (num>>(size-a-1))&1==1:
            A[a]=1
        else:
            A[a]=0
    return A
def get_facs(n,mod_=0):
    A=[1]*(n+1)
    for a in range(2,len(A)):
        A[a]=A[a-1]*a
        if(mod_>0):A[a]%=mod_
    return A
def comb(n,r,mod,fac):
    if(n-r<0):return 0
    return (fac[n]*pow(fac[n-r],mod-2,mod)*pow(fac[r],mod-2,mod))%mod
def next_comb(num,size):
    x=num&(-num)
    y=num+x
    z=num&(~y)
    z//=x
    z=z>>1
    num=(y|z)
    if(num>=(1<<size)):return False
    else:return num
def get_primes(n,type="int"):
    if n==0:
        if type=="int":return []
        else:return [False]
    A=[True]*(n+1)
    A[0]=False
    A[1]=False
    for a in range(2,n+1):
        if A[a]:
            for b in range(a*2,n+1,a):
                A[b]=False
    if(type=="bool"):return A
    B=[]
    for a in range(n+1):
        if(A[a]):B.append(a)
    return B
def is_prime(num):
    if(num<=1):return False
    i=2
    while i*i<=num:
       if(num%i==0):return False
       i+=1
    return True
def ifelse(a,b,c):
    if a:return b
    else:return  c
def join(A,c=""):
    n=len(A)
    A=list(map(str,A))
    s=""
    for a in range(n):
        s+=A[a]
        if(a<n-1):s+=c
    return s
def factorize(n,type_="dict"):
    b = 2
    list_ = []
    while b * b <= n:
        while n % b == 0:
            n //= b
            list_.append(b)
        b+=1
    if n > 1:list_.append(n)
    if type_=="dict":
        dic={}
        for a in list_:
            if a in dic:
                dic[a]+=1
            else:
                dic[a]=1
        return dic
    elif type_=="list":
        return list_
    else:
        return None
def floor_(n,x=1):
    return x*(n//x)
def ceil_(n,x=1):
    return x*((n+x-1)//x)
    return ret
def seifu(x):
    return x//abs(x)
######################################################################################################
def main():
    n=input()
    ans=0
    for a in n:
        ans+=int(a)
    ans=max((len(n)-1)*9,ans)
    print(ans)

main()

Submission status: Wrong Answer

Solution code:
N = input()

if N[1:] == ["9"] * (len(N)-1):
    sum1 = 0
    for i in range(len(N)):
        sum1 += int(N[i])
    print(sum1)

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

Submission status: Wrong Answer

Solution code:
N = input()

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

Submission status: Wrong Answer

Solution code:
# https://atcoder.jp/contests/agc021/tasks/agc021_a

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

Submission status: Wrong Answer

Solution code:
# https://atcoder.jp/contests/agc021/tasks/agc021_a

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

Submission status: Wrong Answer

Solution code:
# https://atcoder.jp/contests/agc021/tasks/agc021_a

n = input()
ans = int(n[0]) - 1 + 9 * (len(n) - 1)
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 = input()
print((len(n)-1)*9+(int(n[0])-1))

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()
x = len(n)

if x == 1:
  print(int(n))
else:
  if int(n[0]) < int((int(n) + 1) / int("1"+"0"*(x-1))):
    print(int(n))
  else:
    print(int(n[0]) - 1 + 9 * (x - 1))

Submission status: Wrong Answer

Solution code:
n = input()
int_n = int(n)
len_n = len(n)
ans = 0

# if n[0] == '1' and n[1:] == '0'*(len_n-1):
#     print(9 * (len_n - 1))
#     exit()

for i in range(len_n):
    target = int(n[:i+1][-1]) -1
    if target < 0:
        continue
    tmp_n = n[:i] + str(target) + '9'* (len_n - i - 1)
    tmp_n_ans = sum([int(i) for i in tmp_n])
    ans = max(tmp_n_ans, ans)
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
S = list(input())
S = list(map(lambda x: int(x),S))
ans = 0

for i in range(len(S) - 1,0,-1):
  
  if S[i] == 9:
    tmp = sum(S)
  else:
    S[i] = 9
    S[i - 1] -= 1
    tmp = sum(S)
  
  ans = max(tmp,ans)
    
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
S = input()
N = len(S)

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

Submission status: Wrong Answer

Solution code:
s = input()
n = len(s)
if n==1:
  print(s)
  exit()
ans = 0
for i in range(n):
  res =0 
  d = int(s[i])
  if d==0:
    continue
  else:
    d -= 1
  for c in s[:i]:
    res += int(c)
  res += d
  res += (n-i-1)*9
  ans = max(ans, res)
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = input()
ans = 0
accu = 0
for i, j in enumerate(n):
    j = int(j)
    if j>0:
        ans = max(ans, accu+j-1+9*(len(n)-i-1))
    accu += j
print(ans)

Submission status: Wrong Answer

Solution code:
import sys

input = sys.stdin.readline
MOD = 1000000007

N  = input()[:-1]

if len(N)== 1:
    print(int(N))
elif len(N)  == 2:
    if N[-1] == '9':
        print(int(int(N)/10) + 9)
    else:
        print(int(int(N)/10)-1 + 9)

else:
    res = 0
    if N[0] == '9':
        res = 9*(len(N)-1)+8
    else:
        check = True
        for i in range(1,len(N)):
            if N[i] != '9':
                check = False
            if check:
                res = 9*(len(N)-1)+int(N[0])
            else:
                res = 9*(len(N)-1)+int(N[0])-1
    print(res)

Submission status: Wrong Answer

Solution code:
import sys

input = sys.stdin.readline
MOD = 1000000007

N  = input()[:-1]

if len(N)== 1:
    print(int(N))
elif len(N)  == 2:
    if N[-1] == '9':
        print(int(int(N)/10) + 9)
    else:
        print(int(int(N)/10)-1 + 9)

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

Submission status: Wrong Answer

Solution code:
N = input()

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

Submission status: Wrong Answer

Solution code:
N=input()
n=int(N)
#N1=[int(x) for x in list(N[:i+1])]
#n=int(N)
if n<10:
    print(n)
    exit()
else:
    ans=0
    for i in range(len(N)-1):
        N2=int(N[:i+1])-1
        
        N1=[int(x) for x in list(str(N2))]
        ans=max(ans,sum(N1)+9*(len(N)-i-1))
    print(ans)

Submission status: Wrong Answer

Solution code:
N=input()
n=int(N)
N1=[int(x) for x in list(N)]
#n=int(N)
if n<10:
    print(n)
    exit()
else:
    ans=0
    for i in range(len(N)-1):
        ans=max(ans,sum(N1[:i+1])-1+9*(len(N)-i-1))
    print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys
## io ##
def IS(): return sys.stdin.readline().rstrip()
def II(): return int(IS())
def MII(): return list(map(int, IS().split()))
def MIIZ(): return list(map(lambda x: x-1, MII()))
## dp ##
def DD2(d1,d2,init=0): return [[init]*d2 for _ in range(d1)]
def DD3(d1,d2,d3,init=0): return [DD2(d2,d3,init) for _ in range(d1)]
## math ##
def to_bin(x: int) -> str: return format(x, 'b') # rev => int(res, 2)
def to_oct(x: int) -> str: return format(x, 'o') # rev => int(res, 8)
def to_hex(x: int) -> str: return format(x, 'x') # rev => int(res, 16)
MOD=10**9+7
def divc(x,y) -> int: return -(-x//y)
def divf(x,y) -> int: return x//y
def gcd(x,y):
    while y: x,y = y,x%y
    return x
def lcm(x,y): return x*y//gcd(x,y)
def enumerate_divs(n):
    """Return a tuple list of divisor of n"""
    return [(i,n//i) for i in range(1,int(n**0.5)+1) if n%i==0]
def get_primes(MAX_NUM=10**3):
    """Return a list of prime numbers n or less"""
    is_prime = [True]*(MAX_NUM+1)
    is_prime[0] = is_prime[1] = False
    for i in range(2, int(MAX_NUM**0.5)+1):
        if not is_prime[i]: continue
        for j in range(i*2, MAX_NUM+1, i):
            is_prime[j] = False
    return [i for i in range(MAX_NUM+1) if is_prime[i]]
## libs ##
from itertools import accumulate as acc
from collections import deque, Counter
from heapq import heapify, heappop, heappush
from bisect import bisect_left
#======================================================#

def main():
    n = II()
    s = str(n)
    d = len(s)
    maxv = 0
    for i in range(d):
        l = sum(int(si) for si in s[:i])
        l += int(s[i])-1
        l += 9*(d-i-1)
        maxv = max(maxv, l)
    print(maxv)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())

def get_first(n):
	return int(str(n)[0])

def check(n):
	# x99..99かどうか
	for i in range(1, len(str(n))):
		if str(i) != '9':
			return False
	return True


if check(n):
	res = get_first(n) + 9 * (len(str(n)) - 1)
else:
	res = (get_first(n) - 1) + 9 * (len(str(n)) - 1)

print(res)

Submission status: Wrong Answer

Solution code:
n = int(input())

def get_first(n):
	return int(str(n)[0])

if get_first(n) == 1:
	res = 9 * (len(str(n)) - 1)
else:
	res = (get_first(n) - 1) + 9 * (len(str(n)) - 1)

print(res)

Submission status: Wrong Answer

Solution code:

import math

def digitSum(n):
    s = str(n)
    array = list(map(int, s))
    return sum(array)

def calc(n):
    ans = []
    for i in range(len(str(n))):
        target = n-10**i
        target = math.floor(target/(10**i))
        for _ in range(i):
            target*=10
            target+=9
        ans.append(digitSum(target))
#        print(target)
    return ans

N = int(input())
ans = max(calc(N))
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())

if N > 10:
    if (N%(int("1" + (len(str(N)) - 1)*"0"))) == int((len(str(N)) - 1) * "9"):
        tmp = list(str(N))
        tmp = [int(item) for item in tmp]
        print(sum(tmp))
    else:
        tmp = list(str(N - (N%(int("1" + (len(str(N)) - 1)*"0"))) - 1))
        tmp = [int(item) for item in tmp]
        print(sum(tmp))
else:
    print(N)

Submission status: Wrong Answer

Solution code:
N = int(input())
maxnum = 0

if (N%(int("1" + (len(str(N)) - 1)*"0"))) == 999:
    tmp = list(str(N))
    tmp = [int(item) for item in tmp]
    print(sum(tmp))
else:
    tmp = list(str(N - (N%(int("1" + (len(str(N)) - 1)*"0"))) - 1))
    tmp = [int(item) for item in tmp]
    print(sum(tmp))

Submission status: Wrong Answer

Solution code:
S=input()
dp=[[0 for i in range(len(S))] for j in range(2)]
if len(S)==1:
    print(S)
    exit()
dp[0][0]=int(S[0])
dp[1][0]=int(S[0])-1
for i in range(len(S)-1):
    dp[0][i+1] = dp[0][i]+int(S[i+1])
    dp[1][i+1] = max(dp[0][i]+int(S[i+1])-1,dp[1][i]+9)
print(dp[1][len(S)-1])

Submission status: Wrong Answer

Solution code:
S=input()
dp=[[0 for i in range(len(S))] for j in range(2)]
dp[0][0]=int(S[0])
dp[1][0]=int(S[0])-1
for i in range(len(S)-1):
    dp[0][i+1] = dp[0][i]+int(S[i+1])
    dp[1][i+1] = max(dp[0][i]+int(S[i+1])-1,dp[1][i]+9)
print(dp[1][len(S)-1])

Submission status: Wrong Answer

Solution code:
# もし全部が9なら、9*N
# 一桁目が9以外なら (一桁目-1) + (len(N)-1 * 9)
# 一桁目が9なら　一桁目が8 + len(N)-1 * 9
S = (input())

if S.count("9") == len(S):
    print(len(S)*9)

elif len(S) == 1:
    print(int(S))

elif S.count("9") == (len(S)-1):
    print((int(S[0])) + (len(S)-1)*9)

elif S[0] == "9":
    print(8 + ((len(S)-1)*9))
else:
    print((int(S[0])-1) + (len(S)-1)*9)

Submission status: Wrong Answer

Solution code:
# もし全部が9なら、9*N
# 一桁目が9以外なら (一桁目-1) + (len(N)-1 * 9)
# 一桁目が9なら　一桁目が8 + len(N)-1 * 9
S = (input())

if S.count("9") == len(S):
    print(len(S)*9)

elif len(S) == 1:
    print(int(S))

elif S[0] == "9":
    print(8 + ((len(S)-1)*9))
else:
    print((int(S[0])-1) + (len(S)-1)*9)

Submission status: Wrong Answer

Solution code:
# もし全部が9なら、9*N
# 一桁目が9以外なら (一桁目-1) + (len(N)-1 * 9)
# 一桁目が9なら　一桁目が8 + len(N)-1 * 9
S = (input())

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

Submission status: Wrong Answer

Solution code:
import sys
import time
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7

def main():
    N = input()
    L = len(N)
    if L == 1:
        ans = int(N)
    elif set(N[1:]) == {'9'}:
        ans = int(N)
    else:
        ans = (int(N[0])-1) + 9*(L-1)
    print(ans)
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
import time
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7

def main():
    N = input()
    L = len(N)
    ans = (int(N[0])-1) + 9*(L-1)
    print(ans)
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations # (string,3) 3回
from collections import deque
from collections import defaultdict
import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def main():
    n = input()
    if len(n) == 1:
        print(n)
        exit()
    allnine = True
    for i in range(1,len(n)):
        if n[i] == '9':
            pass
        else:
            allnine = False
    if allnine:
        print(n)
        exit()
    if n[0] == '1':
        print((len(n)-1) * 9)
        exit()
    print(int(n[0]) + (len(n)-1) * 9 - 1)

if __name__ == '__main__':
  main()

Submission status: Wrong Answer

Solution code:
N=int(input())

s=str(N)
if len(s)==1:
    print(N)
    exit()
val=9*(len(s)-1)
val+=(int(s[0])-1)
print(val)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = input()
digit = len(n) - 1

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

Submission status: Wrong Answer

Solution code:
N = int(input())
if set(list(str(N))) == {"9"}:
    print(9 * len(str(N)))
elif N < 10:
    print(N)
else:
    print(9 * (len(str(N)) - 1) + int(str(N)[0]) - 1)

Submission status: Wrong Answer

Solution code:
N = int(input())
if set(list(str(N))) == ["9"]:
    print(9 * len(str(N)))
elif N < 10:
    print(N)
else:
    print(9 * (len(str(N)) - 1) + int(str(N)[0]) - 1)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = input()
Dig = len(N)
num = None
if Dig == 1:
    print(N)
else:
    for i in range(Dig-1):
        if N[i+1] != str(9):
            num = i
            print(num)
            break
        else:
            continue
    list_num = list(N)
    if not num == None:
        target = int(list_num[num]) -1
        array = list(map(int,N))
        print(target)
        ans = sum(array[:num]) + target + 9*(Dig-num-1)
        print(ans)
    else:
        array = list(map(int,N))
        print(sum(array))

Submission status: Wrong Answer

Solution code:
N = input()
Dig = len(N)
num = None
if Dig == 1:
    print(N)
else:
    for i in range(Dig-1):
        if N[i+1] != str(9):
            num = i
            break
        else:
            continue
    list_num = list(N)
    if not num == None:
        target = int(list_num[num]) -1
        ans = 9*(num) + target + 9*(Dig-num-1)
        print(ans)
    else:
        array = list(map(int,N))
        print(sum(array))

Submission status: Wrong Answer

Solution code:
N = input()
Dig = len(N)
num = None
if Dig == 1:
    print(N)
else:
    for i in range(Dig-1):
        if N[i] != str(9) and N[i+1] != str(9):
            num = i
            break
        else:
            continue
    list_num = list(N)
    if num:
        target = int(list_num[num]) -1
        ans = 9*(num -1) + target + 9*(Dig)
        print(ans)
    else:
        array = list(map(int,N))
        print(sum(array))

Submission status: Wrong Answer

Solution code:
N = input()
Dig = len(N)
num = None
if Dig == 1:
    print(N)
else:
    for i in range(Dig-1):
        if N[i] != str(9) and N[i+1] != str(9):
            num = i
            print(num)
            break
        else:
            continue
    list_num = list(N)
    if num:
        target = int(list_num[num]) -1
        ans = 9*(num -1) + target + 9*(Dig)
        print(ans)
    else:
        array = list(map(int,N))
        print(sum(array))

Submission status: Wrong Answer

Solution code:
N = input()
Dig = len(N)
if Dig == 1:
    print(N)
else:
    for i in range(Dig):
        if N[i] != 9:
            num = i
            break
        else:
            continue
    list_num = list(N)
    target = int(list_num[num]) -1
    ans = 9*(num -1) + target + 9*(Dig)
    print(ans)

Submission status: Wrong Answer

Solution code:
N = input()
for i in range(len(N)):
    if N[i] != 9:
        num = i
        break
    else:
        continue
list_num = list(N)
target = int(list_num[num]) -1
ans = 9*(num -1) + target + 9*(len(N) - num)
print(ans)

Submission status: Wrong Answer

Solution code:
import math

n = str(input())

o = int(math.log10(int(n))//1)

if o == 0:
    print(n)
elif n[1:] == "9" * o:
    print(int(n[0]) + 9*o)
else:
    print(int(n[0]) - 1 + 9*o)

Submission status: Wrong Answer

Solution code:
import math

n = str(input())

o = int(math.log10(int(n))//1)

if o == 0:
    print(n)
elif n[o-1:] == "9" * o:
    print(int(n[0]) + 9*o)
else:
    print(int(n[0]) - 1 + 9*o)

Submission status: Wrong Answer

Solution code:
import sys
import math

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

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
import math

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

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
import math

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

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
import math

def main():
    N = int(input())
    digit = int(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()