TnT/Multi_CodeNet4Repair huggingface dataset:
Problem: Find the maximum possible sum of the digits (in base 10) of a positive integer not greater than N.

Submission attempts (in order):

def maxf(n):
    a = list(map(int, list(n)))
    for i, item in enumerate(a):
        if i == 0 and item != 9:
            if a[i+1:] == [9]*(len(a)-1):break
            a[i] -=1
            a[i+1:] = [9]*(len(a)-1)
            break
        elif item != 9:
            a[i-1] -= 1
            a[i:] = [9]*(len(a)-i)
            break
    return a, sum(a)

print(maxf(input()))


def maxf(n):
    a = list(map(int, list(n)))
    for i, item in enumerate(a):
        if i == 0 and item != 9:
            a[i] -=1
            a[i+1:] = [9]*(len(a)-1)
            break
        elif item != 9:
            a[i-1] -= 1
            a[i:] = [9]*(len(a)-i)
            break
    return sum(a)

print(maxf(input())


def maxf(n):
    a = list(map(int, list(n)))
    for i, item in enumerate(a):
        if i == 0 and item != 9:
            if a[i+1:] == [9]*(len(a)-1):break
            a[i] -=1
            a[i+1:] = [9]*(len(a)-1)
            break
        elif item != 9:
            a[i-1] -= 1
            a[i:] = [9]*(len(a)-i)
            break
    return sum(a)

print(maxf(input()))


Verdicts: Wrong Answer

Runtime Error

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

Submission attempts (in order):
n = int(input())

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


n = input()

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

if len(n) == 1:
    print(n)
else:
    print(sum if set(n[1:]) == {"9"} else sum - 1)


Verdicts: Runtime Error

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

Submission attempts (in order):
N=list(input())
mark=0
for i in range (len(N)):
    if N[i]!='9':
        mark=i
        print (mark)
        break
if mark==0:
    answer=list((''.join(['9']*(len(N)-1))))
else:
    answer=list((''.join(N[:mark-1]+[str(int(N[mark-1])-1)]+['9']*len(N[mark:]))))
    
answer_sum=0
for j in range (len(answer)):
    answer_sum+=int(answer[j])
print(answer_sum)

N=list(input())
import sys
mark=0
for i in range (len(N)):
    if N[i]!='9':
        mark=i
        break
if mark==0 and N[mark+1:]==['9']*len(N[mark+1:]):
    count=0
    for l in range (len(N)):
        count+=int(N[l])
    print(count)
    sys.exit()
N[0]=str(int(N[0])-1)
for j in range (1,len(N)):
    N[j]='9'
count=0
for k in range (len(N)):
    count+=int(N[k])
print(count)

Verdicts: Wrong Answer

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

Submission attempts (in order):
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))




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))




N=input()
ans1=sum(list(map(int,list(N))))
ans2=int(N[0])-1+9*(len(N)-1)
print(max(ans1,ans2))


Verdicts: Wrong Answer

Wrong Answer

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

Submission attempts (in order):
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)

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

Verdicts: Runtime Error

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

Submission attempts (in order):
s = list(input())
ans = [sum(map(int, s)), 9*(len(s)-1) + int(s[0]-1)]
print(max(ans))

s = list(input())
ans = [sum(map(int, s)), 9 * (len(s) - 1) + int(s[0]) - 1]
print(max(ans))

Verdicts: Runtime Error

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

Submission attempts (in order):
n=str(int(input())+1)
print(sum(map(int,list(n[0]+[0]*(len(n)-1)))))


n=str(int(input())+1)
print(sum(map(int,list(str(int(n[0]+'0'*(len(n)-1))-1)))))

Verdicts: Runtime Error

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

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

N = input()
N_list = list(str(N))
sum = 0

for i in N_list:
    sum += int(i)

print (sum)

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

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

Verdicts: Runtime Error

Wrong Answer

Wrong Answer

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

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


m=input()
a=int(m[0])-1+(len(m)-1)*9
b=0
for i in n:
  b+=i
print(max(b,a))

m=input()
a=int(m[0])-1+(len(m)-1)*9
b=0
for i in n:
  b+=int(i)
print(max(b,a))


m=input()
a=int(m[0])-1+(len(m)-1)*9
b=0
for i in m:
  b+=int(i)
print(max(b,a))


Verdicts: Wrong Answer

Runtime Error

Runtime Error

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

Submission attempts (in order):
N = input()
l = len(N)

s = '9'*(l-1)
if N[i::] == s:
    print(int(N[0])+9*(l-1))
else:
    print(int(N[0])-1+9*(l-1))

N = input()
l = len(N)

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

N = input()

l = len(N)
j = "9"*(l-1)

if n[i::] == j:
    print(int(n[0])+9*(n-1))
else:
    print(int(n[0])-1+9*(k-1))

N = input()
l = len(N)

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

N = input()
l = len(N)

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

N = input()

l = len(N)

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

N = input()
l = len(N)

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

Verdicts: Runtime Error

Runtime Error

Runtime Error

Runtime Error

Runtime Error

Runtime Error

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

Submission attempts (in order):
n = input()
ans1=int(n[0])
for i in n:
  ans1 += int(i)
ans2=int(n[0])-1+9*(len(n)-1)
print(max(ans1,ans2)

n = input()
ans1=sum(int(i)for i in n)
ans2=int(n[0])-1+9*(len(n)-1)
print(max(ans1,ans2)

n = input()
ans1=sum(int(i)for i in n)
ans2=int(n[0])-1+9*(len(n)-1)
print(max(ans1,ans2))

Verdicts: Runtime Error

Runtime Error

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

Submission attempts (in order):
N = input()
digit = len(N)
ans=[int(N[0])-1]+[9]*(digit-1)
print(ans)
print(sum(ans))

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

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


Verdicts: Wrong Answer

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

Submission attempts (in order):
N = int(input())
num = str(N)
for i in range(1,len(num)):
    if num[-i] != "9" and 0 < N - (int(num[-i]) + 1) * 10**(i-1):
        N -= (int(num[-i]) + 1) * 10**(i-1)
        num = str(N)
        print(N)

D = 0
for digit in str(N):
    D += int(digit)

print(D)


N = int(input())
num = str(N)
for i in range(1,len(num)):
    if num[-i] != "9" and 0 < N - (int(num[-i]) + 1) * 10**(i-1):
        N -= (int(num[-i]) + 1) * 10**(i-1)
        num = str(N)

D = 0
for digit in str(N):
    D += int(digit)

print(D)

Verdicts: Wrong Answer

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

Submission attempts (in order):
def solve():
    N = list(map(int, list(input())))
    print(N)

    res = 0
    for i in range(len(N)):
        tmp = 0
        for j in range(len(N)):
            if j <= i-1:
                tmp += N[j]
            elif j==i:
                tmp += N[j]-1
            else:
                tmp += 9
        res = max(res, tmp)

    print(res)


if __name__ == "__main__":
    solve()




def solve():
    I = input()
    N = list(map(int, list(I)))

    res = sum(N)

    for i in range(len(N)):
        tmp = 0
        for j in range(len(N)):
            if j <= i-1:
                tmp += N[j]
            elif j==i:
                tmp += N[j]-1
            else:
                tmp += 9
        res = max(res, tmp)

    print(res)


if __name__ == "__main__":
    solve()




Verdicts: Wrong Answer

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

Submission attempts (in order):
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)


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)



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)



Verdicts: Runtime Error

Runtime Error

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

Submission attempts (in order):
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)


S = input()
N = len(S)


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

ans = digitSum(S)
candidate = (int(S[0]) - 1) * pow(10, N-1) + (pow(10, N-1) - 1)
candidate = digitSum(candidate)

if ans > candidate:
    print(ans)
else:
    print(candidate)


Verdicts: Wrong Answer

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

Submission attempts (in order):
n = input()

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

ok = False
ans = ""
for i, c in enumerate(n):
  x = int(c)
  if x == 9:
    ans += "9"
  else:
    if ok:
      ans += "9"
    else:
      if i == len(n)-1:
        ans = ans[:-1]
        ans += str(int(n[i-1])-1)
        ans += "9"
      else:
        ans += str(x-1)
    ok = True

print(ans)
t = 0
for c in ans:
  x = int(c)
  t += x
print(t)

n = input()

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

if all(x == "9" for x in n[1:]):
  ans = n
else:
  ok = False
  ans = ""
  for i, c in enumerate(n):
    x = int(c)
    if x == 9:
      ans += "9"
    else:
      if ok:
        ans += "9"
      else:
        if i == len(n)-1:
          ans = ans[:-1]
          ans += str(int(n[i-1])-1)
          ans += "9"
        else:
          ans += str(x-1)
      ok = True
t = 0
for c in ans:
  x = int(c)
  t += x

print(t)

Verdicts: Wrong Answer

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

Submission attempts (in order):
N = int(input())
x = 9
order = 0
for i in range(16):
    if x > N:
        break
    x = x*10+9
    order = i+1
ans = x
for i in range(10):
    ans -= 10**order
    print(ans)
    if  ans <= N:
        break
ret = 0
while True:
    if ans == 0:
        break
    ret += ans % 10
    ans = ans//10
print(ret)

N = int(input())
x = 9
order = 0
for i in range(16):
    if x > N:
        break
    x = x*10+9
    order = i+1
ans = x
for i in range(10):
    ans -= 10**order
    print(ans)
    if  ans < N:
        break
ret = 0
while True:
    if ans == 0:
        break
    ret += ans % 10
    ans = ans//10
print(ret)

N = int(input())
x = 9
order = 0
for i in range(16):
    if x > N:
        break
    x = x*10+9
    order = i+1
ans = x
for i in range(10):
    ans -= 10**order
    if  ans <= N:
        break
ret = 0
while True:
    if ans == 0:
        break
    ret += ans % 10
    ans = ans//10
print(ret)

Verdicts: Wrong Answer

Wrong Answer

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

Submission attempts (in order):
9999999999999999

N = input()
n = int(N)
t = n % 10 ** (len(N) - 1) + 1
print(max(sum(map(int, N)), sum(map(int, str(n - t)))))


Verdicts: Wrong Answer

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

Submission attempts (in order):
n=int(input())
if n<=9:
  print(n)
else:
  n=str(n)
  x=n[0]
  x=int(x)-1
  if n[1:].count('9')==len(n-1):
    print(x+1(len(n)-1)*9)
  else:
    print(x+(len(n)-1)*9)


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


Verdicts: Runtime Error

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

Submission attempts (in order):
s=input();print(sum(map(int,list(s)or int(s[0])-1+9*(len(s)-1))))

s=str(int(input())+1);print(int(s[0])+9*len(s)-10)

Verdicts: Wrong Answer

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

Submission attempts (in order):
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))

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))
    

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))
    

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)

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
        array = list(map(int,N))
        ans = sum(array[:num]) + target + 9*(Dig-num-1)
        print(ans)
    else:
        array = list(map(int,N))
        print(sum(array))

Verdicts: Wrong Answer

Wrong Answer

Wrong Answer

Runtime Error

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

Submission attempts (in order):
n=input()
l=len(n)
a,b=0,0
while True:
    b+=n[a]
    a+=1
    if a==l:
      break
print(b)

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


a=input()
b=0
for i in range(len(a)):
    b+=int(a[i])
print(max((len(a)-1)*9+int(a[0])-1,b))

Verdicts: Runtime Error

Wrong Answer

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

Submission attempts (in order):
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)

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, -1, -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)

Verdicts: Wrong Answer

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

Submission attempts (in order):
N = int(input())
len = len(str(N))
a = list(str(N))
b =0
for i in range(1,len)[::-1]:
  if a[i] == -1:
    a[i] == '9'
  if a[i] != '9':
    b += (int(a[i])+1) * (10**(len-1-i))
    a[i-1] = str(int(a[i-1])-1)
print(N-b)

N = int(input())
len = len(str(N))
a = list(str(N))
b =0
for i in range(1,len)[::-1]:
  if a[i] == -1:
    a[i] == '9'
  if a[i] != '9':
    b += (int(a[i])+1) * (10**(len-1-i))
    a[i-1] = str(int(a[i-1])-1)
a = list(str(N-b))
b = 0
for i in a:
  b += int(i)
print(b)

Verdicts: Wrong Answer

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

Submission attempts (in order):

pattern = "simple"

n = int(input())

if pattern == "simple":
    
    max_sum = -1

    for i in range(10**(len(str(n))-1)-1, n+1):
        
        i_parts = []
        for i_part in str(i):
            i_parts.append(int(i_part))

        this_sum = sum(i_parts)
        
        if max_sum < this_sum:
            max_sum = this_sum
            max_sum_i = i

    print("max_sum  : {}\nmax_sum_i: {}".format(max_sum, max_sum_i))

elif pattern == "temp":
    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  : {}\nmax_sum_i: {}".format(max_sum, max_sum_i))

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)

n = int(input())

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  : {}\nmax_sum_i: {}".format(max_sum, max_sum_i))

n = int(input())
print(sum([int(j) for j in str(int(str(n+1)[0])-1) + "9"*(len(str(n+1))-1)]))

Verdicts: Wrong Answer

Runtime Error

Wrong Answer

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

Submission attempts (in order):
import sys
input = sys.stdin.readline


def digit_sum(str_num):
	sum = 0	
	
	for i in range(len(str_num)):
		sum += int(str_num[i])
	
	return sum


N = input()
patterns = [N]

for i in range(len(N)-1):
	if N[i] != '0':
		left, right = '', ''  
				
		if i > 0:
			left = N[:i]
		
		n = int(N[i]) - 1
		
		if i < len(N) - 1:
			right = '9' * (len(N)-i-1) 
		
		patterns.append(left + str(n) + right)

ans = 0

for p in patterns:
	ans = max(ans, digit_sum(p))
	
print(ans)

import sys
#input = sys.stdin.readline


def digit_sum(str_num):
	sum = 0	
	
	for i in range(len(str_num)):
		sum += int(str_num[i])
	
	return sum


N = input()
patterns = [N]

for i in range(len(N)-1):
	if N[i] != '0':
		left, right = '', ''  
				
		if i > 0:
			left = N[:i]
		
		n = int(N[i]) - 1
		
		if i < len(N) - 1:
			right = '9' * (len(N)-i-1) 
		
		patterns.append(left + str(n) + right)

ans = 0

for p in patterns:
	ans = max(ans, digit_sum(p))
	
print(ans)

Verdicts: Runtime Error

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

Submission attempts (in order):
N = input()
N_list = list(N)
N = int(N)
K = len(N_list)

ans = int(N_list[0])+(K-1)*9
ans_list = [N_list[0]] + ['9' for _ in range(K-1)]
ans_cand = int(''.join(ans_list))
print(ans_cand)
if N < ans_cand:
    print(ans - 1)
else:
    print(ans)

N = input()
N_list = list(N)
N = int(N)
K = len(N_list)

ans = int(N_list[0])+(K-1)*9
ans_list = [N_list[0]] + ['9' for _ in range(K-1)]
ans_cand = int(''.join(ans_list))
if N < ans_cand:
    print(ans - 1)
else:
    print(ans)

Verdicts: Wrong Answer

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

Submission attempts (in order):
a=list(input())
p=print
x=len(a)
y=int(a[0])
print(9*x-9+y if all(i=='9' for i in a[1:]) else y+9*(x-1))

a=list(input());x,y=len(a)-1,int(a[0]);print(9*x+y if all(i=='9'for i in a[1:])else y-1+9*x)

Verdicts: Wrong Answer

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

Submission attempts (in order):
s = input()
if int(s) < 10: print(s); exit()

ans = -1
for i in range(len(s)):
    t = s[:i]
    NINE = (len(s)-len(t))
    SUB = 0
    t+= '9' * NINE
    if int(s) < int(t): SUB = int('1' + '0' * NINE)
    t = max(int(t) - SUB, 0)
    ans = max(ans, sum(int(c) for c in str(t)))
    print(t)
print(ans)

s = input()
if int(s) < 10: print(s); exit()

ans = -1
for i in range(len(s)):
    t = s[:i]
    NINE = (len(s)-len(t))
    SUB = 0
    t+= '9' * NINE
    if int(s) < int(t): SUB = int('1' + '0' * NINE)
    t = max(int(t) - SUB, 0)
    ans = max(ans, sum(int(c) for c in str(t)))
print(ans)

Verdicts: Wrong Answer

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

Submission attempts (in order):
N = input()

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

N = input()

ans = 0
all_nine_flg = True

for i in range(1,len(N)):
  if N[i] == "9":
    continue
  else:
    all_nine_flg = False
    break

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

Verdicts: Wrong Answer

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

Submission attempts (in order):
s = input()
if len(s) == 1: print(int(s[0])
elif s[1:] == "9"*(len(s)-1): print(int(s[0]+9*len(s)-9)
else: print(int(s[0]+9*len(s)-10)                                    

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


Verdicts: Runtime Error

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

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

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)))))

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

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

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


Verdicts: Runtime Error

Runtime Error

Runtime Error

Runtime Error

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

Submission attempts (in order):
x=int(input())
y=str(x)
n=len(y)
print(int(y[0])+9*n)


x=int(input())
y=str(x)
n=len(y)
print(int(n[0])+9*n)


x=int(input())
y=str(x)
n=len(y)

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


Verdicts: Wrong Answer

Runtime Error

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

Submission attempts (in order):
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)

ans = 0
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)
    for j in range(i,num_len):
      num[j] = "9"
    break
for w in num:
  ans = ans + int(w)
print(ans)

Verdicts: Wrong Answer

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

Submission attempts (in order):
#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)

#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)

#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)

Verdicts: Runtime Error

Runtime Error

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

Submission attempts (in order):
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))

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))
    

Verdicts: Runtime Error

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

Submission attempts (in order):
import bisect
N = int(input())
if len(str(N)) == 1:
    print(N)
    exit()
L = len(list(str(N)))-1
A = [10**(L)*i+10**(L)-1 for i in range(10)]  
n = bisect.bisect_left(A,N)-1
if N in A:
    n += 1
ans = [int(list(str(A[n]))[i]) for i in range(len(list(str(A[n]))))]
print(sum(ans))
print(A)

import bisect
N = int(input())
if len(str(N)) == 1:
    print(N)
    exit()
L = len(list(str(N)))-1
A = [10**(L)*i+10**(L)-1 for i in range(10)]  
n = bisect.bisect_left(A,N)-1
if N in A:
    n += 1
ans = [int(list(str(A[n]))[i]) for i in range(len(list(str(A[n]))))]
print(sum(ans))


Verdicts: Wrong Answer

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

Submission attempts (in order):
N=input()
M=len(str(N))
K=int(N[0])
ans=0
for i in range (M):
	ans+=N[i]

print(max(9*(M-1)+(K-1)),ans)

N=input()
M=len(str(N))
K=int(N[0])
ans=0
for i in range (M):
	ans+=N[i]
print(max(9*(M-1)+(K-1),ans))

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

N=input()
M=int(N[0:2])
L=len(N[2:])*9
K=0
sum=0
for i in range(len(N)):
	sum+=int(N[i])
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(max(sum,K+L))

Verdicts: Runtime Error

Runtime Error

Wrong Answer

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

Submission attempts (in order):
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)))

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(arr)-1)))

Verdicts: Runtime Error

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

Submission attempts (in order):
N=list(input())
cnt=0
size=len(N)-1
if size==0:
    print(N[0])
    exit()
N.reverse()

for i in range(size):
    if N[i]!="9":
        N[i]="9"
        N[i+1]=str(int(N[i+1])-1)
print(cnt)

for i in range(size+1):
    cnt+=int(N[i])
print(cnt)


N=list(input())
cnt=0
size=len(N)-1
if size==0:
    print(N[0])
    exit()
N.reverse()

for i in range(size):
    if N[i]!="9":
        N[i]="9"
        N[i+1]=str(int(N[i+1])-1)
for i in range(size+1):
    cnt+=int(N[i])
print(cnt)


Verdicts: Wrong Answer

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

Submission attempts (in order):
n = list(map(int,input()))
cnt = 0
ans = []

for i in n:
    cnt += 1
    if i == 9:
        continue
    else:
        if cnt == len(n):
            break
        else:
            n[cnt-1] -= 1
            break

for i in range(cnt,len(n)):
    n[i] = 9
print(n)

print(sum(n))

n = list(map(int,input()))
cnt = 0
b = tuple(n)
c = b

for i in n:
    cnt += 1
    if i == 9:
        continue
    else:
        if cnt == len(n):
            cnt -= 1
            n[cnt-1] -= 1
            break
        else:
            if i == 0:
                n[cnt-2] -= 1
                cnt -= 1
                break
            else:
                n[cnt-1] -= 1
                break

for i in range(cnt,len(n)):
    n[i] = 9

if len(n) == 1:
    n = b

print(n)
print(b)

if sum(n) >= sum(b):
    print(sum(n))
else:
    print(sum(b))

n = list(map(int,input()))
cnt = 0
ans = []

for i in n:
    cnt += 1
    if i == 9:
        continue
    else:
        if cnt == len(n):
            cnt -= 1
            n[cnt-1] -= 1
            break
        else:
            if i == 0:
                n[cnt-2] -= 1
                cnt -= 1
                break
            else:
                n[cnt-1] -= 1
                break

for i in range(cnt,len(n)):
    n[i] = 9

print(n)

print(sum(n))

n = list(map(int,input()))
cnt = 0
b = tuple(n)
c = b

for i in n:
    cnt += 1
    if i == 9:
        continue
    else:
        if cnt == len(n):
            cnt -= 1
            n[cnt-1] -= 1
            break
        else:
            if i == 0:
                n[cnt-2] -= 1
                cnt -= 1
                break
            else:
                n[cnt-1] -= 1
                break

for i in range(cnt,len(n)):
    n[i] = 9

if len(n) == 1:
    n = b

if sum(n) >= sum(b):
    print(sum(n))
else:
    print(sum(b))

Verdicts: Wrong Answer

Wrong Answer

Wrong Answer

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

Submission attempts (in order):
# -*- coding: utf-8 -*-

import numpy as np

n = input()

a = np.zeros((int(len(n))))
for i in range(0,len(n)):
    a[i] = int(n[i])

print(int(sum(a)))

# -*- coding: utf-8 -*-
N = int(input())

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

a=[]

a.append(Sum(N))

N_str = str(N)
N_str = list(map(int, list(N_str)))

"右端の数字を1下げたときの最大"
N_str = str(N)
N_str = list(map(int, list(N_str)))
N_str[0] = N_str[0] - 1
for i in range(1,len(N_str)):
    N_str[i] = 9
a.append(sum(N_str))

print(max(a))

Verdicts: Wrong Answer

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

Submission attempts (in order):
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)]


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


Verdicts: Wrong Answer

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

Submission attempts (in order):
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)
    

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



Verdicts: Runtime Error

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

Submission attempts (in order):
import math

N = int(input())
digit_num = math.ceil(math.log10(N))
msd =int(N/(10**(digit_num-1)))
print(msd)
if N%10 == 0:
    print(msd + 9*(digit_num-1))
else:
    print(msd + 9*(digit_num-1) - 1)


import math

N = int(input())
digit_num = math.ceil(math.log10(N))
msd =int(N/(10**(digit_num-1)))
if N%10 == 0:
    print(msd + 9*(digit_num-1))
else:
    print(msd + 9*(digit_num-1) - 1)


import math

N = int(input())
digit_num = math.ceil(math.log10(N))
msd =int(N/(10**(digit_num-1)))
print(msd)
if N%10 == 0:
    print(msd + 9*(digit_num-1))
else:
    print(msd + 9*(digit_num-1) - 1)


import math

N = int(input())
digit_num = math.ceil(math.log10(N))
msd =int(N/(10**(digit_num-1)))

if (N+1)%10 == 0:
    print(msd + 9*(digit_num-1))
elif N-10<0:
    print(N)
else:
    print(msd + 9*(digit_num-1) - 1)


Verdicts: Wrong Answer

Wrong Answer

Wrong Answer

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

Submission attempts (in order):
N = list(input())
print(len(N)*9+N[0]-1)

N = list(input())

flg = 0
for i in range(1,len(N)):
    if N[i]=="9":
        continue
    else:
        flg = 1
        break

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

Verdicts: Runtime Error

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

Submission attempts (in order):
n=int(input())
t=list(str(n))
if n%10**len(t)==0:
  print(9*(len(t)-1))
elif n%10**(len(t)-1)==0:
  print(int(t[0])+9*(len(t)-1))
else:
  print(int(t[0])-1+9*(len(t)-1))

n=int(input())
t=list(str(n))
if n%10**len(t)==0:
  print(9*(len(t)-1))
elif: n%10**(len(t)-1)==0:
  print(t[0]+9*(len(t)-2))
else:
  print(t[0]-1+9*(len(t)-2))

n=int(input())
t=list(str(n))
cnt=0
for i in range(1,len(t)):
  if t[i]=="9":
    cnt=cnt+1
if cnt==len(t)-1:
  print(int(t[0])+9*cnt)
else:
  print(int(t[0])-1+9*(len(t)-1))

Verdicts: Wrong Answer

Runtime Error

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

Submission attempts (in order):
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:
        
        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))
        
        
        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)

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:
        
        if str(n)[0:1] == '1':
            cand = n % 10**(len(str(n)) - 1)
            
            cand_str = "9"*len(str(cand))
            cand = int(cand_str)
            
            
            return max(digit_sum(n,10), digit_sum(cand,10))
        
        
        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))

n = int(input())

ans = judge(n)
print(ans)

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:
        
        if str(n)[0:1] == '1':
            
            cand_str = "9" * (len(str(n)) - 1)
            cand = int(cand_str)
            
            return max(digit_sum(n,10), digit_sum(cand,10))
        
        
        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))

n = int(input())

ans = judge(n)
print(ans)

Verdicts: Runtime Error

Wrong Answer

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

Submission attempts (in order):
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)


s = input()

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


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

print(ans)


n = input()

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


n = input()

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


Verdicts: Runtime Error

Runtime Error

Runtime Error

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

Submission attempts (in order):
N = int(input())

for i in range(17):
    if 10**i <=N <10**(i+1):
        m=i+1
        break

for j in range(1,10):
    if (10**(m-1))*j + 10**(m-1)-1 <=N< (j+1)*(10**(m-1))+10**(m-1)-1:
        a = j
        break

print(a+9*(m-1))

N = int(input())

for i in range(17):
    if 10**i <=N <10**(i+1):
        m=i+1
        break

for j in range(0,10):
    if (10**(m-1))*j + 10**(m-1)-1 <=N< (j+1)*(10**(m-1))+10**(m-1)-1:
        a = j
        break

print(a+9*(m-1))

Verdicts: Runtime Error

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

Submission attempts (in order):
n = input()
n = list(n)

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]

print(sum(N))



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


n = input()
n = list(n)

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]

print(sum(N))



n = input()

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

print(sum(n))

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


Verdicts: Runtime Error

Wrong Answer

Wrong Answer

Runtime Error

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

Submission attempts (in order):
x = int(input())
b = 0
for i in range(16):
  a = x % 10
  b = b + a
  x = x // 10
  
print(b)

def num_sum(n):
	b = 0
	for i in range(16):
		a = n % 10
		b = b + a
		n = n // 10
	return b

x = int(input())
f = 0
for i in range(17):
	c = 10**(16-i)*(x//(10**(16-i))) -1
	if c <= 0:
		c = 0
	d = max(num_sum(x), num_sum(c), f)
	f = d
print(f)

Verdicts: Wrong Answer

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

Submission attempts (in order):
n = list(map(int, input().split()))
print(max((len(n)-1)*9 + n[0]-1, sum(n)))

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

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

n = list(map(int, input().split()))
print(max(sum(n), n[0]-1+9*(len(n)-1)))

ns = list(map(int, list(input())))
print(max(sum(ns), ns[0]-1 + 9*(len(ns)-1)))

Verdicts: Wrong Answer

Wrong Answer

Runtime Error

Wrong Answer

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

Submission attempts (in order):
def resolve():
    n = input()
    l = len(n)
    if n[:1] == "9" * l-1: 
        print(int(n[0]) + 9*(l-1))
    else:
        print((int(n[0])-1) + (9*(l-1)))
resolve()

def resolve():
    n = input()
    l = len(n)
    if n[1:] == "9" * (l-1): 
        print(int(n[0]) + 9*(l-1))
    else:
        print((int(n[0])-1) + (9*(l-1)))
resolve()

Verdicts: Runtime Error

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

Submission attempts (in order):
N=int(input())
n=str(N)
Length=len(n)

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

print(ans)

N=int(input())
# N=100
n=str(N)
Length=len(n)

l=list(n)

if l[1:]==['9']*(Length-1):
    ans=int(n[0])+9*(Length-1)
else:
    ans=int(n[0])-1+9*(Length-1)

print(ans)

Verdicts: Wrong Answer

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

Submission attempts (in order):
tes =input()
a = [int(data) for data in tes] 
print(sum(a))


tes =input()
a = [int(data) for data in tes] 
no_change = sum(a)
changes = a[0]-1 + (len(a)-1)*9
if changes > no_change:
	print(changes)
else:
	print(no_change)

Verdicts: Wrong Answer

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

Submission attempts (in order):
n=input()
ans=0
for i in n:
    ans+=int(i)
print(ans)

n=int(input())
k=len(str(n))
c=n//10**(k-1)
print(c+9*(k-1) if n==(c+1)*10**(k-1)-1 else c+9*(k-1)-1)

Verdicts: Wrong Answer

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

Submission attempts (in order):
#AtCoder Grand Contest 021 a
def wa(x):
    x=str(x)
    s=0
    for i in x:
        s+=int(i)
    return s

n=int(input())
keta=len(str(n))
start=10**(keta-2)
start=max(0,start)
ans=0
print(start)
for i in range(start,n+1):
    ans=max(ans,wa(i))
print(ans)

#AtCoder Grand Contest 021 a
n=input()
keta=len(n)
c=n[0]
ans=int(c)+9*(keta-1)
if n[1:]!=("9"*(keta-1)):
    ans-=1
print(ans)


Verdicts: Runtime Error

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

Submission attempts (in order):
N = input()
n = N

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

if N[1:].count('9') == len(N)-1:
    print(sum([int(i) for i in N]))
    exit()

if N[0]!='9' or any(map(lambda x:x!='9',N)):
    n = chr(ord(N[0])-1) + N[1:]
# elif any(map(lambda x:x!='9',N)):
#     n = chr(min([ord(x) for x in N])-1) + N[1:]

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

print(int(N),ans)
if int(N) >= ans:
    print(sum([int(i) for i in str(ans)]))
else:
    print(sum([int(i) for i in str(ans)]) -1)


N = input()
n = N

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

if N[1:].count('9') == len(N)-1:
    print(N)
    exit()

if N[0]!='9' or any(map(lambda x:x!='9',N)):
    n = chr(ord(N[0])-1) + N[1:]
# elif any(map(lambda x:x!='9',N)):
#     n = chr(min([ord(x) for x in N])-1) + N[1:]

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

print(int(N),ans)
if int(N) >= ans:
    print(sum([int(i) for i in str(ans)]))
else:
    print(sum([int(i) for i in str(ans)]) -1)


N = input()
n = N

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

if N[1:].count('9') == len(N)-1:
    print(sum([int(i) for i in N]))
    exit()

if N[0]!='9' or any(map(lambda x:x!='9',N)):
    n = chr(ord(N[0])-1) + N[1:]
# elif any(map(lambda x:x!='9',N)):
#     n = chr(min([ord(x) for x in N])-1) + N[1:]

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

# print(int(N),ans)
if int(N) >= ans:
    print(sum([int(i) for i in str(ans)]))
else:
    print(sum([int(i) for i in str(ans)]) -1)


Verdicts: Wrong Answer

Wrong Answer

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

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


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


Verdicts: Runtime Error

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

Submission attempts (in order):
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)


n = list(map(int, list(input().strip())))

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)


Verdicts: Wrong Answer

Accepted