Grenade throws from Valera#12198

Grenade throws from Valera

2 seconds
1,024 megabytes
Hard

Valera learned another connector smoke, but out of habit, he threw a molotov at his teammates' feet instead. Now, to get invited to FaceIt again, he needs to solve the problem of a person who plays CS2 on macOS. However, he needs to keep learning smokes, so he asked you to help him with the problem.

Given an array of length . You need to find the number of ways to split it into contiguous subarrays such that the of the -th subarray is equal to i−1. Here is in -indexation. Because of the loss of Problem Setter's favorite CS2 team, he asks you to calculate this modulo 10^9+7.

The mex (minimum excluded value) of a set of non-negative integers is the smallest non-negative integer that is not present in the set. The mex of \{1,0,2,4\} is . The mex of \{1,2,3\} is . The mex of \{0,2,3\} is .

Input

The first line contains one integer (1 \leq n \leq 2 \cdot 10^5) — the size of array .

The second line contains integers a_i (0 \leq a_i < n) representing the elements of the array .

Output

For each test case, output a single integer — the number of ways to split the array into contiguous subarrays such that the condition described in the statement is satisfied, modulo 10^9 + 7.

Examples

Example 1

Loading
Loading

Scoring

  1. ( points): n \le 20

  2. ( points): n \le 100;

  3. ( points): n \le 500;

  4. ( points): n \le 800;

  5. ( points): n \le 5\cdot10^4;

  6. ( points): n \le 10^5;

  7. ( points): no additional constraints