On the forest-filled moon of Endor there is, if we are to believe the Guinness Book of Records, the longest stick in the whole galaxy. On that stick of
It is known that the chameleons of Endor worship the ancient ant laws that dictate that the walk along the stick must be continued until the end of the stick is reached (which means getting off it), and when a collision with another chameleon takes place, you must turn 180 degrees and continue the walk in the opposite direction. Additionally, after a chameleon colored in
If you are given the initial positions, colors and directions of movement of all the chameleons, for each color determine the total trip taken by the chameleons in that color before getting off the stick.
Input
The first line of input contains the integers L
(left) or D
(right) that denote the direction of movement of the
Output
The output must contain
Scoring
In test cases worth 50% of total points, it will additionally hold
Sample Input 1
2 3 10
0 0 D
10 1 L
Sample Output 1
10.0
10.0
0.0
Explanation for Sample Output 1
The chameleons collide after 5 travelled meters in the middle of the stick. After that, both chameleons change their direction of movement. The chameleon moving to the right after collision is colored in 0, whereas the chameleon moving to the left after collision is colored in 1.
Sample Input 2
4 3 7
1 0 D
3 0 D
4 1 L
6 2 D
Sample Output 2
10.0
4.0
1.0
Sample Input 3
4 4 5
1 1 D
3 3 L
4 2 D
5 0 L
Sample Output 3
2.5
4.0
2.5
4.0
Comments