spoj#SKIING. Alpine Skiing
Alpine Skiing
Believe it or not, the devices measuring time in alpine ski racing are not perfect. Instead of measuring the exact time, they measure an interval in which the ski racer finished the race (for example 53.42 sec - 53.45 sec).
The probability is distributed evenly on this interval. (More precisely, if we choose any two sub-intervals of equal length, the probability that the ski racer finished the race in each of these sub-intervals is equal. One can also say that each moment in the given interval has equal probability assigned to it, but this in fact says nothing since the probability for each moment is equal to zero (since there are infinitely many moments in the interval) no matter how we distribute the probability.)
And what if there are N ski racers? Then we have N intervals. Find the probability that the first ski racer on the list won the race (that is, finished the race with the minimal time).
Input
In the first line, there is an integer N (1 ≤ N ≤ 300).
In the next N lines, read the intervals assigned to the ski racers: two real numbers Ai and Bi in each line, representing the interval [Ai, Bi] of the i-th ski racer. (0 < Ai < Bi < 1000)
Output
Print the required probability. The absolute difference between yours and official solution may be at most 10-6.
Example
input
2 1.000 5.000 2.500 3.000
output
0.437500
input
4 3.500 17.300 12.700 21.200 2.900 15.000 1.000 20.000output0.263541