#include <bits/stdc++.h>
using namespace std;
vector<vector<long long> > mul(vector<vector<long long> > a,
                               vector<vector<long long> > b) {
  vector<vector<long long> > c;
  c.resize(a.size());
  for (int i = 0; i < c.size(); i++) c[i].resize(b[0].size(), 0);
  for (int i = 0; i < c.size(); i++)
    for (int j = 0; j < c[i].size(); j++)
      for (int k = 0; k < b.size(); k++)
        c[i][j] = (c[i][j] + a[i][k] * b[k][j]);
  return c;
}
vector<vector<long long> > def;
vector<vector<long long> > bpow(vector<vector<long long> > a, long long st) {
  if (st == 0) return def;
  if (st == 1) return a;
  vector<vector<long long> > b = bpow(a, st >> 1);
  b = mul(b, b);
  if (st & 1) b = mul(a, b);
  return b;
}
long long AR = 19, BR = 13, CR = 23, XR = 228, YR = 322, MOD = 1e9 + 993;
long long myrand() {
  long long ZR = (XR * AR + YR * BR + CR) % MOD;
  XR = YR;
  YR = ZR;
  return ZR;
}
long long sqr(long long x) { return x * x; }
const long long llinf = 2e18;
const long double EPS = 1e-9;
const int maxn = 2e5 + 100, inf = 1e9 + 100, mod = 1e9 + 7;
long long md(long long x) { return x % mod; }
int n;
int d[maxn];
long long sq[55][55][55][55];
long long q[55][55];
long long bpow(long long x, long long y) {
  if (y == 0) return 1;
  if (y == 1) return x;
  long long ret = bpow(x, y >> 1);
  ret = md(ret * ret);
  if (y & 1) ret = md(ret * x);
  return ret;
}
long long bdiv(long long x, long long y) { return md(x * bpow(y, mod - 2)); }
long long fact[55];
void prefact() {
  fact[0] = 1;
  for (long long i = 1; i <= n; i++) fact[i] = md(fact[i - 1] * i);
}
void presq() {
  for (int l = 1; l < n; l++) {
    if (d[l] == 3)
      sq[l][l][2][1] = 1;
    else
      sq[l][l][1][0] = 1;
    for (int r = l; r < n - 1; r++)
      for (int k = 0; k <= (r - l + 1) * 2; k++)
        for (int db = 0; db <= r - l + 1; db++)
          if (sq[l][r][k][db] != 0) {
            long long val = sq[l][r][k][db];
            if (d[r + 1] == 2) {
              sq[l][r + 1][k + 1][db] = md(sq[l][r + 1][k + 1][db] + val);
              if (db > 0)
                sq[l][r + 1][k - 1][db - 1] =
                    md(sq[l][r + 1][k - 1][db - 1] + val * db);
              if (k - 2 * db > 0)
                sq[l][r + 1][k - 1][db] =
                    md(sq[l][r + 1][k - 1][db] + val * (k - 2 * db));
            } else {
              sq[l][r + 1][k + 2][db + 1] =
                  md(sq[l][r + 1][k + 2][db + 1] + val);
              if (db > 0)
                sq[l][r + 1][k][db - 1] =
                    md(sq[l][r + 1][k][db - 1] + val * db);
              if (k - 2 * db > 0)
                sq[l][r + 1][k][db] =
                    md(sq[l][r + 1][k][db] + val * (k - 2 * db));
              if (k - 2 * db > 1)
                sq[l][r + 1][k - 2][db] =
                    md(sq[l][r + 1][k - 2][db] +
                       val * (k - 2 * db) * (k - 2 * db - 1) / 2);
              if (k - 2 * db > 0 && db > 0)
                sq[l][r + 1][k - 2][db - 1] =
                    md(sq[l][r + 1][k - 2][db - 1] + val * (k - 2 * db) * db);
              if (db > 1)
                sq[l][r + 1][k - 2][db - 2] =
                    md(sq[l][r + 1][k - 2][db - 2] + val * db * (db - 1) / 2);
            }
          }
  }
}
void preq() {
  if (d[0] == 2)
    q[1][2] = 1;
  else
    q[1][3] = 1;
  for (int r = 2; r < n; r++)
    for (int l = 1; l <= r; l++)
      if (q[l][r] > 0)
        for (int k = 0; k <= (r - l + 1) * 2; k++)
          for (int db = 0; db <= r - l + 1; db++)
            if (r + k < n)
              q[r + 1][r + k] =
                  md(q[r + 1][r + k] +
                     bdiv(md(md(q[l][r] * sq[l][r][k][db]) * fact[k]),
                          bpow(2, db)));
}
int main() {
  ios::sync_with_stdio(0);
  cin >> n;
  for (int i = 0; i < n; i++) cin >> d[i];
  if (d[0] == 3 && n == 3) {
    cout << 0;
    return 0;
  }
  prefact();
  presq();
  preq();
  long long answer = 0;
  for (int l = 1; l < n; l++)
    answer = md(answer + q[l][n - 1] * sq[l][n - 1][0][0]);
  cout << answer;
}
