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: Runtime Error

Solution code:
n = str(input())
if n == 1:
    print(1)
    exit()
if n[0] == "1":
    tmpint = eval("9"*(len(n)-1))
    #print("tmpint",tmpint)
else:
    tmpint = eval(str(eval(n[0])-1) + "9"*(len(n)-1))
    #print("tmpint",tmpint)
tmpsum = sum([
        eval(str(tmpint)[i]) for i in range(len(str(tmpint)))
    ])
ssum = sum([
        eval(n[i]) for i in range(len(str(n)))
    ])
print(max(tmpsum,ssum))
#print(tmpsum,ssum)

Submission status: Runtime Error

Solution code:
n = str(input())
if n[0] == "1":
    tmpint = eval("9"*(len(n)-1))
    #print("tmpint",tmpint)
else:
    tmpint = eval(str(eval(n[0])-1) + "9"*(len(n)-1))
    #print("tmpint",tmpint)
tmpsum = sum([
        eval(str(tmpint)[i]) for i in range(len(str(tmpint)))
    ])
ssum = sum([
        eval(n[i]) for i in range(len(str(n)))
    ])
print(max(tmpsum,ssum))
#print(tmpsum,ssum)

Submission status: Runtime Error

Solution code:
n=int(input())
k=list(str(n))
ans=0
print(max(sum(k),9*len(k)-9+k[0]-1))

Submission status: Runtime Error

Solution code:
n = str(input())

li_n = list(map(int,n))

s = li_n[-1] + 1

ans = int(n) - s

ans2 = list(map(int,str(ans)))

print(sum(ans2))

Submission status: Runtime Error

Solution code:
def main():
    n = input()

    l = len(n)

    nines = "9" * (l - 1)
    num = int(nines)

    for i in range(1, 10):
        tmp = str(i) + nines
        if int(tmp) <= int(n):
            num = tmp

    ans = sum(map(int, num))
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
def main():
    n = input()

    l = len(n)
    diff = ""
    for i, e in enumerate(n):
        if i == 0:
            c = 0
        elif i == l - 1:
            c = int(e) + 1
        else:
            c = int(e)

        c = str(c)
        diff += c

    num = int(n) - int(diff)
    num = str(num)
    ans = sum(map(int, num))
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
N=input()

def calc(str):
    l=list(map(int,str))
    all=sum(l)
    
    return all

cand1=str(int(N)-int(N[-1])-1)
cand2=str(int(N[0])*10**(len(N)-1)-1)
print(max(calc(cand1),calc(cand2)))

Submission status: Runtime Error

Solution code:
N = str(input())
count = 0
new_n = ""

for i in range(len(N)):
    if N[i]!="9" and i==len(N)-1:
        new_n = str(int(N)-int(N[-1])-1)
        break
    elif N[i]!="9":
        new_n = str((int(N[i]) * 10**(len(N)-i-1)) -1)
        break

for j in new_n:
    count += int(j)

print(count)

Submission status: Runtime Error

Solution code:
n=int(input())
if n < 10 :
    print(n)
else:
    n=list(str(n))
    key=0
    for i in range(n):
        if n[1+i]!="9":
            key=1
    if key ==0:
        print((len(n)-1)*9+int(n[0]))
    else:
        print((len(n)-1)*9+int(n[0])-1)

Submission status: Runtime Error

Solution code:
def main():
    n = input()
    if len(n) == 1:
        print(n)
    else:
        ans = (len(n) - 1) * 9
        t = 0
        for i in range(len(n)):
            t += int(n[i])
        ans = max(ans, t)
        k = int(n)
        for i in range(len(n)-1):
            nn = str(k)
            m = int(nn[len(n) - i - 1:]) + 1
            #print(m)
            k -= m
            t = 0
            for j in range(len(str(k))):
                t += int(str(k)[j])
            ans = max(ans, t)
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
from math import log10
N = input()
n = int(N)
t = n % 10 ** int(log10(n)) + 1
if n == 0:
  print(0)
else:
  print(max(sum(map(int, N)), sum(map(int, str(n - t)))))

Submission status: Runtime Error

Solution code:
from math import log10
N = input()
n = int(N)
t = n % 10 ** int(log10(n)) + 1
print(max(sum(map(int, N)), sum(map(int, str(n - t)))))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n=list(map(int,list(input())))
k=len(n)
c=n[0]
for i in range(1,k):
    f=1
    if n[i]!=9:
        f=0
if f:
    print(sum(n))
else:
    print(c+9*(k-1)-1)

Submission status: Runtime Error

Solution code:
def main():
    N = input().strip()
    ans = 0
    count = 0
    for i in range(len(N)):
        if N[i] != "9":
            break
        count += 1
    if count == len(N):
        print(9*count)
    elif count == len(N)-1:
        print(9*count+int(N[-2])-1)
    else:
        print(9*(len(N)-1)+int(N[count])-1)

if __name__ == "__main__":
    main()

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
# 9or8で埋めたやつが強い あるいはオリジナル
# 桁を一つ落として（1なら9999...）残りを9で埋める
# オリジナルはたとえば199とかのとき19が最大になる

s = input()
tmp = 0
for i in s:
    tmp += int(i)
if s[0] == "1":
    print(max(9 * (len(s) - 1), tmp))
else:
    print(int(max(s[0]) - 1 + 9 * (len(s) - 1), tmp))

Submission status: Runtime Error

Solution code:
N = input()
l = len(N)
x = int(N[0])*int(pow(10, l-1))+int('9'*(l-1))
if int(N) < x:
    x -= 1
ans = 0
while x > 0:
    ans += x%10
    x //= 10
print(ans)

Submission status: Runtime Error

Solution code:
def sol(n):
    #n=input()
    if len(set(n[1:]))<=1 and (n[-1]=='9' or len(n)==1):
      m=0
    else:
      m=1
    print(int(n[0])+9*len(n)-9-m)

n=input()
sol(str(i))

Submission status: Runtime Error

Solution code:
# 2019/07/16
# AtCoder Grand Contest 021 - A
# For the answer: 
# 1. 桁分割、桁数Count
# 2-1. 上位桁から9以外を探索
# 2-2. 9以外があれば、その1つ上桁を-1
# 2-3. ただし先頭の場合は自身を-1
# 3. (桁数-1)*9 + 上位桁-1

# Input
n = int(input())

# 1.
wn = n
ketalist = list()
while wn > 0:
    ketalist.append(wn % 10)
    wn = int(wn / 10)

# 2. 
ketalist.reverse()
for i in range(len(ketalist)):
    if ketalist[i] < 9:
        if i == 0:
            tgtnum = ketalist[i] - 1
        else:
            tgtnum = ketalist[i-1] - 1
        break

# 3.
if len(ketalist) > 1:
    if ketalist[0] == 1:
        ans = (len(ketalist) - 1) * 9
    else:
        ans = (len(ketalist) - 1) * 9 + tgtnum
else:
    ans = n

# Output
print(ans)

Submission status: Runtime Error

Solution code:
# 2019/07/16
# AtCoder Grand Contest 021 - A
# For the answer: 
# 1. 桁分割、桁数Count
# 2-1. 上位桁から9以外を探索
# 2-2. 9以外があれば、その1つ上桁を-1
# 2-3. ただし先頭の場合は自身を-1
# 3. (桁数-1)*9 + 上位桁-1

# Input
n = int(input())

# 1.
wn = n
ketalist = list()
while wn > 0:
    ketalist.append(wn % 10)
    wn = int(wn / 10)

# 2. 
ketalist.reverse()
for i in range(len(ketalist)):
    if ketalist[i] < 9:
        if i == 0:
            tgtnum = ketalist[i] - 1
        else:
            tgtnum = ketalist[i-1] - 1
        break

# 3.
if ketalist[0] == 1:
    ans = (len(ketalist) - 1) * 9
else:
    ans = (len(ketalist) - 1) * 9 + tgtnum

# Output
print(ans)

Submission status: Runtime Error

Solution code:
n=input()
l=len(n)
a,b=0,0
while True:
    b+=n[a]
    a+=1
    if a==l:
      break
print(b)

Submission status: Runtime Error

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: Runtime Error

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))n = input()
l = len(n)
if l == 1:
    print(n)
elif set(list(n[1:])) == {"9"}:
    print(int(n[0])+9*(l-1))
else:
    print(int(n[0])-1+9*(l-1))

Submission status: Runtime Error

Solution code:
N = input()

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: Runtime Error

Solution code:
s = input()

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

Submission status: Runtime Error

Solution code:
n=input()
l=len(n)
flag=0
for i in range(l-1):
  if n[-i]!=9:
    flag=1
    break
ans=int(n[0]-1)+9*(l-1)
if flag==1:
  print(ans)
else:
  print(ans+1)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <cstdlib>
#include <iomanip>
typedef long long ll;
using namespace std;

int main () {
    string s;
    cin >> s;
    int top = s[0] - '0';
    bool f = true;
    ll n = s.size();
    for(int i = 1; i < n; i++)
    {
        if(s[i] != '9') {f=!f;break;}
    }
    if(f) {
        cout << top + 9 * (n - 1) << endl;
    }else {
        cout << top + 9 * (n - 1) - 1 << endl;
    }
}

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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: Runtime Error

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

Submission status: Runtime Error

Solution code:
n = input()

lst = list(map(int, list(n)))
print(sum(lst[0], lst[0] - 1 + 9 * (len(lst) - 1)))

Submission status: Runtime Error

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: Runtime Error

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(n) == 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: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
arr=[int(i) for i in input()]
csum=[arr[0]]
for i in range(1,len(arr)):
  csum.append(csum[-1]+arr[i])
maxsum= csum[-1]

print(max(maxsum,arr[0]-1+9*(len(are)-1)))

Submission status: Runtime Error

Solution code:
N = str(input())

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

Submission status: Runtime Error

Solution code:
N = str(input())

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

Submission status: Runtime Error

Solution code:
#include<bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define int long long
using namespace std;
signed main(){
	string a;
	cin >> a;
	int b;
	int n = a.size()-1;
	int x = stoll(a);
	while(x >= 10){
		b = x/10;
		x /= 10;
	}
	b--;
	cout << n*9+b;
    return 0;
}

Submission status: Runtime Error

Solution code:
n = int(input())
strs = [int(x) for x in str(n)]
kijyun = [9]*(len(strs)-1)
if strs[1:] == kijyun:
    print((len(strs)-1)*9+strs[1])
else:
    print((len(strs)-1)*9+strs[1]-1)

Submission status: Runtime Error

Solution code:
n = int(input())
strs = [int(x) for x in str(n)]
kijyun = [9]*(len(strs)-1)
if strs[1:] == kijyun:
    print((n-1)*9+strs[1])
else:
    print((n-1)*9+strs[1]-1)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n = int(input())

cand = 0

def digit_sum(num:int, base:int) -> int:
    if num < base:
        return num
    else:
        return digit_sum(int(num/base), base) + (num % base)

def judge(n: int) -> int:
    if n < 10:
        return n
    
    else:
        # 先頭の位が1のとき、先頭の1を落として全部9にしたものが候補
        if str(n)[0:1] == '1':
            cand = n % 10**(len(str(n)) - 1)
            print(cand)
            
            cand_str = "9"*len(str(cand))
            cand = int(cand_str)
            
            print(cand)
            
            return max(digit_sum(n,10), digit_sum(cand,10))
        
        # そうでないとき、先頭の位を1小さくする
        else:
            top = n // 10**(len(str(n)) - 1)
            cand_str = str(top-1) + "9" * (len(str(n))-1)
            cand = int(cand_str)
            
            return max(digit_sum(n,10), digit_sum(cand,10))
            
        
    


print(ans)

Submission status: Runtime Error

Solution code:
s = input()

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

Submission status: Runtime Error

Solution code:
#digit sum
import sys
import numpy as np

if N == 0:
    print(0)
else:
    N = int(input())
    a = int(np.log10(N))
    b = int(str(N)[0])
    string = str(N)
    poss = 0
    count = 0
    max_count = len(string) - 1
    for s in string[1:]:
        if s is '9': 
            count += 1
    if count is max_count:
        print(9 * a + b)
    else:
        print(9 * a + b - 1)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
def inpl(): return map(int, input().split())
N = input()
ans = 0

while N:
    if N[0] == "9":
        ans += 9
        N = N[1:]
    else:
        break

if all([n=="9" for n in list(N[1:])]):
    print(ans + int(N[0]) + len(N[1:])*9)
elif ans == 0:
    if len(N) == 1:
        ans = int(N)
    else:
        ans += int(N[0]) - 1 + len(N[1:])*9
    print(ans)
elif len(N)==0:
    print(ans)
else:
    print(ans - 1 + len(N)*9)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
l = list(input())

for i in range(len(l)-1, -1, -1):
  if not l[i] == '9' and not i == 0:
    l[i] = '9'
    if l[i-1] == '0':
      l[i-1] = '9'
    else:
      l[i-1] = str(int(l[i-1])-1)

if l[0] == '1':
  ans = '+'.join(l[1:])
  print(eval(ans))
else:
  ans = '+'.join(l)
  print(eval(ans))

Submission status: Runtime Error

Solution code:
a =input()

b = [x for x in list(a)]
if len(a) == 1:
    print(int(a))
elif len(a) == a[1:].count('9') + 1:
    print(sum(b))
else:
    print(int(b[0])-1+(len(a)-1)*9)

Submission status: Runtime Error

Solution code:
N=input()
digit=pow(10,len(N))
n=int(N)
c=0
c2=0
Q=0
n[c]=str(n/(digit/10))
while c2<n:
	while c<digit:
    	c=c+1
    	n[c]=(n[c-1]-(n*digit))/(digit/10)  
    while c>=0:
      ans[c2]=ans[c2]+n[c]
      c=c-1
	c2=1+c2
while c2>=0:
  if(Q<ans[c2]):
  	Q=ans[c2]
  c2=c2-1
print(Q)

Submission status: Runtime Error

Solution code:
if n<10:
  print(n)
else:
  L=list(map(int, list(str(n))))
  if(L.count(9)==len(L)) or (L[0]!=9 and L.count(9)==len(L) -1):
    print(sum(L))
  else :
    print(9*(len(L)-1)+int(L[0])-1)

Submission status: Runtime Error

Solution code:
n=int(input())
if N<10:
  print(n)
else:
  L=list(map(int, list(str(N))))
  if(L.count(9)==len(L)) or (L[0]!=9 and L.count(9)==len(L) -1):
    print(sum(L))
  else :
    print(9*(len(L)-1)+int(L[0])-1)

Submission status: Runtime Error

Solution code:
def digit_sum(n):
    result = 0
    while n != 0:
        result += n % 10
        n = n // 10
    return result

num = int(input())
print(max([digit_sum(n) for n in range(1, num)]))

Submission status: Runtime Error

Solution code:
n = input()

a = n[0]
b = n[1:]

if (int(b)+1) % (10 ** len(b)) == 0:
    flag = True
else:
    flag = False

if flag:
    ans = int(a) + 9 * len(b)
else:
    ans = int(a) - 1 + 9 * len(b)

print(ans)

Submission status: Runtime Error

Solution code:
max_sum_i = int(str(n)[0]) * 10**(len(str(n))-1) -1
max_sum = sum([int(i) for i in str(max_sum_i)])

print(max_sum)

Submission status: Runtime Error

Solution code:
N = [int(x) for x in input()]
print(max(sum(N), N[0]-1+9*len(N))

Submission status: Runtime Error

Solution code:
n = int(input())

if n < int("1" + "9"*(len(str(n))-1)):
	s = 9*(len(str(n))-1)
else:
	for i in range(1,10)[::-1]:
		if n > int(str(i) + "9"*(len(str(n))-1)):
			s = i + 9*(len(str(n))-1)
			break

print(s)

Submission status: Runtime Error

Solution code:
if __name__ == '__main__':
    # n = 100
    # n = 9995
    # n = 3141592653589793
    n = input()

    ary = list(map(int, list(str(n))))

    # x..xxの全探索
    m = -1
    middle = [9 for i in range(0, len(ary[1:-2]))] # 数列の真ん中
    for i in range(0, 10):
        for j in range(0, 10):
            for k in range(0, 10):
                if m < sum([i] + middle + [j, k]) and int(''.join(map(str, [i] + middle + [j, k]))) <= n:
                    m = sum([i] + middle + [j, k])
    print(m)

Submission status: Runtime Error

Solution code:
import math
N = int(input())
x = [0 for i in range(N)]
y = [0 for i in range(N)]
for i in range(N):
    x[i], y[i] = map(int, input().split())


def mindis(t):
    j = 0
    for i in range(N):
        if x[i]*math.sin(t)+y[i]*math.cos(t)<x[j]*math.sin(t)+y[i]*math.cos(t):
            j = i
    return j


r = [0 for i in range(N)]
M = 2500000
for i in range(M):
    k = mindis(2*math.pi*i/M)
    r[k] += 1
S = sum(r)
for i in range(N):
    print(r[i]/S)

Submission status: Runtime Error

Solution code:
#encoding=utf-8
def solve(n):
    k = len(n)
    c = str(n)[k - 1]
    if str(n)[1..k] = '9' * k:
        return c + 9 * (k - 1)
    return c + 9 * (k - 1)  - 1

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

Submission status: Runtime Error

Solution code:
from math import log10
N = int(input())
ans = []
for i in range(1,int(log10(N))+1):
    ans.append((sum(map(int,list(str((int(N/(10**i))*(10**i)-1)))))))
print(max(ans))

Submission status: Runtime Error

Solution code:
from math import acos, hypot, pi


class Point:
    def __init__(self, i, x, y):
        self.i = i
        self.x = int(x)
        self.y = int(y)


class Line:
    def __init__(self, p1, p2):
        self.p1 = p1
        self.p2 = p2
        self.d2 = (p1.x - p2.x) ** 2 + (p1.y - p2.y) ** 2
        if p1.x == p2.x:
            self.a = 1
            self.b = 0
        else:
            self.a = p2.y - p1.y
            self.b = p1.x - p2.x
        self.c = -p1.y * self.b - p1.x * self.a

    def dist(self, p):
        f = self.a * p.x + self.b * p.y + self.c
        if f == 0:
            d12 = (self.p1.x - p.x) ** 2 + (self.p1.y - p.y) ** 2
            d22 = (self.p2.x - p.x) ** 2 + (self.p2.y - p.y) ** 2
            if self.d2 < max(d12, d22):
                return None
            return 0
        if f < 0:
            return -1
        else:
            return 1

    def kaku(self, other):
        x = self.a * other.a + self.b * other.b
        x /= hypot(self.a, self.b) * hypot(other.a, other.b)
        return pi - acos(x)


def make_p(n, pp):
    pids = {p.i: [] for p in pp}
    for i in range(n):
        if len(pids[i]) == 2:
            continue
        p1 = pp[i]
        for j in pids:
            if i == j or len(pids[j]) == 2:
                continue
            p2 = pp[j]
            line = Line(p1, p2)
            ptype = {0: 0, 1: 0, -1: 0, None: 0}
            for k in pids:
                if k == i or k == j:
                    continue
                ptype[line.dist(pp[k])] += 1
            if ptype[None]:
                continue
            if ptype[1] == 0 or ptype[-1] == 0:
                pids[i].append(j)
                pids[j].append(i)
    return pids


def main():
    n = int(input())
    if n == 2:
        print(0.5)
        print(0.5)
        return
    pp = []
    for i in range(n):
        p = Point(i, *input().split())
        pp.append(p)
    pids = make_p(n, pp)
    prob = [0.0] * n
    for i, nei in pids.items():
        if len(nei) == 2:
            l1 = Line(pp[i], pp[nei[0]])
            l2 = Line(pp[i], pp[nei[1]])
            kaku = l1.kaku(l2)
            prob[i] += kaku / (2 * pi)
    for p in prob:
        print(p)


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
N = int(input())


def kakuinowa(n):
    a = str(n)
    s = 0
    for i in range(len(a)):
        s = s + int(a[i])
    return s

import math
m = kakuinowa(N)
for i in range(int(math.log10(N)) + 1):
    n = kakuinowa((N // 10**i) * 10**i - 1)
    if n > m:
        m = n


print(m)

Submission status: Runtime Error

Solution code:
N = input()

b = []
for i in range(N+1):
    a = int(list(str(i)))
    b.append(sum(a))

print(max(b))

Submission status: Runtime Error

Solution code:
def is_9(arr):
    s = []
    for i in range(len(arr)):
        if arr[i] != '9':
            return False
        s.append(arr[i])
    return sum(s)


n = list(input())
fd = int(n.pop(0))
if is_9(n):
    print(fd + int(is_9(n)))
print(fd - 1 + int(9 * len(n)))

Submission status: Runtime Error

Solution code:
N = int(input())


def kakuinowa(n):
    a = str(n)
    s = 0
    for i in range(len(a)):
        s += int(a[i])
    return s

import math
m = kakuinowa(N)
for i in range(int(math.log10(N)) + 1):
    n = kakuinowa((N // 10**i) * 10**i - 1)
    if n > m:
        m = n


print(m)

Submission status: Runtime Error

Solution code:
N = map(int,raw_input().split())

l= int(len(N))
one  = int(N[0])-1

for i in range(l-1):
    N[i]=9

for i in range(l-1):
    count = +int(N[i])
    
print(one+count-int(N[0]))

Submission status: Runtime Error

Solution code:
#coding:utf-8
n = int(input())
num = len(str(n))
tmp = pow(10, num)-1
s = 0
for i in range(num+1):
    if i == num:
        s = sum(list(map(int, str(tmp-9*pow(10, num-1)+(int(str(n)[0])-1)*pow(10, num-1)))))
        break
    elif tmp-pow(10, i) <= n:
        s = sum(list(map(int, str(tmp-pow(10, i)))))
        break
if sum(list(map(int, str(n)))) > s:
    print(sum(list(map(int. str(n)))))
else:
    print(s)

Submission status: Runtime Error

Solution code:
#coding:utf-8
n = int(input())
num = len(str(n))
tmp = pow(10, num)-1
s = 0
for i in range(num+1):
    if i == num:
        s = sum(list(map(int, str(tmp-9*pow(10, num-1)+(int(str(n)[0])-1)*pow(10, num-1)))))
        break
    elif tmp-pow(10, i) <= n:
        s = sum(list(map(int, str(tmp-pow(10, i)))))
        break
if sum(list(map(int. str(n)))) > s:
    print(sum(list(map(int. str(n)))))
else:
    print(s)

Submission status: Runtime Error

Solution code:
#encoding=utf-8
def solve(n):
    ans_a = calc_digit_sum(n)
    ans_b = calc_digit_sum(n - n % 10 - 1)
    ans_c = calc_digit_sum(10 ** (len(str(n)) - 1) - 1 + 10 ** (len(str(n)) - 1) * (int(str(n)[0]) - 1) )
    return max(ans_a, ans_b, ans_c)

def calc_digit_sum(n):
    str_n = str(n)
    ans = 0
    for x in range(len(str_n)):
        ans = ans + int(str_n[x])
    return ans

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

Submission status: Runtime Error

Solution code:
_num = int(input())
_sumlist = []
for i in range(num//10, _num + 1):
    _sum = 0
    while i:
        _sum += i % 10
        i //= 10
    _sumlist.append(_sum)
print(max(_sumlist))

Submission status: Runtime Error

Solution code:
N = int(input())

def sum(n):
    s = 0
    if n == 0:
        return 0
    else:
        return n % 10 + sum(n//10)

        
import math
m = sum(N)
for i in range(int(math.log10(N)) + 1):
    n = sum((N // 10**i) * 10**i - 1)
    if n > m:
        m = n


print(m)

Submission status: Runtime Error

Solution code:
N = input()
l = len(str(N))-1
print(l*9 + (N//(10**l)-1))

Submission status: Runtime Error

Solution code:
N = int(input())
for i in range(17):
    a = (N + 1) // (10 ** i)
    if a:
        b = a
    elif a == 0:
        c = (i -1) * 9 + b - 1
        break
print(c)

Submission status: Runtime Error

Solution code:
n = input()
tail = int(n[1:])
m = str(int(n) - tail - 1)
ans = 0
for i in m:
    ans += int(i)
print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
a = 0
while 10 ** a < n:
    a = a + 1
b = (n + 1) // (10 ** (a -1))
c = b * (10 ** (a - 1)) - 1
d = 0
for i in range(len(str(c))):
    d = d + int(str(c)[i])
print(d)

Submission status: Runtime Error

Solution code:
n = int(input())
a = 0
while 10 ** a < n:
    a = a + 1
b = n // (10 ** (a -1))
c = b * (10 ** (a - 1)) - 1
d = 0
for i in range(len(str(c))):
    d = d + int(str(c)[i])
print(d)