atcoder#ARC104F. [ARC104F] Visibility Sequence
[ARC104F] Visibility Sequence
Score : points
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 .
3
3 2 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 .
3
1 1 2
1
We have two candidates for , as follows:
- , for which is ;
- , for which is .
Thus, there is one integer sequence that can be.
5
2 2 2 2 2
16
13
3 1 4 1 5 9 2 6 5 3 5 8 9
31155