시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 2048 MB126440.000%

문제

Morgan the robot has an array $A$ of size $N$, indexed from $1$ to $N$. The value of each element in $A$ is randomly generated; $A_i$ can be any integer from $L_i$ to $R_i$ (inclusive) with equal probability.

Morgan defines the beauty of $A$ as follows. First, Morgan has a variable named score that is initialized to $0$. An operation on the array $a$ is as follows:

  • Choose an index $i$ such that $1 ≤ i < |a|$ and $a_i = a_{i+1}$. If no such $i$ exists, then the operation cannot be performed.
  • Add the value of $a_i$ to score and remove $a_i$ from the array.
  • The array $a$ becomes the concatenation of the remaining elements without changing its order.

The beauty of $A$ is the maximum value of score$^2$ Morgan can possibly get after performing zero or more operations on the array $A$.

Since the array is randomly generated, Morgan wonders about the expected beauty of $A$. Due to the inefficiency of his algorithm, Morgan asks for your help to calculate the expected value.

입력

Input begins with an integer $N$ ($1 ≤ N ≤ 200\, 000$) representing the size of array $A$. Each of the next $N$ lines contains two integers $L_i$ $R_i$ ($1 ≤ L_i ≤ R_i ≤ 10^8$).

출력

Let $M = 998\, 244\, 353$. It can be shown that the expected value can be expressed as an irreducible fraction $\frac{p}{q}$, where $p$ and $q$ are integers and $q \not\equiv 0 \bmod M$. Output an integer $x$ in a single line such that $0 ≤ x < M$ and $x \cdot q \equiv p \bmod M$.

예제 입력 1

3
1 2
2 3
1 3

예제 출력 1

831870298

There are $12$ possibilities of $A$. Out of all possibilities, the following has positive beauty.

  • $[1, 2, 2]$ with a beauty of $4$.
  • $[1, 3, 3]$ with a beauty of $9$.
  • $[2, 2, 1]$ with a beauty of $4$.
  • $[2, 2, 2]$ with a beauty of $16$.
  • $[2, 2, 3]$ with a beauty of $4$.
  • $[2, 3, 3]$ with a beauty of $9$.

Therefore, the expected beauty of $A$ is $(4 + 9 + 4 + 16 + 4 + 9)/12 = \frac{46}{12} = \frac{23}{6}$. Since $831\, 870\, 298 \cdot 6 \equiv 23 \bmod 998\, 244\, 353$, you need to output $831\, 870\, 298$.

예제 입력 2

4
1 1
1 1
2 2
2 2

예제 출력 2

9

The only possible value of $A$ is $[1, 1, 2, 2]$ with a beauty of $(1 + 2)^2 = 9$.

예제 입력 3

3
1 2
3 4
5 6

예제 출력 3

0