Jumping

From a location i, you can jump forward aia_i or bib_i steps forward. Once you get beyond location nn, stop making any jumps. Beginning at location 1, how many ways are there get past location nn.

Input

The first line contains the integer nn. The following nn lines contain integers aia_i and bib_i indicating the size of jumps made. In order of location 1,2,3…1,2,3 \dots.

Output

The number of ways of getting from location 11 to beyond nn, modulo 109+710^9 + 7

Constraints

  • 1≤n≤1051 \le n \le 10^5
  • 1≤a,b≤1051 \le a,b \le 10^5

Example 1

In
Code 1
5
1 2
1 2
1 2
1 2
1 2
Out
Code 2
13

Example 2

In
Code 3
10
1 3
1 3
2 2
2 3
2 5
2 5
1 4
1 5
1 4
2 2
Out
Code 4
31

Comments0


No comments yet

Be the first to comment.

New comment


Log in to join the discussion.