3697.Beautiful Decomposition

Time Limit: 1s Memory Limit: 256MB

Valera considers a number beautiful, if it equals 2k or -2k for some integer k (k \ge 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 Format(From the terminal/stdin)

The first line contains string s (1 \le |s| \le 106), that is the binary representation of number n without leading zeroes (n \gt 0).

Output Format(To the terminal/stdout)

Print a single integer - the minimum amount of beautiful numbers that give a total of n.

Sample Input 1

Copy
10
  \n

Sample Output 1

Copy
1
 \n

Sample Input 2

Copy
111
   \n

Sample Output 2

Copy
2
 \n

Sample Input 3

Copy
1101101
       \n

Sample Output 3

Copy
4
 \n

Hints

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

In the second sample n=7 and Valera can decompose it into sum 23+(-20).

In the third sample n=109 can be decomposed into the sum of four summands as follows: 27+(-24)+(-22)+20.

Submit

请先 登录

© 2025 FAQs