#include <bits/stdc++.h>
using namespace std;
void qmax(int &x, int y) {
  if (x < y) x = y;
}
void qmin(int &x, int y) {
  if (x > y) x = y;
}
inline int read() {
  char s;
  int k = 0, base = 1;
  while ((s = getchar()) != '-' && s != EOF && !(isdigit(s)))
    ;
  if (s == EOF) exit(0);
  if (s == '-') base = -1, s = getchar();
  while (isdigit(s)) k = k * 10 + (s ^ '0'), s = getchar();
  return k * base;
}
inline void write(long long x) {
  static char cnt, num[20];
  cnt = 0;
  if (!x) {
    putchar('0');
    return;
  }
  for (; x; x /= 10) num[++cnt] = x % 10;
  for (; cnt; putchar(num[cnt--] + 48))
    ;
}
const long long mod = 1e9 + 7;
const int maxn = 60;
long long f[maxn][maxn], g[maxn][maxn][maxn], ny[maxn], jie[maxn];
int n, du[maxn];
int cnt2[maxn], cnt3[maxn];
long long ksm(long long x, int y) {
  long long sum = 1;
  while (y) {
    if (y & 1) sum = sum * x % mod;
    x = x * x % mod;
    y >>= 1;
  }
  return sum;
}
long long C(int x, int y) { return jie[x] * ny[y] % mod * ny[x - y] % mod; }
long long N(int x) {
  if (x == 2) return 1;
  return jie[x - 1] * ny[2] % mod;
}
int main() {
  n = read();
  jie[0] = 1;
  ny[0] = 1;
  for (int i = 1; i <= n; i++) {
    jie[i] = jie[i - 1] * i % mod;
    ny[i] = ksm(jie[i], mod - 2);
    du[i] = read();
    if (du[i] == 2) cnt2[i]++;
    if (du[i] == 3) cnt3[i]++;
    cnt2[i] += cnt2[i - 1];
    cnt3[i] += cnt3[i - 1];
  }
  for (int i = 0; i <= n; i++)
    for (int j = 0; j <= n; j++)
      for (int k = 0; j + k <= n; k++) {
        if (!i && !j && !k) {
          g[i][j][k] = 1;
          continue;
        }
        if (!i && !j && (k)) {
          for (int l = 2; l < k; l++) {
            g[i][j][k] +=
                g[i][j][k - l - 1] * C(k - 1, l) % mod * N(l + 1) % mod;
            g[i][j][k] %= mod;
          }
          continue;
        }
        if (!i) {
          g[i][j][k] += g[i][j - 2][k] * (j - 1) % mod;
          g[i][j][k] += g[i][j][k - 1] * k % mod;
          if (g[i][j][k] >= mod) g[i][j][k] -= mod;
          continue;
        }
        if (j - 1 >= 0) g[i][j][k] = g[i - 1][j - 1][k] * j % mod;
        if (k - 1 >= 0) g[i][j][k] += g[i - 1][j + 1][k - 1] * k % mod;
        g[i][j][k] %= mod;
      }
  f[du[1] + 1][du[1]] = 1;
  for (int i = du[1] + 2; i <= n; i++)
    for (int j = 1; j <= i - du[1] - 1; j++)
      for (int k = 1; k < i - j; k++) {
        f[i][j] +=
            f[i - j][k] *
            g[j][cnt2[i - j] - cnt2[i - j - k]][cnt3[i - j] - cnt3[i - j - k]] %
            mod;
        f[i][j] %= mod;
      }
  long long ans = 0;
  for (int i = 1; i < n; i++) {
    ans += (f[n][i] * g[0][cnt2[n] - cnt2[n - i]][cnt3[n] - cnt3[n - i]]) % mod;
    ans %= mod;
  }
  cout << ans << endl;
  ;
  return 0;
}
