#P10202. Sacrificial Jade Stones

    ID: 12196 Type: Default 1000ms 256MiB

Sacrificial Jade Stones

Sacrificial Jade Stones

We are given NN jade stones arranged in a row and numbered 1,2,,N1,2,\dots,N. Each stone ii has a color aia_i. In each round of the sacrificial ritual you must choose a contiguous segment [l,r][l, r] (with 1lrN1\le l\le r\le N) 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 KK is updated as follows: [ K \leftarrow 10000\cdot K + (100\cdot l + r), ] with an initial value of K=0K=0. After submerging a segment, the stones on the right shift to the left and are renumbered consecutively starting from 11. When all stones have been submerged the ritual is complete, and the final value of KK 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 ll and rr in each removal on the current numbering) differs. Since the answer might be large, output it modulo 109+710^9+7.


Note: Although the update rule for KK may look like it accumulates digits in base 1000010000, 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 KK is numerically equal.

inputFormat

The first line contains a single integer NN (1N501 \le N \le 50).\nThe second line contains NN integers a1,a2,,aNa_1,a_2,\dots,a_N, where aia_i is the color of the ii-th jade stone.

outputFormat

Output a single integer representing the number of distinct final mystical power values modulo 109+710^9+7.

sample

1
1
1

</p>