The Uncertainty of Politics

Each hearing has a start time and a uniform integer length in [a,b]; pick hearings to attend fully so the expected count is maximized.

Hard8Dynamic programmingProbabilitySortingBinary searchNo attempts yetTime limit2sMemory limit512 MB

Problem

You have a trip to Washington D.C. coming up, and you want to sit in on as many Congressional committee hearings as you can. Your representative gave you a pass that admits you to the audience of any hearing. Three things make the schedule hard to plan.

  1. There are many committees and therefore many hearings, and some of them overlap in time.
  2. Committees start a hearing exactly on time, but how long a hearing runs is hard to predict. The rules do not allow a filibuster in a committee hearing, so no hearing lasts forever.
  3. Entering a hearing that is already underway, or leaving one before it is over, is rude. You do not want to embarrass the representative who gave you the pass, so once you attend a hearing you stay for all of it. The hearing rooms are close together, so the moment one hearing ends you can join another hearing that starts at that same moment.

Congress publishes the schedule well before your trip. For each hearing it gives the start time ss and the values aa and bb, the shortest and the longest possible length of that hearing. The actual length is an integer drawn uniformly from the closed interval [a,b][a, b]. That is, the hearing starts at time ss and ends at time s+Ls + L, where LL is equally likely to be any integer with aLba \le L \le b.

Find a strategy that maximizes the expected number of hearings you attend. As an example, take four hearings with these values.

hearingssaabb
Social media and elections117
NASA missions323
Oil and gas exploration514
Hurricane recovery efforts61010

For this schedule the optimal strategy reaches an expected value of 2.125 hearings. You begin with the NASA hearing, which starts at time 3 and ends at time 5 or at time 6 with equal probability, since its length is uniform over the set {2, 3}. If it ends at time 5 you go straight to the oil and gas exploration hearing, and with probability 1/4 that hearing ends at time 6, which lets you attend a third hearing on hurricane recovery. If the NASA hearing ends at time 6 instead, you go straight to the hurricane recovery hearing. This strategy gives you 3 hearings 12.5% of the time and 2 hearings the other 87.5% of the time, so the expected value is 2.125. Starting with the social media and elections hearing might get you to four hearings if you are lucky, but the best expected value from that start is only 2.10714.

Input

The first line contains an integer nn, the number of scheduled hearings (1n1041 \le n \le 10^4). Each of the next nn lines contains three integers ss, aa, and bb: the start time, the minimum length, and the maximum length of one hearing (1s1061 \le s \le 10^6, 1ab1061 \le a \le b \le 10^6). The hearings are listed in nondecreasing order of start time.

Output

Print, on one line, the expected number of hearings attended under an optimal strategy, rounded to six digits after the decimal point. Always print all six digits, so a value of 1 is printed as 1.000000. In every test case the answer is away from a rounding boundary, so the direction of the rounding does not matter.