#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline bool chkmin(T &x, T y) {
  return y < x ? x = y, 1 : 0;
}
template <typename T>
inline bool chkmax(T &x, T y) {
  return x < y ? x = y, 1 : 0;
}
const int INF = 0x3f3f3f3f;
const int N = 50 + 10, mod = 1e9 + 7;
int f[N][N][N], dp[N][N], deg[N], fac[N], inv[N], Inv2[N], Sum2[N], Sum3[N];
inline int read() {
  int x = 0, flag = 1;
  char ch = getchar();
  while (!isdigit(ch) && ch != '-') ch = getchar();
  if (ch == '-') flag = -1, ch = getchar();
  while (isdigit(ch)) x = (x << 3) + (x << 1) + (ch - '0'), ch = getchar();
  return x * flag;
}
inline void Add(int &x, int y) {
  if ((x += y) >= mod) x -= mod;
}
inline int fpm(int a, int b) {
  int res = 1;
  while (b) {
    if (b & 1) res = 1ll * res * a % mod;
    a = 1ll * a * a % mod, b /= 2;
  }
  return res;
}
inline int Comb(int n) { return 1ll * n * (n - 1) / 2 % mod; }
inline void init(int n) {
  fac[0] = 1;
  for (int i = (1), iend = (n); i <= iend; i++)
    fac[i] = 1ll * fac[i - 1] * i % mod;
  inv[n] = fpm(fac[n], mod - 2);
  for (int i = (n), iend = (1); i >= iend; i--)
    inv[i - 1] = 1ll * inv[i] * i % mod;
}
inline int Getinv(int n) {
  return n == 0 ? 1 : 1ll * inv[n] * fac[n - 1] % mod;
}
int main() {
  int n = read();
  init(n);
  for (int i = (1), iend = (n); i <= iend; i++) {
    deg[i] = read();
    Sum2[i] = Sum2[i - 1] + (deg[i] == 2);
    Sum3[i] = Sum3[i - 1] + (deg[i] == 3);
  }
  int Inv = fpm(2, mod - 2);
  Inv2[0] = 1;
  for (int i = (1), iend = (n); i <= iend; i++)
    Inv2[i] = 1ll * Inv2[i - 1] * Inv % mod;
  for (int k = (0), kend = (n / 2 + 1); k <= kend; k++)
    for (int i = (0), iend = (n); i <= iend; i++)
      for (int j = 0; i + j * 2 <= 2 * n; j++)
        if (i + j * 2 >= k * 2) {
          int &res = f[k][i][j];
          if (k == 0)
            res = 1;
          else {
            if (j) res = (res + 2ll * f[k - 1][i][j - 1] * i * j) % mod;
            if (i > 1) res = (res + 1ll * f[k - 1][i - 2][j] * Comb(i)) % mod;
            if (j > 1)
              res = (res + 4ll *
                               (f[k - 1][i + 2][j - 2] -
                                (k > 1 ? f[k - 2][i][j - 2] : 0) + mod) *
                               Comb(j)) %
                    mod;
          }
          f[k][i][j] = 1ll * f[k][i][j] * Getinv(k) % mod;
        }
  dp[1][deg[1]] = 1;
  for (int i = (1), iend = (n - 1); i <= iend; i++)
    for (int j = (0), jend = (n); j <= jend; j++)
      if (dp[i][j]) {
        for (int k = (0), kend = (n - i - j); k <= kend; k++) {
          int cnt2 = Sum2[i + j] - Sum2[i], cnt3 = Sum3[i + j] - Sum3[i],
              val = (cnt2 + cnt3 * 2 - k);
          if (val & 1 || val < 0) continue;
          Add(dp[i + j][k], 1ll * dp[i][j] * f[val / 2][cnt2][cnt3] % mod *
                                Inv2[cnt3] % mod * fac[k] % mod);
        }
      }
  printf("%d\n", dp[n][0]);
  return 0;
}
