#arc104f. [arc104_f]Visibility Sequence
[arc104_f]Visibility Sequence
Problem Statement
There are buildings under construction arranged in a row, numbered from left to right.
Given is an integer sequence of length . The height of Building , , can be one of the integers between and (inclusive).
For each such that , let us define as follows:
- If there is an integer such that , is the maximum such . Otherwise, is .
Considering all possible combinations of the buildings' heights, find the number of integer sequences that can be, modulo .
Constraints
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
Print the number of integer sequences that can be when all possible combinations of the buildings' heights are considered, modulo .
Sample Input 1
3
3 2 1
Sample Output 1
4
We have six candidates for , as follows:
- , for which is ;
- , for which is ;
- , for which is ;
- , for which is ;
- , for which is ;
- , for which is .
Thus, there are four integer sequences that can be: , and .
Sample Input 2
3
1 1 2
Sample Output 2
1
We have two candidates for , as follows:
- , for which is ;
- , for which is .
Thus, there is one integer sequence that can be.
Sample Input 3
5
2 2 2 2 2
Sample Output 3
16
Sample Input 4
13
3 1 4 1 5 9 2 6 5 3 5 8 9
Sample Output 4
31155