cho.sh
Notes
Loading...

Flipping

Time limit

2s

Memory limit

128 MB

Problem

You are given a binary string S. In one move, choose one or more consecutive characters of S and flip all of them: 0 becomes 1, and 1 becomes 0.

Your goal is to make every character in the string equal.

For instance, let S = 0001100.

  1. If you flip the whole string, it becomes 1110011.
  2. If you then flip the 4th through 5th characters, it becomes 1111111, so two moves are enough.

However, if you flip only the 4th through 5th characters from the start, the string becomes 0000000, so one move is enough.

Given S, find the minimum number of moves needed.

Input

The first line contains a binary string S. The length of S is less than 1,000,000.

Output

Print the minimum number of moves needed to make every character equal.