Jumping
From a location i, you can jump forward or steps forward. Once you get beyond location , stop making any jumps. Beginning at location 1, how many ways are there get past location .
Input
The first line contains the integer . The following lines contain integers and indicating the size of jumps made. In order of location .
Output
The number of ways of getting from location to beyond , modulo
Constraints
Example 1
In
5
1 2
1 2
1 2
1 2
1 2
Out
13
Example 2
In
10
1 3
1 3
2 2
2 3
2 5
2 5
1 4
1 5
1 4
2 2
Out
31
Comments