Problem list
Log in
#icpc00315 · ICPC BAPC 2018

Game Night

Gold II 1.0 s 2048 MB

-3mm

-15mm

It is finally Bobby's birthday, and all of his Acquaintances, Buddies and Colleagues have gathered for a board game night. They are going to play a board game which is played in up to three big teams. Bobby decided to split his guests into how well he knows them: the Acquaintances on team $A$, the Buddies on team $B$, and the Colleagues on team $C$.

While Bobby was busy explaining the rules to everyone, all his guests already took seats around his large, circular living room table. However, for the game it is crucial that all people sitting on a team are sitting next to each other. Otherwise, members of other teams could easily eavesdrop on their planning, ruining the game. So some people may need to change seats to avoid this from happening.

Bobby wants to start playing the game as soon as possible, so he wants people to switch seats as efficiently as possible. Given the current arrangement around the circular table, can you figure out the minimal number of people that must switch seats so that the teams are lined up correctly?

Input

  • The first line of the input contains the integer $n$, where $1 \leq n \leq 10^5$ is the number of players (as well as seats).
  • The second line contains a string of length $n$, consisting only of the characters in ABC. This indicates the teams of the people sitting around the table in order.

Output

Print a single integer: the minimal number of people you have to ask to move seats to make sure the teams sit together.

Example 1

Input
5
ABABC
Output
2

Example 2

Input
12
ABCABCABCABC
Output
6

Example 3

Input
4
ACBA
Output
0

Example 4

Input
6
BABABA
Output
2

Example 5

Input
9
ABABCBCAC
Output
3
Source
ICPC BAPC 2018
Appears in
Not part of a ladder, contest or set yet.
Accepted 0 Submissions 0 Acceptance 0% Solvers 0

Discussion

Threads about this problem. Spoilers are collapsed; wrap hints in ||double bars||.

No discussion yet. Start a thread if something here needs explaining.

Recent submissions Open with filters
Code