275 传统题

[ABC421C] 相间字符串 (Alternated)

时间限制
2000ms
内存限制
512MiB
登顶 / 尝试
0/ 0
难度
2

[ABC421C] 相间字符串 (Alternated)

Problem Statement

You are given a string SS of length 2N2N. SS contains exactly NN occurrences of A and NN occurrences of B.

Find the minimum number of operations (possibly zero) needed to make SS have no adjacent identical characters, where an operation consists of swapping two adjacent characters in SS.

Input

The input is given from Standard Input in the following format:

$N$
$S$

Output

Print the answer.

Example

3
AABBBA
2

Note

  • Constraints:

  • 1≤N≤5×1051\leq N \leq 5\times 10^5

  • NN is an integer.

  • SS is a string of length 2N2N consisting of NN occurrences of A and NN occurrences of B.

  • Source: ABC421C