cho.sh
Notes
Loading...

String Exchange

Time limit

2s

Memory limit

128 MB

Problem

You are given a string containing only a and b. You may swap characters to make all a characters occupy one consecutive block. Find the minimum number of swaps needed.

The string is circular, so the first and last characters are adjacent.

For example, aabbaaabaaba can be rearranged so that all a characters are consecutive with two swaps.

Input

The first line contains a string consisting only of a and b. The length of the string is at most 1,000.

Output

Print the minimum number of swaps needed to make all a characters consecutive.