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

#F1996. One-Based Arithmetic

  • ID: 2002
  • 传统题
  • 2000ms
  • 256MiB
  • 尝试: 0
  • AC · 已通过: 0
  • 教学难度:进阶
  • 上传者:
  • 枚举
  • 搜索
  • 分治
  • 算法思想
  • 进阶
  • 难度
  • 共享题库
  • 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 题。保留原作者与原赛事署名。