You are given a set of continuous random variables . These variables are mutually independent. Each variable has a probability distribution function defined as:
Your task is to arrange these variables in any order such that the expectation of inversions is minimized.
The number of inversions in a sequence is the count of pairs where and .
Find the minimum expectation using modular arithmetic with modulus . The result can be expressed as , where and . Output the value .
Input
第一行一個正整數,表示隨機變量的個數。
接下來的行,每行兩個整數,表示第個隨機變量的概率密度函數中的參數。
The first line contains a single integer , denoting the number of variables.
In the next lines, each line contains two integers , denoting the parameters of the -th probability distribution function.
Output
輸出共一行,一個整數,表示最小期望逆序對的個數對 取模後的結果。
Output a single line with a single integer indicating the minimum expectation modulo .
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:一個達到最小期望逆序對數的序列是:。
Example 1: One of the sequences with the minimum expectation of inversions is .