cswork / OAOpen practice workspace

AmazonOA #337

Reverse Binary String with Minimum Shifts

Estimated MediumJudge-ready

Topics (AI-labelled)Two PointersStringsGreedy

Each time, remove one character from any position of the binary string and append it to the end. The target is the reverse of the original string. Find the minimum number of operations.

Input

One line containing a binary string. The original bounds are 1≤length≤100000.

Output

Output a single integer, the answer.

Example 1

Input:

00110101

Output:

3

Example 2

Input:

01

Output:

1

Example 3

Input:

0110

Output:

0

Example notes

The outputs of the three public examples are 3; 1; and 0, checked by independent enumeration or direct simulation.

Editorial

Loading solution…