Universal Cup Judging System

Universal Cup

时间限制: 4 s 内存限制: 512 MB 总分: 100 可 Hack ✓
统计

For a permutation of $1, 2, \ldots, n$, let $s_i$ be the length of the shortest contiguous subarray containing all values $1, 2, \ldots, i$.

Let $\operatorname{pos}_p(x)$ be the position of $x$ in the permutation; we have

$$ s_i = \max_{1 \le x \le i} \operatorname{pos}_p(x) - \min_{1 \le x \le i} \operatorname{pos}_p(x) + 1. $$

For each $i$, an interval constraint $[l_i, r_i]$ is given.

Please count the permutations satisfying $l_i \le s_i \le r_i$ for every $i$. Print the answer modulo $998244353$.

Input

The first line contains an integer $n$ ($1 \le n \le 2 \cdot 10^5$).

Each of the next $n$ lines contains two integers $l_i$ and $r_i$ ($1 \le l_i \le r_i \le n$).

Output

Print the number of valid permutations modulo $998244353$.

Please note that a valid permutation may not exist.

Examples

Input 1

3
1 1
2 2
3 3

Output 1

4

Note

The valid permutations in the example are $(1, 2, 3)$, $(2, 1, 3)$, $(3, 1, 2)$, and $(3, 2, 1)$.

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.