#P10202. Sacrificial Jade Stones
Sacrificial Jade Stones
Sacrificial Jade Stones
We are given jade stones arranged in a row and numbered . Each stone has a color . In each round of the sacrificial ritual you must choose a contiguous segment (with ) such that all the stones in that segment have the same color, and submerge them in water. When you submerge a segment, the mystical power is updated as follows: [ K \leftarrow 10000\cdot K + (100\cdot l + r), ] with an initial value of . After submerging a segment, the stones on the right shift to the left and are renumbered consecutively starting from . When all stones have been submerged the ritual is complete, and the final value of is recorded.
Your task is to determine the number of distinct final mystical power values that can be obtained by performing the removals in different orders. Two removal orders are considered different if the ordered sequence of chosen segments (that is, the and in each removal on the current numbering) differs. Since the answer might be large, output it modulo .
Note: Although the update rule for may look like it accumulates digits in base , different orders of removal (even if they yield the same sequence of removed segments as numbers) are counted only once if the final value of is numerically equal.
inputFormat
The first line contains a single integer ().\nThe second line contains integers , where is the color of the -th jade stone.
outputFormat
Output a single integer representing the number of distinct final mystical power values modulo .
sample
1
1
1
</p>