3159.One-Based Arithmetic

Time Limit: 1s Memory Limit: 256MB

Prof. Vasechkin wants to represent positive integer n as a sum of addends, where each addends is an integer number containing only 1s. For example, he can represent 121 as 121=111+11+—1. Help him to find the least number of digits 1 in such sum.

Input Format(From the terminal/stdin)

The first line of the input contains integer n (1 \le n \lt 1015).

Output Format(To the terminal/stdout)

Print expected minimal number of digits 1.

Sample Input

Copy
121
   \n

Sample Output

Copy
6
 \n

Submit

请先 登录

© 2025 FAQs