#include <bits/stdc++.h>
using namespace std;
void proc_status() {
  ifstream t("/proc/self/status");
  cerr << string(istreambuf_iterator<char>(t), istreambuf_iterator<char>())
       << endl;
}
int read() {
  int x = 0, f = 1;
  char c = getchar();
  while (!isdigit(c)) {
    if (c == '-') f = 0;
    c = getchar();
  }
  while (isdigit(c)) {
    x = (x << 3) + (x << 1) + (c ^ 48);
    c = getchar();
  }
  return f ? x : -x;
}
const int mod = 1e9 + 7, maxn = 55;
int fac[maxn << 1], ifac[maxn << 1], inv[maxn << 1], bin[maxn << 1];
int f[maxn][maxn][maxn], g[maxn][maxn], d[maxn], d2[maxn], d3[maxn];
int C(int N, int M) {
  return N < M ? 0 : (long long)fac[N] * ifac[M] % mod * ifac[N - M] % mod;
}
void add(int &x, int y) {
  x += y;
  if (x >= mod) x -= mod;
}
int Pow(int x, int p) {
  int r = 1;
  while (p) {
    if (p & 1) r = (long long)r * x % mod;
    x = (long long)x * x % mod;
    p >>= 1;
  }
  return r;
}
int main() {
  int n = read();
  for (int i = 1; i <= n; ++i) d[i] = read();
  for (int i = 1; i <= n; ++i) d2[i] = d2[i - 1] + (d[i] == 2);
  for (int i = 1; i <= n; ++i) d3[i] = d3[i - 1] + (d[i] == 3);
  inv[0] = inv[1] = fac[0] = fac[1] = ifac[0] = ifac[1] = 1;
  for (int i = 2; i <= 2 * n + 5; ++i) {
    fac[i] = (long long)fac[i - 1] * i % mod;
    inv[i] = (long long)(mod - mod / i) * inv[mod % i] % mod;
    ifac[i] = (long long)ifac[i - 1] * inv[i] % mod;
  }
  bin[0] = 1;
  for (int i = 1; i <= 2 * n + 5; ++i)
    bin[i] = ((long long)bin[i - 1] << 1) % mod;
  for (int i = 1; i <= 2 * n + 5; ++i) bin[i] = Pow(bin[i], mod - 2);
  f[1][1][0] = 1;
  for (int i = 1; i < n; ++i)
    for (int j = 0; j <= i; ++j)
      for (int k = 0; k + j <= i; ++k) {
        add(f[i + 1][j + 1][k], f[i][j][k]);
        if (j) add(f[i + 1][j - 1][k + 2], (long long)f[i][j][k] * j % mod);
        add(f[i + 1][j][k], (long long)f[i][j][k] * k % mod);
        if (j > 1)
          add(f[i + 1][j - 2][k + 2],
              (long long)f[i][j][k] * j % mod * (j - 1) % mod * inv[2] % mod);
        if (k > 1)
          add(f[i + 1][j][k - 2],
              (long long)f[i][j][k] * k % mod * (k - 1) % mod * inv[2] % mod);
        if (j && k)
          add(f[i + 1][j - 1][k], (long long)f[i][j][k] * k % mod * j % mod);
      }
  for (int i = 1; i <= n; ++i)
    for (int j = 0; j <= n; ++j)
      for (int k = 0; k <= n; ++k) {
        if (!f[i][j][k]) continue;
        f[i][j][k] = (long long)f[i][j][k] *
                     Pow((long long)fac[i] * ifac[j] % mod * ifac[k] % mod *
                             ifac[i - j - k] % mod,
                         mod - 2) %
                     mod;
      }
  g[1][1] = 1;
  int ans = 0;
  if (d[1] == 1) g[2][2] = 1;
  if (d[1] == 2) g[2][3] = 1;
  if (d[1] == 3) g[2][4] = 1;
  for (int i = 2; i <= n; ++i)
    for (int j = 1; j <= i; ++j) {
      if (!g[j][i]) continue;
      for (int k = i + 1;
           k - i <= (i == 1 ? d[1]
                            : (d3[i] - d3[j - 1]) * 2 + (d2[i] - d2[j - 1])) &&
           k <= n;
           ++k) {
        int s = k - i;
        int D1 = d2[i] - d2[j - 1], D2 = d3[i] - d3[j - 1];
        for (int x = 0; x <= D1; ++x)
          for (int y = 0; y <= D2 && x + y <= s; ++y) {
            int tmp = s - x - y;
            if ((tmp & 1) || (tmp < 0)) continue;
            add(g[i + 1][k], (long long)C(s, x) * C(s - x, y) % mod * C(D1, x) %
                                 mod * C(D2, y) % mod * C(D2 - y, tmp >> 1) %
                                 mod * fac[x] % mod * fac[y] % mod * fac[tmp] %
                                 mod * bin[tmp >> 1] % mod *
                                 f[i - j + 1][x + (tmp >> 1)][D1 - x + y] %
                                 mod * g[j][i] % mod);
          }
      }
    }
  for (int i = 1; i <= n; ++i)
    add(ans, (long long)g[i][n] * f[n - i + 1][0][d2[n] - d2[i - 1]] % mod);
  cout << ans << endl;
  return 0;
}
