Codeforces Round 171 (Div. 2)
E
Beautiful Decomposition
Codeforces
1900
原题
← D→
翻译中…

Valera considers a number beautiful, if it equals $2^{*k*}$ or -$2^{*k*}$ for some integer $*k*$ $(*k* ≥ 0)$. Recently, the math teacher asked Valera to represent number $*n*$ as the sum of beautiful numbers. As Valera is really greedy, he wants to complete the task using as few beautiful numbers as possible.

翻译中…

Help Valera and find, how many numbers he is going to need. In other words, if you look at all decompositions of the number $*n*$ into beautiful summands, you need to find the size of the decomposition which has the fewest summands.

翻译中…

Input

翻译中…

The first line contains string $*s*$ $(1 ≤ |*s*| ≤ 10^{6})$, that is the binary representation of number $*n*$ without leading zeroes $(*n* > 0)$.

翻译中…

Output

翻译中…

Print a single integer — the minimum amount of beautiful numbers that give a total of $*n*$.

翻译中…

Note

翻译中…

In the first sample $*n* = 2$ is a beautiful number.

翻译中…

In the second sample $*n* = 7$ and Valera can decompose it into sum $2^{3} + ( - 2^{0})$.

翻译中…

In the third sample $*n* = 109$ can be decomposed into the sum of four summands as follows: $2^{7} + ( - 2^{4}) + ( - 2^{2}) + 2^{0}$.

翻译中…

样例

Input #1
10
Output #1
1
InputCopy OutputCopy
Input #2
111
Output #2
2
InputCopy OutputCopy
Input #3
1101101
Output #3
4
InputCopy OutputCopy
题目信息
题号
279E
时间限制
2 s
内存限制
256 MB
标签
动态规划
博弈论
贪心
数论

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。