atcoder#ARC150E. [ARC150E] Weathercock
[ARC150E] Weathercock
Score : points
Problem Statement
people are standing in a line from left to right. Let us denote them as person from left to right.
Each person is always facing either left or right. The direction of each person at time is represented by a string of length , , consisting of L
and R
. At time , person is facing left if is L
, and right if it is R
.
At time , these people simultaneously change their directions according to the following rules.
- When a person is facing left: If there are one or more people in the direction the person is facing, and more than half of those people are facing right, the person changes direction and faces right. Otherwise, the person does not change direction.
- When a person is facing right: If there are one or more people in the direction the person is facing, and more than half of those people are facing left, the person changes direction and faces left. Otherwise, the person does not change direction.
Find the sum, modulo , of the numbers of times the people change direction from time to .
Constraints
- is a string of length consisting of
L
andR
. - All numerical values in the input are integers.
Input
The input is given from Standard Input in the following format:
Output
Print the answer.
7 1
RRLRLLL
9
If we represent the directions of the seven people at each time, we have LLRLRRL
at , LLRLRLL
at , and LLLLLLL
at .
After , the directions of the seven people do not change. Therefore, the answer is .
4 10
LLRR
0
23 200
RLRRRLLLLLLLLRRRLLRLRRR
2207