#P2476. Paint the Wooden Blocks

    ID: 15747 Type: Default 1000ms 256MiB

Paint the Wooden Blocks

Paint the Wooden Blocks

You are given a row of nn wooden blocks numbered from 11 to nn. You also have kk types of paint. For the ii-th type of paint, you have exactly cic_i units available, and ( \sum_{i=1}^{k}c_i = n ), meaning that the paint is just enough to cover all the blocks. You need to paint all the blocks so that any two adjacent blocks have different colors. Count the number of valid painting schemes. Since the answer could be large, output the result modulo (10^9+7).

inputFormat

The first line contains an integer kk, the number of paint colors. The second line contains kk space-separated integers: c1,c2,,ckc_1, c_2, \dots, c_k, where cic_i indicates the number of blocks that must be painted with the ii-th color. It is guaranteed that ( \sum_{i=1}^{k} c_i = n ).

outputFormat

Output a single integer: the number of valid painting schemes modulo (10^9+7).

sample

1
1
1