#arc157b. [arc157_b]XYYYX
[arc157_b]XYYYX
Problem Statement
You are given a string of length consisting of X
and Y
. You will choose characters at distinct positions in and change each of them: X
becomes Y
and Y
becomes X
. Find the maximum possible number of pairs of consecutive Y
s in the resulting string.
Constraints
- is a string of length consisting of
X
andY
.
Input
The input is given from Standard Input in the following format:
Output
Print the maximum possible number of pairs of consecutive Y
s in the resulting string.
Sample Input 1
5 1
XYXYX
Sample Output 1
2
You will choose one character.
- If you choose the -st character, the resulting string is
YYXYX
, with one pair of consecutiveY
s at positions . - If you choose the -nd character, the resulting string is
XXXYX
, with no pair of consecutiveY
s. - If you choose the -rd character, the resulting string is
XYYYX
, with two pairs of consecutiveY
s at positions and . - If you choose the -th character, the resulting string is
XYXXX
, with no pair of consecutiveY
s. - If you choose the -th character, the resulting string is
XYXYY
, with one pair of consecutiveY
s at positions .
Thus, the sought maximum number is .
Sample Input 2
5 4
XYXYX
Sample Output 2
2
It is optimal to choose the -st, -nd, -rd, and -th characters to get YXYYY
, or choose the -st, -rd, -th, and -th characters to get YYYXY
. Note that you may not choose a character at the same position multiple times.