#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int sum = 0, p = 1;
  char ch = getchar();
  while (!(('0' <= ch && ch <= '9') || ch == '-')) ch = getchar();
  if (ch == '-') p = -1, ch = getchar();
  while ('0' <= ch && ch <= '9') sum = sum * 10 + ch - 48, ch = getchar();
  return sum * p;
}
const int maxn = 52;
const int mod = 1e9 + 7;
int n, f[maxn][maxn][maxn], g[maxn][maxn], d[maxn], dp[maxn][maxn][maxn],
    jc[maxn], jcn[maxn], inv[maxn];
inline int C(int n, int m) {
  return (long long)jc[n] * jcn[m] % mod * jcn[n - m] % mod;
}
inline int power(int a, int b) {
  int ans = 1;
  while (b) {
    if (b & 1) ans = (long long)ans * a % mod;
    b >>= 1;
    a = (long long)a * a % mod;
  }
  return ans;
}
inline void init() {
  n = read();
  for (int i = (1), _end_ = (n); i <= _end_; i++) d[i] = read();
  jc[0] = jc[1] = jcn[0] = jcn[1] = inv[1] = 1;
  for (int i = (2), _end_ = (50); i <= _end_; i++)
    jc[i] = (long long)i * jc[i - 1] % mod,
    inv[i] = (long long)(mod - mod / i) * inv[mod % i] % mod,
    jcn[i] = (long long)inv[i] * jcn[i - 1] % mod;
  f[0][0][0] = 1;
  for (int k = (2), _end_ = (50); k <= _end_; k++)
    if (~k & 1) f[0][0][k] = (long long)f[0][0][k - 2] * (k - 1) % mod;
  for (int j = (1), _end_ = (50); j <= _end_; j++)
    for (int k = (0), _end_ = (50); k <= _end_; k++)
      if (~k & 1) {
        if (k >= 2)
          f[0][j][k] =
              (f[0][j][k] + (long long)f[0][j - 1][k - 2] * C(k, 2)) % mod;
        if (j >= 2)
          f[0][j][k] =
              (f[0][j][k] + (long long)f[0][j - 2][k] * (j - 1) * k) % mod;
        if (j >= 3)
          f[0][j][k] =
              (f[0][j][k] + (long long)f[0][j - 3][k + 2] * C(j - 1, 2)) % mod;
      }
  for (int i = (1), _end_ = (50); i <= _end_; i++)
    for (int j = (0), _end_ = (50); j <= _end_; j++)
      for (int k = (0), _end_ = (50); k <= _end_; k++)
        f[i][j][k] = ((j ? (long long)f[i - 1][j - 1][k + 1] * j : 0) +
                      (k ? (long long)f[i - 1][j][k - 1] * k : 0)) %
                     mod;
}
inline void doing() {
  dp[1][1][1] = 1;
  if (d[1] == 2) {
    dp[2][3][2] = 1;
  } else {
    dp[2][4][3] = 1;
  }
  for (int i = (3), _end_ = (n); i <= _end_; i++) {
    for (int j = (i), _end_ = (n); j <= _end_; j++) {
      for (int k = (1), _end_ = (j); k <= _end_; k++) {
        int A = 0, B = 0;
        for (int l = (1), _end_ = (j - k); l <= _end_; l++) {
          (d[j - k - l + 1] == 2 ? B : A)++;
          dp[i][j][k] =
              (dp[i][j][k] + (long long)dp[i - 1][j - k][l] * f[k][A][B]) % mod;
        }
      }
    }
  }
  int ans = 0;
  for (int i = (2), _end_ = (n); i <= _end_; i++) {
    int A = 0, B = 0;
    for (int k = (1), _end_ = (n); k <= _end_; k++) {
      (d[n - k + 1] == 2 ? B : A)++;
      ans = (ans + (long long)dp[i][n][k] * f[0][A][B]) % mod;
    }
  }
  printf("%d\n", ans);
}
int main() {
  init();
  doing();
  return 0;
}
