100 atcoder#ABC179D. [ABC179D] Leaping Tak
[ABC179D] Leaping Tak
Score : points
Problem Statement
There are cells arranged in a row, numbered from left to right.
Tak lives in these cells and is currently on Cell . He is trying to reach Cell by using the procedure described below.
You are given an integer that is less than or equal to , and non-intersecting segments . Let be the union of these segments. Here, the segment denotes the set consisting of all integers that satisfy .
- When you are on Cell , pick an integer from and move to Cell . You cannot move out of the cells.
To help Tak, find the number of ways to go to Cell , modulo .
Constraints
- and do not intersect ()
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
Print the number of ways for Tak to go from Cell to Cell , modulo .
5 2
1 1
3 4
4
The set is the union of the segment and the segment , therefore holds.
There are possible ways to get to Cell :
- ,
- ,
- and
- .
5 2
3 3
5 5
0
Because holds, you cannot reach to Cell . Print .
5 1
1 2
5
60 3
5 8
1 3
10 15
221823067
Note that you have to print the answer modulo .