5603: 基于一的算术

内存限制:256 MB 时间限制:2 S
题面:传统 评测方式:文本比较 上传者:
提交:2 通过:2

题目描述

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

输出格式

Print expected minimal number of digits 1.

输入样例 复制

121

输出样例 复制

6