406088: GYM102263 J Thanos Power

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

Description

J. Thanos Powertime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard output

After gathering all the infinity stones and dusting half the population of the universe, Thanos went to gardens street. He decided to plant some flowers using the reality stone.

So Thanos now wants to plant $$$N$$$ flowers in least number of steps needed. In each step he can: Choose a number $$$(0 \leq x)$$$,then Plant $$$10^x$$$ plants or remove $$$10^x$$$ plants with the help of the power stone. What is the least number of steps he needs to plant exactly $$$N$$$ flowers.

Input

A single integer $$$N$$$ $$$(0 \le N \le 10^{10^5})$$$, the number of flowers Thanos wants to plant.

Output

The least number of steps Thanos needs to plant $$$N$$$ plants.

ExamplesInput
3000
Output
3
Input
231
Output
6
Note

In the first sample, fastest way to plant 3000 plants is:

step 1 plant $$$10^3$$$

step 2 plant $$$10^3$$$

step 3 plant $$$10^3$$$

so the answer is 3 steps.

Source/Category

加入题单

上一题 下一题 算法标签: