Victor likes trains. Who doesn't?
Victor owns
Roger, Victor's arch-nemesis, has disrupted Victor's trains and arranged them haphazardly. Victor wishes to restore the trains so that they are equally separated from each other. To do this, while the trains are moving, he can force any subset of them to stop running for some amount of time or switch them to the opposite rail. Trains move at a rate of one unit per second when not stopped.
Compute the minimum time in seconds needed for Victor to restore balance to his trains!
Constraints
Subtask 1 [50%]
Subtask 2 [50%]
No additional constraints.
Input Specification
The first line will contain two integers,
Each of the next L
or R
representing the direction that the train is moving in.
Output Specification
Print, on a single line, the minimum amount of time needed for Victor to restore balance.
This amount must have an absolute error of at most
Sample Input 1
100 5
5 R
35 L
46 L
75 L
85 R
Sample Output 1
0.5
Sample Input 2
100 8
9 L
15 R
41 L
33 L
81 R
33 R
100 L
97 R
Sample Output 2
15.5
Comments