B. Building Skyscrapers
time limit per test
4 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

The Legendary Huron is planning the construction of $$$n$$$ skyscrapers on a major street in Huronland that runs from west to east. The final skyline will be an array of positive integers $$$A = [a_1, a_2, \dots, a_n]$$$, where $$$a_i$$$ is the height of the $$$i$$$-th skyscraper from the west. The order of construction and the heights are yet to be decided. For safety reasons, only one skyscraper can be built at a time.

After all skyscrapers are completed, the Tourism Office will promote each one using a panoramic photo. For each skyscraper $$$i$$$, the office selects the longest contiguous segment of skyscrapers that includes $$$i$$$, such that the maximum height in the segment is $$$a_i$$$, and takes a photo of such segment. A photo is considered successful if:

  1. Skyscraper $$$i$$$ is the last one built among all skyscrapers in the photo.
  2. Let $$$k$$$ be the number of skyscrapers in the segment and $$$d$$$ the absolute difference between the maximum and second maximum heights in it. Then $$$d$$$ must satisfy $$$l_k \leq d \leq r_k$$$, where $$$l_k$$$ and $$$r_k$$$ are input integers. If the segment contains only one skyscraper, the second maximum is considered $$$0$$$. For example, the segment $$$[4, 9, 1, 3]$$$ has $$$d = 5$$$; the segment $$$[2, 1, 2]$$$ has $$$d = 0$$$; and the segment $$$[4]$$$ has $$$d = 4$$$.

The Tourism Office asks the Legendary Huron to assign positive heights and a construction order so that all $$$n$$$ photos are successful. Two plans are different if the heights or construction order differ. Determine the number of such valid plans, modulo $$$998244353$$$.

Input

The first line contains $$$n$$$ ($$$1 \leq n \leq 5 \cdot 10^5$$$).

Then $$$n$$$ lines follows, where the $$$(i+1)$$$-th line contains two integers $$$l_i$$$ and $$$r_i$$$ ($$$0 \leq l_i \leq r_i \leq 10^9$$$).

Output

Print the answer modulo $$$998244353$$$.

Examples
Input
1
1 10
Output
10
Input
1
0 0
Output
0
Input
2
1 4
5 7
Output
24
Input
3
1 1
2 2
3 3
Output
6