#hhkb2020f. [hhkb2020_f]Random Max

[hhkb2020_f]Random Max

Problem Statement

There are NN continuous random variables xix_i (1iN1 ≤ i ≤ N), each of which follows the continuous uniform distribution on the interval \[L_i, R_i\]. (That is, xix_i is a random variable that can take any real value between LiL_i and RiR_i (inclusive) with equal probability.)

Let EE be the expected value of the maximum of these NN random variables. Under the constraints in this problem, it can be proved that $E \\times (N+1)! \\times \\prod_{i=1}^N (R_i - L_i)$ is a positive integer. Find this value modulo 1,000,000,0071,000,000,007.

Constraints

  • 1N10001 ≤ N ≤ 1000
  • 0Li<Ri1090 ≤ L_i < R_i ≤ 10^9
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

NN L1L_1 R1R_1 :: LNL_N RNR_N

Output

Print $E \\times (N+1)! \\times \\prod_{i=1}^N (R_i - L_i)$ modulo 1,000,000,0071,000,000,007, as an integer.


Sample Input 1

1
1 2

Sample Output 1

3

The expected value of the maximum of these random variables - there is actually just one in this case - is equal to the median of the range of the values the variable can take, that is, E=frac32E = \\frac{3}{2}.

Thus, the correct output is $E \\times (N+1)! \\times (R_1 - L_1) = E \\times 2 = 3$.


Sample Input 2

2
1 2
1 2

Sample Output 2

10

The expected value in question is E=frac53E = \\frac{5}{3}.


Sample Input 3

2
1 2
2 4

Sample Output 3

36

Sample Input 4

5
40 96
81 92
16 384
32 768
65 536

Sample Output 4

52776507