Robot
Time limit1sMemory limit512 MB
Count the height assignments within each pillar's range so that, for every start pillar, the two robots' pass counts differ by at most 2, modulo 1e9+7.
- Level
Medium7 of 10
- Topics
- Dynamic programming, Divide and conquer, Combinatorics
- Solved
- No attempts yet
Problem
Two robots, and , take part in a series of experiments. There are pillars in a row, numbered 1 to , and the height of pillar is a positive integer . Each robot moves only to a neighboring pillar. A robot on pillar can only try to move to pillar or . In each experiment, you choose a starting pillar and place both robots on it. Then the robots move by the rules below. Robot always moves left, but it cannot move onto a pillar higher than pillar . Precisely, stops at pillar () if and only if or , and for all . Robot always moves right, but it can only move onto pillars shorter than pillar . Precisely, stops at pillar () if and only if or , and for all . The height of each pillar can be any integer from to , inclusive. For every choice of starting pillar , the absolute difference between the number of pillars that and pass through must be at most 2. Count the height assignments that satisfy this for every . Two assignments differ if some pillar has a different height in them. Output the count modulo .
Input
The first line contains . Each of the next lines contains two integers and .
Output
Print one integer on one line, the answer modulo .
Constraints
and .