407721: GYM102881 J ABC
Memory Limit:256 MB
Time Limit:1 S
Judge Style:Text Compare
Creator:
Submit:0
Solved:0
Description
J. ABCtime limit per test1 secondmemory limit per test256 megabytesinputabc.inoutputstandard output
You're given an string $$$s$$$ of length $$$n$$$. Each character in it is either '$$$a$$$', '$$$b$$$', or '$$$c$$$'. In addition, the string contains at most $$$1$$$ '$$$b$$$' character.
You can swap the values of any two indices. Find the minimum number of swaps needed so that for every index $$$i$$$ $$$(1 \leq i \leq n - 1)$$$, either $$$s_i=s_{i+1}$$$ or $$$s_i$$$ = '$$$b$$$' or $$$s_{i+1}$$$ = '$$$b$$$'.
InputThe first line contains a single integer $$$n$$$ $$$(1 \leq n \leq 10^5)$$$ — the length of the string.
The second line contains the string $$$s$$$.
OutputIf there's no way to satisfy the condition in the statement, print "-1". Othwerwise, print the minimum number of swaps to achieve the condition.
ExampleInput3 acbOutput
1