#P50688. [APIO 2016] Boat

[APIO 2016] Boat

Description

In the city of Seoul, a river called the Han River flows in the east-west direction. On the northern shore of the river there are NN boating schools numbered from 11 to NN as you move from the western end to the eastern end of the shore. All boats from the same school have the exact same color and thus are indistinguishable. The boats from different schools always have different colors and thus are always distinguishable. The school numbered ii may choose to not send any boats to the festival. If it chooses to send boats to the festival it may send any number of boats from aia_i to bib_i, inclusive. (aibi)(a_i≤b_i)

One key condition is that the number of boats sent by the school numbered ii, if it has chosen to sendany boats, should be larger than the number of boats sent by any school numbered less than ii, if anysuch school have chosen to send boats.

Given aia_i's and bib_i's for all schools, find the number of all possible ways the schools may send boats to the festival, under the condition that at least one school chooses to send boats.

Input

The first line of the input contains a single integer NN -- the number of schools. The ii'th of the next NN lines contains two integers aia_i and bib_i. (1aibi109)(1≤a_i≤b_i≤10^9)

Output

The output should consist of a single line with the remainder when the number of all possible cases theschools may send boats to the festival is divided by 109+710^9+7.

Sample

2
1 2
2 3
7

There are 4 ways where only one school sends boats and 3 ways where both schools send boats and thus the answer is 7.

Limits And Hints

Subtask 1 (9 points): 1N5001 \le N \le 500 and for all 1iN,1 \le i \le N, ai=bia_i=b_i.

Subtask 2 (22 points): 1N5001 \le N \le 500 and i=1N(biai)106\sum_{i=1}^{N}(b_i-a_i) \le 10^6.

Subtask 3 (27 points): 1N1001 \le N \le 100.

Subtask 4 (42 points): 1N5001 \le N \le 500.