COCI '11 Contest 5 #3 Dna
View as PDFBiologists have discovered a strange DNA molecule, best described as a sequence of characters from
the set
. An unlikely sequence of mutations has resulted in a DNA strand consisting only of
A's.
Biologists found that very odd, so they began studying the mutations in greater detail.
They discovered two types of mutations. One type results in changing a single character of the
sequence . The second type changes a whole prefix of the sequence, specifically
replacing all characters in positions from
to
(for some
between
and
, inclusive) with the other
character (
with
,
with
).
Compute the least possible number of mutations that could convert the starting molecule to its end
state (containing only A characters). Mutations can occur in any order.
Input Specification
The first line of input contains the positive integer
, the length of the molecule.
The second line of input contains a string with characters, with each character being either
or
.
This string represents the starting state of the molecule.
Output Specification
The first and only line of output must contain the required minimum number of mutations.
Sample Input 1
4
ABBA
Sample Output 1
2
Sample Input 2
5
BBABB
Sample Output 2
2
Sample Input 3
12
AAABBBAAABBB
Sample Output 3
4
Comments