#P51175. [NOI 2019] Robots
[NOI 2019] Robots
Description
Recently, Bob invented kinds of robots: type P and type Q. Now he wants to test the mobility of these two robots.
There are pillars arranged in a row, numbered from to . The -th pillar has a height of . The robots can only move between adjacent pillars, that is, if the robot is currently on the -th pillar. it can only move to the -th or -th pillar.
In each test, Bob will choose a number , and put the robots on the -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 . Formally, it will stop at pllar if and only if:
- or
- holds for all
Robots of type Q will always move to the right, but it can only move to the pillars that are shorter than pillar . Formally, it will stop at pllar if and only if:
- or
- holds for all
Bob can set the height of all the pillars, the height of the -th pillar can be any integer in range . He wants to know how many possible ways are there to set the heights so that no matter which number is, the difference between the number of pillars that the robots pass by is not greater than .
Since the answer could be very large, you should print the answer module instead.
Input
The first line contains a single integer .
Each of the next lines contains twp integers .
Output
Print a single integer — the answer module .
Sample
5
3 3
2 2
3 4
2 2
3 3
1
There are two possible ways to set the heights:
- If the heights are respectively. When , we can see that Robot of type P will stop at pillar (pass by pillars in total) and robot of type Q will stop at pillar (pass by pillars in total), which breaks the condition.
- If the heights are respectively. We can show that no matter which number is, the condition is always satisfied.
Limits And Hints
For all of the tests, , .
For partial scores, you can look up at the origin statement (NOI/2019/Day1.pdf
).