Time limit
2s
Memory limit
128 MB
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.
The first line contains a string consisting only of a and b. The length of the string is at most 1,000.
Print the minimum number of swaps needed to make all a characters consecutive.