#include <bits/stdc++.h>
using namespace std;
const long long MAXN = 60;
const long long Mod = 1e9 + 7;
long long c[MAXN][MAXN];
long long r[MAXN][MAXN];
long long dp[MAXN][MAXN];
long long d[MAXN];
long long fact[MAXN];
long long rev_p_2[MAXN];
long long pw(long long x, long long n) {
  if (n == 0) {
    return 1;
  }
  long long a = pw(x, n / 2);
  a *= a;
  a %= Mod;
  if (n & 1) {
    a *= x;
    a %= Mod;
  }
  return a;
}
int main() {
  ios_base ::sync_with_stdio(false);
  cin.tie(0);
  long long n;
  cin >> n;
  fact[0] = 1;
  for (long long i = 1; i <= n; i++) {
    fact[i] = fact[i - 1] * i;
    fact[i] %= Mod;
  }
  for (long long i = 0; i <= n; i++) {
    for (long long j = 0; j <= i; j++) {
      if (j == 0 || j == i) {
        c[i][j] = 1;
      } else {
        if (i != 0) {
          c[i][j] = c[i - 1][j] + c[i - 1][j - 1];
          c[i][j] %= Mod;
        }
      }
    }
  }
  r[0][0] = 1;
  for (long long i = 3; i <= n; i++) {
    for (long long j = i - 3; j >= 0; j--) {
      long long k = fact[i - j - 1] * c[i - 1][i - j - 1];
      k %= Mod;
      k *= r[0][j];
      k %= Mod;
      k *= pw(2, Mod - 2);
      k %= Mod;
      r[0][i] += k;
      r[0][i] %= Mod;
    }
  }
  for (long long i = 2; i <= n; i += 2) {
    for (long long j = 0; j <= n; j++) {
      for (long long u = 0; u <= j; u++) {
        long long k = (i - 1) * c[j][u];
        k %= Mod;
        k *= fact[u];
        k %= Mod;
        r[i][j] += k * r[i - 2][j - u];
        r[i][j] %= Mod;
      }
    }
  }
  rev_p_2[0] = 1;
  for (long long i = 1; i <= n; i++) {
    rev_p_2[i] = rev_p_2[i - 1] * pw(2, Mod - 2);
    rev_p_2[i] %= Mod;
  }
  for (long long i = 1; i <= n; i++) {
    cin >> d[i];
  }
  dp[1][d[1]] = pw(fact[d[1]], Mod - 2);
  for (long long i = 2; i <= n; i++) {
    for (long long j = 0; j <= n; j++) {
      long long a = 0, b = 0;
      for (long long u = i; u > 1; u--) {
        a += (d[u] == 3);
        b += (d[u] == 2);
        for (long long w = 0; w <= a && 2 * w <= j; w++) {
          for (long long y = 0; y <= (a - w) && y <= (j - 2 * w); y++) {
            if (b < (j - 2 * w - y)) {
              continue;
            }
            long long k = c[a][w] * c[a - w][y];
            k %= Mod;
            k *= c[b][j - 2 * w - y];
            k %= Mod;
            k *= rev_p_2[w];
            k %= Mod;
            k *= fact[i - u + 1];
            k %= Mod;
            k *= r[b - j + 2 * y + 2 * w][a - w - y];
            k %= Mod;
            dp[i][j] += k * dp[u - 1][i - u + 1];
            dp[i][j] %= Mod;
          }
        }
      }
    }
  }
  cout << dp[n][0];
}
