#abc179d. [abc179_d]Leaping Tak
[abc179_d]Leaping Tak
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 , , \\ldots, . 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 .
Sample Input 1
Sample Output 1
The set is the union of the segment and the segment , therefore holds.
There are possible ways to get to Cell :
- ,
- ,
- and
- .
Sample Input 2
Sample Output 2
Because holds, you cannot reach to Cell . Print .
Sample Input 3
Sample Output 3
Sample Input 4
Sample Output 4
Note that you have to print the answer modulo .