401376: GYM100425 E The Street Escalator

Memory Limit:128 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

E. The Street Escalatortime limit per test1 secondmemory limit per test128 megabytesinputstandard inputoutputstandard output

The longest escalator in the world is located in Hong Kong. Unlike conventional escalators in the subway, this escalator goes right down the street and was built in order to reduce the number of traffic jams in the city. Now it carries tens of thousands of people every day.

Travelling in Hong Kong, a certain tourist decided to use the escalator to go down. He was surprised when it turned out that the escalator is going only up. The escalator was empty, so the tourist decided to try to walk down to the bottom. But as soon as the tourist began his movement, the passengers began to enter the escalator from the bottom...

The escalator runs upwards at a constant speed; the tourist moves downwards with constant speed which exceeds the escalator's speed by absolute value. At any given time, each person (our tourist or some other passenger) is either on the left side of the escalator or on the right side.

For each passenger who will meet the tourist before the end, we know the side initially selected by him and the probability that he changes the side: each second, the passenger changes the side he is currently standing at to the opposite one with that probability. Moreover, for each passenger, we know the time interval Ti in seconds between entering an escalator and meeting with the tourist. Thus, during the time interval of Ti seconds, the passenger will make a decision whether to change the side exactly Ti times.

The tourist starts moving on the left side and will change the side only if otherwise he will run into a passenger.

You need to find the expected number of times that the tourist will change the side before he will finish his journey at the bottom.

Tourist can be considered thin enough so that he can pass between passengers who stand on adjacent stairs at different sides. The time used by the tourist to change the side is negligible.

Input

The first line of the input contains the integer N (1 ≤ N ≤ 105) which is the number of passengers coming to the bottom of the escalator.

Each of the following N lines contains a description of the passenger which consists of the following three pieces. First comes the time interval Ti in seconds (1 ≤ Ti ≤ 106) between the moment when the passenger entered the escalator and the moment he meets the tourist. Then goes a character Ci which is either "L" if the passenger starts at the left side or "R" if he starts at the right side (sides are given relative to the tourist). It is followed by the probability of side change Pi (0 ≤ Pi ≤ 1) given with no more than three digits after the decimal point. All values of Ti in the input are pairwise different.

Passengers in the input data are listed in the order in which they enter the escalator, that is, in decreasing order of Ti.

Output

Print the expected number of side changes made by tourist with absolute or relative error no more than 10 - 6.

ExamplesInput
2
5 L 0.5
1 R 0.4
Output
1.000000000000

加入题单

上一题 下一题 算法标签: