Codeforces Round 513 by Barcelona Bootcamp (rated, Div. 1 + Div. 2)
B
Maximum Sum of Digits
Codeforces
1100
原题
← AC →
翻译中…

You are given a positive integer $n$.

翻译中…

Let $S(x)$ be sum of digits in base 10 representation of $x$, for example, $S(123) = 1 + 2 + 3 = 6$, $S(0) = 0$.

翻译中…

Your task is to find two integers $a, b$, such that $0 \leq a, b \leq n$, $a + b = n$ and $S(a) + S(b)$ is the largest possible among all such pairs.

翻译中…

Input

翻译中…

The only line of input contains an integer $n$ $(1 \leq n \leq 10^{12})$.

翻译中…

Output

翻译中…

Print largest $S(a) + S(b)$ among all pairs of integers $a, b$, such that $0 \leq a, b \leq n$ and $a + b = n$.

翻译中…

Note

翻译中…

In the first example, you can choose, for example, $a = 17$ and $b = 18$, so that $S(17) + S(18) = 1 + 7 + 1 + 8 = 17$. It can be shown that it is impossible to get a larger answer.

翻译中…

In the second test example, you can choose, for example, $a = 5000000001$ and $b = 4999999999$, with $S(5000000001) + S(4999999999) = 91$. It can be shown that it is impossible to get a larger answer.

翻译中…

样例

Input #1
35
Output #1
17
InputCopy OutputCopy
Input #2
10000000000
Output #2
91
InputCopy OutputCopy
题目信息
题号
1060B
时间限制
2 s
内存限制
512 MB
标签
贪心

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。