Under construction

Still being built. Things may change

Lottery

Interview

Time limit1sMemory limit128 MB

Summary
Change as few letters of the given A, B, or C string as possible so no two neighbors match.
Level

Easy3 of 10

Topics
Greedy, String
Solved
No attempts yet

Problem

A lottery company runs a numbers game called Letter Game. A game ticket has nn positions, and on each position you mark exactly one of three letters: A, B, or C. The figure below shows an example ticket for n=10n = 10.

The winning string is produced by a drawing machine that holds 3n3n balls: nn balls marked A, nn marked B, and nn marked C. The machine has nn holes arranged in a row, and during the draw exactly one ball is pulled into each hole. Reading the letters on the drawn balls from left to right gives a string of nn letters, which is the result of the draw. A ticket marked with exactly this string wins the grand prize. The figure below shows a draw for which the ticket above would win.

The draw, however, is not entirely fair: two balls of the same kind (the same letter) repel each other and never end up in adjacent holes, so the arrangement shown in the figure above is in fact impossible. As a result, in every possible draw no two consecutive letters are the same.

You have already marked a string of nn letters on your ticket. You want to change your string so that no two consecutive letters are equal, changing as few positions as possible; each position you change may be set to any of the letters A, B, or C. Determine the minimum number of letters you have to change.

Input

The first line contains an integer nn (2≤n≤5000002 \le n \le 500000). The second line contains a string of nn characters, each equal to A, B, or C. This string contains at least one pair of adjacent equal letters.

Output

Print a single positive integer: the minimum number of letters that must be changed so that no two adjacent letters in the string are equal.

Examples1

  1. Example 1

    Input
    10
    BAACBBAAAC
    
    Expected output
    3