#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = (int) 1e6 + 4005;
const LL mod = (LL) 1e9 + 7;
LL c[N], fact[N], inv[N], dp[2005][2005], ans[4005];
// calculates (-1)^n
int sign (int n) {
if (n & 1) return -1;
else return 1;
}
// calculates a^b % mod
LL modpow (LL a, LL b, LL mod) {
LL res = 1;
while (b) {
if (b & 1) res = (res * a) % mod;
a = (a * a) % mod;
b >>= 1;
}
return res;
}
// calculates nCr.
LL C (LL n, LL r) {
if (r < 0 || r > n) return 0;
LL ans = (fact[n] * inv[n - r]) % mod;
return (ans * inv[r]) % mod;
}
int main () {
fact[0] = 1;
// calculate factorial and inverse modulo p for each factorial.
for (LL i = 0; i < N; i++) fact[i + 1] = (LL) (fact[i] * (i + 1)) % mod;
for (int i = 0; i < N; i++) inv[i] = modpow (fact[i], mod - 2, mod);
// process the input and calculate array c_i as shown in the editorial.
int n;
scanf ("%d", &n);
for (int i = 0; i < n; i++) {
int foo;
scanf ("%d", &foo);
c[foo + 1] ++;
}
// Now we come for the dp step.
// dp[i][s] = as given in the editorial, coefficient of x^s in first i steps.
dp[0][0] = 1;
for (int i = 1; i <= 1001; i++) {
for (int s = 0; s <= 2000; s++) {
int k = i;
LL sum = 0;
// try all coefficients of x^(k * l), this is crucial step in complexity reduction.
for (int l = 0; l <= s; l++) {
if (k * l > s) break;
// coefficient of x^(k * l) in (x^(i + 1) - 1) ^ c_i
LL prod = C (c[i], l) * sign (c[i] - l);
sum = (sum + dp[i - 1][s - k * l] * prod) % mod;
if (sum < 0) sum += mod;
}
dp[i][s] = sum;
}
}
// Now do the multiplication part as shown in the editorial.
for (int i = 0; i <= 2000; i++) {
for (int j = 0; j <= 2000; j++) {
// coefficients of x^j in (x - 1)^(-n) is (-1)^n C (n + j - 1, j), See the given link for explantion.
ans[i + j] = (ans[i + j] + dp[1001][i] * sign (n) * C (n + j - 1, j)) % mod;
if (ans[i + j] < 0) ans[i + j] += mod;
}
}
// finally take the query input as given in the problem.
int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