Testing Round 10
C
One-Based Arithmetic
Codeforces
1800
原题
← BD →
翻译中…

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

翻译中…

The first line of the input contains integer $*n*$ ($1 ≤ *n* < 10^{15}$).

翻译中…

Output

翻译中…

Print expected minimal number of digits 1.

翻译中…

样例

Input #1
121
Output #1
6
InputCopy OutputCopy
题目信息
题号
440C
所属比赛
时间限制
0.5 s
内存限制
256 MB
标签
暴力
DFS 及类似
分治

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