loj#P3157. 「NOI2019」机器人

    ID: 16349 传统题 文件IO:robot 3000ms 512MiB 尝试: 0 已通过: 0 难度: (无) 上传者: 标签>多项式 / 形式幂级数NOI离散化2019

「NOI2019」机器人

Description

Recently, Bob invented 22 kinds of robots: type P and type Q. Now he wants to test the mobility of these two robots.

There are nn pillars arranged in a row, numbered from 11 to nn. The ii-th pillar has a height of hih_i. The robots can only move between adjacent pillars, that is, if the robot is currently on the ii-th pillar. it can only move to the (i1)(i-1)-th or (i+1)(i+1)-th pillar.

In each test, Bob will choose a number s(1sn)s\,(1 \leq s \leq n), and put the robots on the ss-th pillar. Then the robots will move according to their own rules.

Robots of type P will always move to the left, but it can't move to the pillars that are higher than pillar ss. Formally, it will stop at pllar l(ls)l\,(l \leq s) if and only if:

  • l=1l = 1 or hl1>hsh_{l-1} > h_s
  • hjhsh_j \leq h_s holds for all ljsl \leq j \leq s

Robots of type Q will always move to the right, but it can only move to the pillars that are shorter than pillar ss. Formally, it will stop at pllar r(rs)r\,(r \leq s) if and only if:

  • r=nr = n or hr+1hsh_{r+1} \geq h_s
  • hj<hsh_j < h_s holds for all s<jrs < j \leq r

Bob can set the height of all the pillars, the height of the ii-th pillar can be any integer in range [Ai,Bi][A_i, B_i]. He wants to know how many possible ways are there to set the heights so that no matter which number ss is, the difference between the number of pillars that the robots pass by is not greater than 22.

Since the answer could be very large, you should print the answer module 109+710^9 + 7 instead.

Input

The first line contains a single integer nn.

Each of the next nn lines contains twp integers Ai,BiA_i, B_i.

Output

Print a single integer — the answer module 109+710^9 + 7.

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

Limits And Hints

For all of the tests, 1n3001 \leq n \leq 300, 1AiBi1091 \leq A_i \leq B_i \leq 10^9.

For partial scores, you can look up at the origin statement (NOI/2019/Day1.pdf).