Interstellar Transmissions

Time limit: 0.25s Memory limit: 16MB Input: Output:

Task

After reading about the ambitious SETI program, William decided to join the project and build an array of NN radios for interstellar transmissions in his garage. However, the array has not received any extraterrestrial message yet, fact that William blamed to the phenomenon of interference.

In particular, William noticed that whenever the ii-th radio is turned on, ViV_i of the radios on its left (that is, radios j=iVii1j = i-V_i \ldots i-1) receive disturbed signals and are not usable. Fortunately, no interfering signals are received by radios on the right (that is, with j>ij > i). In order to plan his next experiment avoiding interferences, William now needs to select a subset of his radios avoiding interferences, that is, such that if radio ii is turned on then all radios between iVii-V_i and i1i-1 are turned off.

Help William plan his next experiment, by counting the number of subsets of radios avoiding interferences modulo 109+710^9 + 7.

Input data

The first line contains the only integer NN. The second line contains NN integers ViV_i.

Output data

You need to write a single line with an integer: the number of valid subsets of radios modulo 109+710^9 + 7.

Constraints and clarifications

  • 1N10000001 \le N \le 1\,000\,000.
  • 0Vii0 \le V_i \le i for each i=0N1i=0\ldots N-1.
# Points Constraints
1 5 Examples.
2 20 Vi=1V_i = 1 for each i=0N1i=0\ldots N-1.
3 30 N10N \le 10.
4 25 N1000N \le 1000.
5 20 No additional limitations.

Example 1

stdin

3
0 0 0

stdout

8

Explanation

In the first sample case, there is no interference thus all 88 subsets of the three radios are valid.

Example 2

stdin

6
0 1 2 3 2 1

stdout

13

Explanation

In the second sample case, the 1313 valid subsets are the following:

Log in or sign up to be able to send submissions!