#P4063. [JXOI2017] 数列
[JXOI2017] 数列
Description
Jiutiao Kelian (pinyin) has an integer sequence of length . She now wants to construct an integer sequence of length that satisfies the following:
-
.
-
For any , let be the minimum among through that are greater than or equal to , and let be the maximum among through that are less than or equal to . Then must satisfy . If there is no number greater than or equal to , then ; if there is no number less than or equal to , then .
Now she wants to know how many different sequences satisfy these conditions. Two sequences and are different if and only if there exists at least one position such that .
Input Format
The first line contains an integer , and the second line contains integers .
Output Format
Output a single integer denoting the number of valid sequences. The answer can be large; output it modulo .
3
2 2 2
6
Hint
For example, when and for all , the valid sequences are $[1, 1, 1], [1, 2, 1], [1, 2, 2], [2, 1, 1], [2, 1, 2], [2, 2, 2]$.
Constraints:
| Test point ID | ||
|---|---|---|
Translated by ChatGPT 5
京公网安备 11011102002149号