Coloring the Balls

Count the sequences formed by drawing all balls from a box where the last ball of color 1 appears before the last of color 2, and so on.

Medium7Dynamic programmingCombinatoricsMathNo attempts yetTime limit2sMemory limit512 MB

Problem

Alice has nn balls in kk colors. The colors are numbered 1 through kk, and two balls of the same color cannot be told apart. All of the balls sit in one box.

Alice drew the balls out one at a time until the box was empty. Looking at the order she drew them, she noticed this property.

  • For every integer ii with 1i<k1 \le i < k, the last ball of color ii came out before the last ball of color i+1i+1.

For example, [1,2,1,1,2,3][1, 2, 1, 1, 2, 3] satisfies the condition. In contrast, [1,1,2,1,3,3][1, 1, 2, 1, 3, 3] does not, because the last ball of color 1 came out fourth while the last ball of color 2 came out third.

You are given how many balls of each color the box held at the start. Count the drawing orders that satisfy the property above.

Input

The first line contains the number of colors kk. (1k10001 \le k \le 1000)

Each of the next kk lines contains one integer cic_i, the number of balls of color ii. (1ci10001 \le c_i \le 1000)

The sum nn of all cic_i is at most 1000.

Output

Print, on one line, the number of drawing orders that satisfy the property, modulo 10000000071000000007 (109+710^9 + 7).