#P16815. [蓝桥杯 2026 国 Python B] 糖果转盘

[蓝桥杯 2026 国 Python B] 糖果转盘

Problem Description

Xiao Lan has a circular candy carousel. There are NN candies placed on the carousel in clockwise order. The color of the ii-th candy is represented by a lowercase English letter SiS_i.

Xiao Lan wants to choose a cut between two adjacent candies, cut the circular carousel open, and unfold it into a line. After unfolding, the order of the candies remains the original clockwise order. There are NN possible cuts: you can cut between the ii-th and the (i+1)(i + 1)-th candies where 1≤i<N1 \le i < N, or between the NN-th and the 11-st candies.

If, in the unfolded line of candies, every pair of adjacent candies has different colors, then this cut is called a beautiful cut.

Please calculate the number of beautiful cuts.

Input Format

The first line contains an integer NN, indicating the number of candies.

The second line contains a string SS of length NN, where the ii-th character SiS_i represents the color of the ii-th candy.

Output Format

Output one line containing an integer, indicating the number of beautiful cuts.

6
ababab
6
5
aabcd
1
8
aaabbcde
0

Hint

Sample Explanation 1

On the ring, every pair of adjacent candies has different colors. No matter which cut you choose, in the unfolded line the adjacent colors are still all different, so all 6 cuts are beautiful.

Sample Explanation 2

On the ring, only the 1st and the 2nd candies have the same color. Only by cutting between these two candies will this pair of adjacent same-color candies not be kept after unfolding, so the number of beautiful cuts is 1.

Sample Explanation 3

On the ring, there are at least two pairs of adjacent candies with the same color. A single cut can break at most one adjacent relationship, so after unfolding there will still be adjacent same-color candies, and there are no beautiful cuts.

Constraints and Notes

For 30%30\% of the testdata, 2≤N≤2002 \le N \le 200.

For 60%60\% of the testdata, 2≤N≤50002 \le N \le 5000.

For all testdata, 2≤N≤2×1052 \le N \le 2 \times 10^5, and SS consists only of lowercase English letters.

Translated by ChatGPT 5