#include <bits/stdc++.h>
using namespace std;
template <typename T>
T next_int() {
  T x = 0, p = 1;
  char ch;
  do {
    ch = getchar();
  } while (ch <= ' ');
  if (ch == '-') {
    p = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + (ch - '0');
    ch = getchar();
  }
  return p * x;
}
string next_token() {
  char ch;
  string ans = "";
  do {
    ch = getchar();
  } while (ch <= ' ');
  while (ch > ' ') {
    ans += ch;
    ch = getchar();
  }
  return ans;
}
const long long INF = (long long)1e18;
const int INFINT = (int)1e9 + 227 + 1;
const int MAXN = (int)1e6 + 227 + 1;
const int MOD = (int)1e9 + 7;
const long double EPS = 1e-9;
long long bin_pow(long long a, long long b) {
  if (!b) return 1;
  long long ans = bin_pow(a, b / 2);
  ans = ans * ans % MOD;
  if (b % 2) ans = ans * a % MOD;
  return ans;
}
long long dp[2][51][51][51][51];
long long c[100][100];
int main() {
  c[0][0] = 1;
  for (int i = 0; i < 100; i++)
    for (int j = 0; j < 100; j++)
      if (i) {
        (c[i][j] += c[i - 1][j]) %= MOD;
        if (j) (c[i][j] += c[i - 1][j - 1]) %= MOD;
      }
  int n;
  cin >> n;
  vector<int> d(n);
  for (int i = 0; i < n; i++) d[i] = next_int<int>() - 1;
  dp[0][(d[0] == 1)][(d[0] == 2)][(d[1] == 1)][(d[1] == 2)] = 1;
  for (int i = 2; i < n; i++) {
    for (int q1 = 0; q1 <= i; q1++)
      for (int q2 = 0; q1 + q2 <= i; q2++)
        for (int w1 = 0; q1 + q2 + w1 <= i; w1++)
          for (int w2 = 0; q1 + q2 + w1 + w2 <= i; w2++) {
            if (!dp[0][q1][q2][w1][w2]) continue;
            if (q1 + q2 == 0) {
              if (w1)
                (dp[1][w1 - 1][w2][(d[i] == 1)][(d[i] == 2)] +=
                 dp[0][q1][q2][w1][w2] * w1) %= MOD;
              if (w2)
                (dp[1][w1 + 1][w2 - 1][(d[i] == 1)][(d[i] == 2)] +=
                 dp[0][q1][q2][w1][w2] * w2) %= MOD;
            }
            for (int k = 0; k <= d[i]; k++) {
              for (int f = 0; f <= k; f++) {
                int s = k - f;
                if (q1 && w1 - f >= 0 && w2 - s >= 0) {
                  (dp[1][q1 - 1][q2][w1 - f + ((d[i] - k) == 1) + s]
                     [w2 - s + ((d[i] - k) == 2)] +=
                   dp[0][q1][q2][w1][w2] * c[w1][f] % MOD * c[w2][s] % MOD *
                   q1) %= MOD;
                }
                if (q2 && w1 - f >= 0 && w2 - s >= 0) {
                  (dp[1][q1 + 1][q2 - 1][w1 - f + ((d[i] - k) == 1) + s]
                     [w2 - s + ((d[i] - k) == 2)] +=
                   dp[0][q1][q2][w1][w2] * c[w1][f] % MOD * c[w2][s] % MOD *
                   q2) %= MOD;
                }
              }
            }
          }
    for (int q1 = 0; q1 <= i + 1; q1++)
      for (int q2 = 0; q1 + q2 <= i + 1; q2++)
        for (int w1 = 0; q1 + q2 + w1 <= i + 1; w1++)
          for (int w2 = 0; q1 + q2 + w1 + w2 <= i + 1; w2++) {
            swap(dp[0][q1][q2][w1][w2], dp[1][q1][q2][w1][w2]);
            dp[1][q1][q2][w1][w2] = 0;
          }
  }
  cout << dp[0][0][0][0][0] << "\n";
}
