#abc238h. [abc238_h]Removing People
[abc238_h]Removing People
Problem Statement
people numbered to are standing in a circle, in the clockwise order of Person , Person , , Person . The direction each person faces is given by a string of length . For each , Person is facing in the counter-clockwise direction if L
, and clockwise direction if R
.
The following operation will be repeated times.
- Choose one of the remaining people with equal probability, and remove from the circle the nearest person seen from the chosen person. This incurs a cost equal to the distance from the chosen person to the removed person.
Here, the distance from Person to Person is defined as follows.
- When Person is facing in the clockwise direction:
- if ;
- if .
- When Person is facing in the counter-clockwise direction:
- if ;
- if .
Find the expected value of the total cost incurred, modulo (see Notes).
Notes
It can be proved that the sought expected value is always a rational number. Additionally, under the Constraints of this problem, when that value is expressed as using two coprime integers and , there is a unique integer such that and . Find this .
Constraints
- is an integer.
- is a string of length consisting of
L
andR
.
Input
Input is given from Standard Input in the following format:
Output
Print the answer.
Sample Input 1
3
LLR
Sample Output 1
831870297
The sought expected value is . We have , so should be printed.
For your reference, here is one possible scenario.
- Person is chosen. The nearest person seen from Person remaining in the circle is Person , who gets removed from the circle.
- Person is chosen again. The nearest person seen from Person remaining in the circle is Person , who gets removed from the circle.
In this case, the total cost incurred is .
Sample Input 2
10
RRRRRRLLRR
Sample Output 2
460301586