跳到主要内容
图灵 OJTURING / ONLINE JUDGE

#F1996. One-Based Arithmetic

    ID: 2002 传统题 2000ms 256MiB 尝试: 0 已通过: 0 难度: 5 上传者: 标签>枚举搜索分治算法思想进阶难度共享题库Codeforces英文题面题目来源题面语言

One-Based Arithmetic

题目描述

C. One-Based Arithmetic
time limit per test
0.5 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

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

Output

Print expected minimal number of digits 1.

Examples
Input
121
Output
6

题目来源:fps-www.educg.net-codeforce-1-2833.xml.zip;FPS 共享题包,题包内第 1583 题。保留原作者与原赛事署名。