#P3643. [APIO2016] 划艇

[APIO2016] 划艇

Description

In the city of Seoul, the Han River runs east to west. On its north bank, from west to east, there are NN rowing schools, numbered 11 to NN. Each school owns several boats. All boats from the same school share the same color, and different schools have different colors. Boats of the same color are considered identical. Each school may choose to send some boats to the festival, or choose not to send any. If school ii chooses to participate, it may send any number of boats between aia_i and bib_i inclusive (aibia_i \leq b_i).

Importantly, if school ii participates, the number of boats it sends must be greater than the number sent by any participating school with a smaller index.

Given all aia_i and bib_i, determine how many possible participation configurations there are, with at least one boat participating. Two configurations are different if and only if there exists some color (i.e., some school) for which the number of participating boats differs.

Input Format

The first line contains an integer NN, the number of schools.

The next NN lines each describe one school. Line ii contains two positive integers aia_i and bib_i (1aibi1091 \leq a_i \leq b_i \leq 10^9).

Output Format

Output a single line with one integer: the number of possible configurations modulo 1,000,000,0071{,}000{,}000{,}007.

2
1 2
2 3
7

Hint

Sample explanation:

  • When only one school participates, there are 44 configurations.
  • When both schools participate, there are 33 configurations.
  • Therefore, the answer is 77.

Constraints:

  • Subtask 11 (9 points): 1N5001 \leq N \leq 500 and ai=bia_i = b_i for all 1iN1 \leq i \leq N.
  • Subtask 22 (22 points): 1N5001 \leq N \leq 500 and i=1N(biai)106\sum_{i=1}^N (b_i - a_i) \leq 10^6.
  • Subtask 33 (27 points): 1N1001 \leq N \leq 100.
  • Subtask 44 (42 points): 1N5001 \leq N \leq 500.

Translated by ChatGPT 5