#P8810. [蓝桥杯 2022 国 C] 数组个数
[蓝桥杯 2022 国 C] 数组个数
Problem Description
Xiao Lan has an array of length . Array is obtained from another circular array of length by performing one adjacent maximization operation. Here and are adjacent, and and are also adjacent.
Formally:
$$b_i= \begin{cases} \max\{a_{n-1},a_0,a_1\}& i=0\\ \max\{a_{i-1},a_i,a_{i+1}\}& 0<i<n-1\\ \max\{a_{n-2},a_{n-1},a_0\}& i=n-1\\ \end{cases}$$Xiao Lan wants to know how many arrays can satisfy the condition such that after one adjacent maximization operation, array can be obtained. Note that every element in must be a non-negative integer.
Input Format
The first line contains an integer , indicating the length of the array.
The second line contains integers , with a single space between adjacent integers.
Output Format
Output one line containing an integer representing the answer. The answer may be very large, so output the remainder after dividing by (i.e. ).
5
8 6 1 8 8
7
Hint
Sample Explanation
There are possible arrays : , , , , , , .
Constraints
For of the testdata, .
For of the testdata, .
For all testdata, , .
Lanqiao Cup 2022 National Contest, Group C, Problem G.
Translated by ChatGPT 5