#ABC155E. Payment

Payment

题目描述

In the Kingdom of AtCoder, only banknotes are used as currency. There are 10100+110^{100}+1 kinds of banknotes, with the values of 1,10,102,103,,10(10100)1, 10, 10^2, 10^3, \dots, 10^{(10^{100})}. You have come shopping at a mall and are now buying a takoyaki machine with a value of NN. (Takoyaki is the name of a Japanese snack.)

To make the payment, you will choose some amount of money which is at least NN and give it to the clerk. Then, the clerk gives you back the change, which is the amount of money you give minus NN.

What will be the minimum possible number of total banknotes used by you and the clerk, when both choose the combination of banknotes to minimize this count?

Assume that you have sufficient numbers of banknotes, and so does the clerk.

在 AtCoder 王国,只有纸币被用作货币。纸币有 10100+110^{100}+1 种,价值为 1,10,102,103,,10(10100)1, 10, 10^2, 10^3, \dots, 10^{(10^{100})} 。您来商场购物,现在购买一台章鱼烧机,价值为 NN 。章鱼烧是一种日本小吃的名称。

付款时,你要选择一个至少是 NN 的金额交给店员。然后,店员把找零还给你,找零就是你给的钱减去 NN

当你和店员都选择纸币的组合来最小化这个数字时,你和店员使用的纸币总数可能最少是多少?

假设你有足够数量的纸币,店员也有足够数量的纸币。

输入格式

输入内容按以下格式标准输入:

NN

输出格式

打印您和店员使用的纸币总数的最小值。

样例 #1

样例输入 #1

36

样例输出 #1

8

样例 #2

样例输入 #2

91

样例输出 #2

3

样例 #3

样例输入 #3

314159265358979323846264338327950288419716939937551058209749445923078164062862089986280348253421170

样例输出 #3

243

说明

数据规模与约定

  • NN 是介于 11101,000,00010^{1,000,000} 之间(含)的整数。

样例 11 解释

如果您给了四张面值各为 1010 的纸币,而店员又给了您四张面值各为 11 的纸币,那么总共使用了八张纸币。

支付的纸币不能少于 8 张,所以答案是 88

样例 22 解释

如果您给了两张面值为 100,1100, 1 的纸币,而店员还给您一张面值为 1010 的纸币,则总共使用了三张纸币。