#P10202. [湖北省选模拟 2024] 沉玉谷 / jade

[湖北省选模拟 2024] 沉玉谷 / jade

Background

If there were no gods under heaven, this would be the kingdom of humans.

Problem Description

You will preside over a ritual. The ritual uses NN jade stones arranged in a line, numbered from left to right as 1,2,,N1,2,\cdots,N. The color of jade stone ii is aia_i.

In each round of the ritual, you need to choose a consecutive segment of jade stones with the same color alar(1lrN50)a_l \sim a_r(1\le l \le r\le N\le 50), and sink them into the water. The immortal power value KK of this ritual will become 10000K+100l+r10000\cdot K+100\cdot l+r, where the initial value of KK is 00.

After a segment of jade stones is sunk into the water, the jade stones on the right will shift left. At the same time, the numbering will also change, and they will be renumbered from left to right as 1,2,1,2,\cdots. For example, there are 77 jade stones with colors 1,1,2,2,2,3,21,1,2,2,2,3,2. At the beginning, the jade stone with color 33 is numbered 66. After jade stones 353\sim 5 are sunk into the water, its number will become 33.

When all jade stones have been sunk into the water, the ritual is completed, and the value of KK at this time is the immortal power value of this ritual. How many different immortal power values are possible after the ritual is completed?

Since the answer may be very large, you only need to output the value modulo 109+710^9+7.

Input Format

The input has two lines.

The first line contains a positive integer NN, representing the number of jade stones.

The second line contains NN positive integers a1,a2,,aNa_1,a_2,\cdots,a_N, where aia_i represents the color of the ii-th jade stone.

Output Format

Output one line with one integer, representing the number of different immortal power values modulo 109+710^9+7.

1
1
1
3
3 3 1
8
5
1 2 1 2 1

165
见选手目录下的 jade/jade4.in 与 jade/jade4.ans。
该样例满足测试点 5 ∼ 8 的限制。
见选手目录下的 jade/jade5.in 与 jade/jade5.ans。
该样例满足测试点 9 ∼ 12 的限制。
见选手目录下的 jade/jade6.in 与 jade/jade6.ans。
该样例满足测试点 13 ∼ 16 的限制。
见选手目录下的 jade/jade7.in 与 jade/jade7.ans。

Hint

Sample Explanation 3

Here are two possible immortal power values and the ways to obtain them:

  1. $(1,\underline{2},1,2,1) \xrightarrow{K=202} (1,1,\underline{2},1) \xrightarrow{K=2\ 020\ 303} (\underline{1},\underline{1},1) \xrightarrow{K=20\ 203\ 030\ 102} (\underline{1}) \xrightarrow{K=202\ 030\ 301\ 020\ 101} ()$, obtaining the immortal power value KK as 202 030 301 020 101202\ 030\ 301\ 020\ 101.

  2. $(1,2,\underline{1},2,1) \xrightarrow{K=303} (1,\underline{2},\underline{2},1) \xrightarrow{K=3\ 030\ 203} (\underline{1},\underline{1}) \xrightarrow{K=30\ 302\ 030\ 102} ()$, obtaining the immortal power value KK as 30 302 030 10230\ 302\ 030\ 102.

Subtasks

For all testdata, it is guaranteed that 1N501 \le N \le 50 and 1aiN1 \le a_i \le N.

Test Point ID NN\le Special Property
121\sim 2 1818 None
33 5050 A
44 B
585\sim 8 C,D
9129\sim 12 C
131613\sim 16 D
172517\sim 25 None

Special Property A: It is guaranteed that ai=ia_i=i.

Special Property B: It is guaranteed that ai=1a_i=1.

Special Property C: It is guaranteed that there do not exist p1<p2<p3<p4p_1<p_2<p_3<p_4 such that ap1=ap3a_{p_1}=a_{p_3}, ap2=ap4a_{p_2}=a_{p_4}, and ap1ap2a_{p_1}\neq a_{p_2}.

Special Property D: It is guaranteed that there do not exist p1<p2<p3p_1<p_2<p_3 such that ap1=ap2=ap3a_{p_1}=a_{p_2}=a_{p_3}.

Translated by ChatGPT 5