100 atcoder#ABC140D. [ABC140D] Face Produces Unhappiness
[ABC140D] Face Produces Unhappiness
Score : points
Problem Statement
There are people standing in a queue from west to east.
Given is a string of length representing the directions of the people.
The -th person from the west is facing west if the -th character of is L
, and east if that character of is R
.
A person is happy if the person in front of him/her is facing the same direction. If no person is standing in front of a person, however, he/she is not happy.
You can perform the following operation any number of times between and (inclusive):
Operation: Choose integers and such that , and rotate by degrees the part of the queue: the -th, -th, , -th persons. That is, for each , the -th person from the west will stand the -th from the west after the operation, facing east if he/she is facing west now, and vice versa.
What is the maximum possible number of happy people you can have?
Constraints
- is an integer satisfying .
- is an integer satisfying .
- Each character of is
L
orR
.
Input
Input is given from Standard Input in the following format:
Output
Print the maximum possible number of happy people after at most operations.
6 1
LRLRRL
3
If we choose , we have LLLRLL
, where the -nd, -rd, and -th persons from the west are happy.
13 3
LRRLRLRRLRLLR
9
10 1
LLLLLRRRRR
9
9 2
RRRLRLRLL
7