Under construction

Still being built. Things may change

Bessie Slows Down

Time limit1sMemory limit128 MB

Summary
Bessie runs 1000 metres with speed 1/(k+1) after k slowdowns triggered by time or distance events, and the total time is rounded to the nearest second.
Level

Medium4 of 10

Topics
Simulation, Sorting, Math
Solved
No attempts yet

Problem

Bessie the cow is racing in the cross-country skiing event at the winter Moolympic games. She starts out at 1 metre per second. She tires as the race goes on, so she keeps slowing down. After the first slowdown she moves at 12\frac{1}{2} metre per second, after the second at 13\frac{1}{3} metre per second, and in general after kk slowdowns she moves at 1k+1\frac{1}{k+1} metre per second.

When and where Bessie slows down is given as a list of events. T 17 means she slows down at a specific time, 17 seconds into the race. D 10 means she slows down at a specific distance from the start, 10 metres in this case.

Given NN such events, compute how many seconds Bessie needs to cover a full kilometre. Round the answer to the nearest integer second, and round up when the fractional part is exactly 0.50.5.

Input

The first line has NN. (1≤N≤100001 \le N \le 10000)

Each of the next NN lines holds one event, either T x or D x. T x is a time event and D x is a distance event, and xx is a non-negative integer. Every event happens before Bessie completes 1000 metres. Several events can land on the same moment, and then Bessie slows down that many times at once. The events are not necessarily listed in order.

No input makes the exact finishing time land on x.5x.5.

Output

Print the total time Bessie takes to travel 1 kilometre.

Hint

Suppose one event sits at time 30 and another at distance 10. Bessie covers the first 10 metres at 1 metre per second, which takes 10 seconds. Her speed then drops to 12\frac{1}{2} metre per second, so the next 10 metres take 20 seconds. That moment is the 30 second mark, where she slows again to 13\frac{1}{3} metre per second. The remaining 980 metres take 980×3=2940980 \times 3 = 2940 seconds, so the total is 10+20+2940=297010 + 20 + 2940 = 2970 seconds.

Examples1

  1. Example 1

    Input
    2
    T 30
    D 10
    
    Expected output
    2970