#P2476. [SCOI2008] 着色方案
[SCOI2008] 着色方案
Description
There are wooden blocks arranged in a row, numbered from to from left to right.
You have colors of paint, and the -th color is enough to paint blocks.
All the paint is just enough to cover all blocks, i.e., .
Since it looks bad if two adjacent blocks have the same color, you want to count the number of colorings in which any two adjacent blocks have different colors.
Since the answer may be large, please output the result modulo .
Input Format
The first line contains an integer , the number of colors.
The second line contains integers , where is the number of blocks that can be painted with the -th color.
Output Format
Output a single integer, the answer modulo .
3
1 2 3
10
5
2 2 2 2 2
39480
10
1 1 2 2 3 3 4 4 5 5
85937576
Hint
- For 50% of the testdata, , .
- For 100% of the testdata, , .
Translated by ChatGPT 5
京公网安备 11011102002149号