#P5469. [NOI2019] 机器人

[NOI2019] 机器人

Description

Little R likes studying robots.

Recently, Little R developed two new types of robots, P-type robots and Q-type robots. Now he wants to test their moving abilities. The test is done on nn pillars arranged in a line from left to right, numbered 1n1 - n in order. The height of pillar ii is a positive integer hih_i. Robots can only move between adjacent pillars, that is: if a robot is currently on pillar ii, it can only try to move to pillar i1i - 1 and pillar i+1i + 1.

In each test, Little R chooses a starting point ss and places both types of robots on pillar ss. Then they move according to their own rules.

The P-type robot keeps moving to the left, but it cannot move onto a pillar that is higher than the starting pillar ss. More specifically, the P-type robot stops at pillar l (ls)l \ (l \leq s) if and only if both of the following conditions hold:

  • l=1l = 1 or hl1>hsh_{l-1} > h_s.

  • For every jj with ljsl \leq j \leq s, we have hjhsh_j \leq h_s.

The Q-type robot keeps moving to the right, but it can only move onto pillars that are lower than the starting pillar ss. More specifically, the Q-type robot stops at pillar r (rs)r \ (r \geq s) if and only if both of the following conditions hold:

  • r=nr = n or hr+1hsh_{r+1} \geq h_s.

  • For every jj with s<jrs < j \leq r, we have hj<hsh_j < h_s.

Now, Little R can set the height of each pillar. The selectable height range for pillar ii is [Ai,Bi][A_i, B_i], that is, AihiBiA_i \leq h_i \leq B_i. Little R hopes that no matter where the test starting point ss is chosen, the absolute value of the difference between the numbers of pillars moved over by the two robots is always less than or equal to 22. He wants to know how many height-setting schemes satisfy this requirement. Little R considers two schemes different if and only if there exists some kk such that the height of pillar kk is different in the two schemes. Please output the number of valid schemes modulo 109+710^9 + 7.

Input Format

The first line contains a positive integer nn, representing the number of pillars.

The next nn lines each contain two positive integers Ai,BiA_i, B_i, representing the minimum and maximum height of pillar ii.

Output Format

Output one line with one integer, the answer modulo 109+710^9 + 7.

5
3 3
3 3
3 4
2 2
3 3
1

Hint

More Samples

You can get more samples through the additional files.

Sample 2

See robot/robot2.in and robot/robot2.ans in the additional files.

Sample 3

See robot/robot3.in and robot/robot3.ans in the additional files.

Sample 4

See robot/robot4.in and robot/robot4.ans in the additional files.

Explanation for Sample 1

There are two possible pillar height settings:

  • Heights: 3 2 3 2 3. If the starting point is set to 55, the P-type robot will stop at pillar 11, moving across 44 pillars. The Q-type robot stops at pillar 55, moving across 00 pillars. This does not satisfy the condition.

  • Heights: 3 2 4 2 3. In this case, no matter where the starting point is chosen, the condition is satisfied. Details are shown in the table below:

::cute-table{tuack}

Starting index P-type robot Q-type robot
11 Stops at pillar 11, moves across 00 Stops at pillar 22, moves across 11
22 Stops at pillar 22, moves across 00
33 Stops at pillar 11, moves across 22 Stops at pillar 55, moves across 22
44 Stops at pillar 44, moves across 00
55 Stops at pillar 44, moves across 11 Stops at pillar 55, moves across 00

Constraints

For all testdata: 1n3001 \leq n \leq 300, 1AiBi1091 \leq A_i \leq B_i \leq 10^9.

The detailed limits for each test point are shown in the table below:

::cute-table{tuack}

Test point ID nn\le Special property
1,21,2 77 Ai=Bi,Bi7A_i=B_i,B_i\le 7
3,43,4 Bi7B_i\le 7
5,6,75,6,7 5050 Bi100B_i\le 100
8,9,108,9,10 300300 Bi104B_i\le 10^4
11,1211,12 5050 Ai=1,Bi=109A_i=1,B_i=10^9
13,14,1513,14,15 None.
16,1716,17 150150 ^
18,1918,19 200200
2020 300300

Translated by ChatGPT 5