302288: CF440C. One-Based Arithmetic

Memory Limit:256 MB Time Limit:0 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

One-Based Arithmetic

题意翻译

题目大意是:给你一个n,你需要把n用若干个1组成数通过加加减减表示出来,求最少用的1的个数。 例:121=111+11-1 用了6个1。 $n\le 10^{15}$

题目描述

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.

输入输出格式

输入格式


The first line of the input contains integer $ n $ ( $ 1<=n&lt;10^{15} $ ).

输出格式


Print expected minimal number of digits 1.

输入输出样例

输入样例 #1

121

输出样例 #1

6

Input

题意翻译

题目大意是:给你一个n,你需要把n用若干个1组成数通过加加减减表示出来,求最少用的1的个数。 例:121=111+11-1 用了6个1。 $n\le 10^{15}$

加入题单

算法标签: