Trystland rulers
Practice
0 (0 votes)
Easy Medium
Problem
5% Success 601 Attempts 30 Points 0.5s Time Limit 256MB Memory 1024 KB Max Code

There is a kingdom, Trystland with n cities aligned in a row. Each city i is ruled by some ruler \(R_i\).

Now, starting from city 1 to n, the ruler of the city decides how many cities to the right he wants to capture. In other words, say ruler of city i decides to capture k cities, \(0 \le k \le n-i\), then the ruler of all the cities j, where \(i \le j \le i+k\), gets immediately changed to the ruler of city i.

You are required to find number of different configurations that are possible after the decisions of all the rulers. As the number could be quite large, print the answer modulo \(10^9 + 7\)

Input

The first line consists of an integer n denoting number of cities in the kingdom.

The second line consists of n space seperated integers denoting the sequence of rulers of cities. \(i^{th}\) integer indicate the ruler of the \(i^{th}\) city.

Output

Print one line containing the number of possible configurations modulo \(10^9 + 7\).

Constraints

  • \(1 \le n \le 100000\)

  • \( 1 \le R_i \le 100\)

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:30
2 votes
Tags:
Dynamic ProgrammingAlgorithmsApprovedEasy-Medium
Points:30
Tags:
Easy-Medium
Points:30
12 votes
Tags:
Dynamic ProgrammingCombinatoricsEasy-MediumReadyMathematicsOpenApproved