Jumping
Jumping
From a location i, you can jump forward ai or bi steps forward. Once you get beyond location n, stop making any jumps. Beginning at location 1, how many ways are there get past location n.
Input
The first line contains the integer n. The following n lines contain integers ai and bi indicating the size of jumps made. In order of location 1,2,3….
Output
The number of ways of getting from location 1 to beyond n, modulo 109+7
Constraints
- 1≤n≤105
- 1≤a,b≤105
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
Comments0
No comments yet
Be the first to comment.
New comment
Log in to join the discussion.