시간 제한 메모리 제한 제출 정답 맞은 사람 정답 비율
1 초 512 MB 3 2 2 66.667%

문제

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?

입력

  • The first line of the input contains the integer n, where 1 ≤ n ≤ 105 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.

출력

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

예제 입력 1

5
ABABC

예제 출력 1

2

예제 입력 2

12
ABCABCABCABC

예제 출력 2

6

예제 입력 3

4
ACBA

예제 출력 3

0

예제 입력 4

6
BABABA

예제 출력 4

2

예제 입력 5

9
ABABCBCAC

예제 출력 5

3