Problem:
Score : 1000 points

Problem Statement

Snuke has come up with the following problem.

You are given a sequence d of length N.
Find the number of the undirected graphs with N vertices labeled 1,2,...,N satisfying the following conditions, modulo 10^{9} + 7:

The graph is simple and connected.

The degree of Vertex i is d_i.

When 2 \leq N, 1 \leq d_i \leq N-1, {\rm Σ} d_i = 2(N-1), it can be proved that the answer to the problem is \frac{(N-2)!}{(d_{1} -1)!(d_{2} - 1)! ... (d_{N}-1)!}.

Snuke is wondering what the answer is when 3 \leq N, 1 \leq d_i \leq N-1, { \rm Σ} d_i = 2N.
Solve the problem under this condition for him.

Constraints

3 \leq N \leq 300

1 \leq d_i \leq N-1

{ \rm Σ} d_i = 2N

Partial Scores

In the test set worth 200 points, N \leq 5.

In the test set worth another 200 points, N \leq 18.

In the test set worth another 300 points, N \leq 50.

Input

Input is given from Standard Input in the following format:

N
d_1 d_2 ... d_{N}

Output

Print the answer.

Sample Input 1

5
1 2 2 3 2

Sample Output 1

6

There are six graphs as shown below:

Sample Input 2

16
2 1 3 1 2 1 4 1 1 2 1 1 3 2 4 3

Sample Output 2

555275958

Be sure to find the answer modulo 10^{9} + 7.

Solution in C# (Mono 4.6.2.0) (judge verdict: Accepted)

using System;
using System.Linq;
using System.Collections.Generic;

namespace Program {
    public class Solver {

        const long MOD = (long)1e9 + 7;
        static long ModPow(long x, long k) {
            long ret = 1;
            for (; k > 0; k /= 2, x = x * x % MOD)
                if (k % 2 == 1) ret = ret * x % MOD;
            return ret;
        }
        static long Inverse(long x) { return ModPow(x, MOD - 2); }
        static void Add(ref long x, long y) { x = (x + y) % MOD; }


        static void Main() {
            var n = int.Parse(Console.ReadLine());
            var d = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var fact = new long[n + 1];
            var ifact = new long[n + 1];
            fact[0] = ifact[0] = 1;
            for (int i = 1; i <= n; i++) {
                fact[i] = fact[i - 1] * i % MOD;
                ifact[i] = Inverse(fact[i]);
            }
            //cycle
            if (d.All(x => x == 2)) {
                Console.WriteLine(fact[n - 1] * Inverse(2) % MOD);
                return;
            }

            var dp = new long[n + 5, 2];
            dp[0, 0] = 1;
            foreach (var x in d) {
                var next = new long[n + 5, 2];
                for (int i = 0; i <= n; i++)
                    for (int k = 0; k < 2; k++) {
                        Add(ref next[i, k], dp[i, k] * ifact[x - 1]);
                        if (x >= 2) Add(ref next[i + 1, k], dp[i, k] * ifact[x - 2]);
                        if (k == 0 && x >= 3) Add(ref next[i + 1, k + 1], dp[i, k] * ifact[x - 3]);
                    }
                dp = next;
            }


            long ans = 0;
            for (int i = 3; i < n; i++) {
                var coef = fact[n - i - 1] * fact[i - 1] % MOD;
                Add(ref ans, dp[i, 1] * coef);
            }
            Console.WriteLine(ans * Inverse(2) % MOD);
        }
    }
}