#P7767. [COCI 2011/2012 #5] DNA

[COCI 2011/2012 #5] DNA

Description

There is a sequence of length NN consisting of the letters AA and BB.

Each operation can be one of the following two types:

  1. Change one character in the sequence (ABA\to B or BAB\to A).

  2. Change a prefix of the sequence, i.e. perform operation 1 on characters 11 through KK (1KN)(1\le K\le N).

Find the minimum number of operations needed to make the entire sequence all AA.

Input Format

The first line contains an integer NN.

The second line contains NN characters, representing the sequence.

Output Format

Output one line containing one integer, representing the answer.

4
ABBA
2
5
BBABB
2
12
AAABBBAAABBB
4

Hint

1N1061\le N\le 10^{6}.

The sequence consists only of 'A' and 'B'.

Translated from COCI 2011/2012 #5 T3.

Translated by ChatGPT 5