F. 期望 Expectations

Memory limit: 512 MiB Time limit: 2000 ms Input file: stdin Output file: stdout
Problem type: traditional Judging mode: text compare

Description

給你 n 個連續型隨機變量 X_1,X_2,\cdots,X_n 。這 n 個隨機變量相互獨立。對於每個 X_i ,它的概率密度函數為:

f_i(x)= \begin{cases} \frac{1}{r_i-l_i} & \text{ 若 } l_i\le x \le r_i \\ 0 & \text{ 其它情況 } \end{cases}

你可以按任意順序重排這 n 個隨機變量,使得期望的逆序對個數最小。

一個序列 (a_1,a_2,\cdots,a_n) 的逆序對個數滿足 1\le i<j \le n a_i>a_j 的小區整數對 (i,j) 的數量。

輸出期望最小逆序對的個數對 10^9+7 取模後的結果。保證答案可以表示成 \frac{P}{Q} 的形式,其中 Q \not \equiv 0\pmod {10^9+7} (P,Q)=1 。你需要輸出 P\times Q^{10^9+5}\bmod 10^9+7


You are given a set of n continuous random variables X_1, X_2, \ldots, X_n . These variables are mutually independent. Each variable X_i has a probability distribution function defined as:

f_i(x)= \begin{cases} \frac{1}{r_i - l_i} & \text{if } l_i \leq x \leq r_i \\ 0 & \text{otherwise} \end{cases}

Your task is to arrange these n variables in any order such that the expectation of inversions is minimized. The number of inversions in a sequence (a_1, a_2, \ldots, a_n) is the count of pairs (i, j) where 1 \leq i < j \leq n and a_i > a_j . Find the minimum expectation using modular arithmetic with modulus 10^9+7 . The result can be expressed as \frac{P}{Q} , where Q \not\equiv 0 \pmod{10^9+7} and (P,Q) = 1 . Output the value P \times Q^{10^9+5} \bmod (10^9+7) .

Input

第一行一個正整數 n ,表示隨機變量的個數。

接下來的 n 行,每行兩個整數 l_i,r_i ,表示第 i 個隨機變量的概率密度函數中的參數。


The first line contains a single integer n , denoting the number of variables.

In the next n lines, each line contains two integers l_i,r_i , denoting the parameters of the i -th probability distribution function.

Output

輸出共一行,一個整數,表示最小期望逆序對的個數對 10^9+7 取模後的結果。


Output a single line with a single integer indicating the minimum expectation modulo 10^9+7 .

Sample

Sample 1 input

3
1 4
2 3
1 3

Sample 1 output

83333335

Sample 2 input

3
1 5
1 4
1 4

Sample 2 output

250000003

Sample explanation

樣例1:一個達到最小期望逆序對數的序列是: ([1,3],[2,3],[1,4])

Example 1: One of the sequences with the minimum expectation of inversions is ([1,3],[2,3],[1,4]) .

Constraint and hint

對於全部數據,滿足 1\le n \le 2\times 10^5, 1\le l_i < r_i \le 10^9

子任務 分數 附加限制
1 10 n\le 5000 , l_i + 1 = r_i
2 20 n\le 5000
3 30 n\le 10^5,1\le l_i < r_i\le 10^5
4 40 無附加限制

It is guaranteed that 1\le n \le 2\times 10^5, 1\le l_i < r_i \le 10^9 .

Subtask Score Additional constraints
1 10 n\le 5000 , l_i + 1 = r_i
2 20 n\le 5000
3 30 n\le 10^5,1\le l_i < r_i\le 10^5
4 40 No additional constraints