#P8810. [蓝桥杯 2022 国 C] 数组个数

[蓝桥杯 2022 国 C] 数组个数

Problem Description

Xiao Lan has an array B=(b0,b1,,bn1)B = (b_0,b_1,\cdots,b_{n-1}) of length nn. Array BB is obtained from another circular array A=(a0,a1,,an1)A = (a_0,a_1,\cdots,a_{n-1}) of length nn by performing one adjacent maximization operation. Here aia_i and ai+1a_{i+1} are adjacent, and a0a_0 and an1a_{n-1} 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 AA can satisfy the condition such that after one adjacent maximization operation, array BB can be obtained. Note that every element in AA must be a non-negative integer.

Input Format

The first line contains an integer nn, indicating the length of the array.

The second line contains nn integers b0,b1,,bn1b_0,b_1,\cdots,b_{n-1}, 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 10000000071000000007 (i.e. 109+710^9+7).

5
8 6 1 8 8
7

Hint

Sample Explanation

There are 77 possible arrays AA: (6,0,0,1,8)(6,0,0,1,8), (6,0,1,0,8)(6,0,1,0,8), (6,0,1,1,8)(6,0,1,1,8), (6,1,0,0,8)(6,1,0,0,8), (6,1,0,1,8)(6,1,0,1,8), (6,1,1,0,8)(6,1,1,0,8), (6,1,1,1,8)(6,1,1,1,8).

Constraints

For 30%30\% of the testdata, 3n103 \le n \le 10.

For 60%60\% of the testdata, 3n1003 \le n \le 100.

For all testdata, 3n10003 \le n \le 1000, 0bi100 \le b_i \le 10.

Lanqiao Cup 2022 National Contest, Group C, Problem G.

Translated by ChatGPT 5