#include <bits/stdc++.h>
using namespace std;
void fastIO() {
  std::ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
template <typename T, typename U>
inline void mnze(T &x, U y) {
  if (y < x) x = y;
}
template <typename T, typename U>
inline void mxze(T &x, U y) {
  if (x < y) x = y;
}
void _scan(int &x) { scanf("%d", &x); }
void _scan(long long &x) { scanf("%lld", &x); }
void _scan(double &x) { scanf("%lf", &x); }
void _scan(char &x) { scanf(" %c", &x); }
void _scan(char *x) { scanf("%s", x); }
void scan() {}
template <typename T, typename... U>
void scan(T &head, U &...tail) {
  _scan(head);
  scan(tail...);
}
template <typename T>
void _dbg(const char *sdbg, T h) {
  cerr << sdbg << "=" << h << "\n";
}
template <typename T, typename... U>
void _dbg(const char *sdbg, T h, U... t) {
  while (*sdbg != ',') cerr << *sdbg++;
  cerr << "=" << h << ",";
  _dbg(sdbg + 1, t...);
}
const int MAXN = 52, MOD = 1e9 + 7;
int n, d[MAXN];
long long dpf[MAXN][MAXN][MAXN], dpg[MAXN][MAXN];
long long f(int o1, int o2, int l) {
  (o1, o2, l);
  if (o1 < 0 || o2 < 0 || l < 0) return 0;
  long long &ret = dpf[o1][o2][l];
  if (ret != -1) return ret;
  if (o1 == 0 && o2 == 0 && l == 0) return ret = 1;
  ret = 0;
  if (l > 0) {
    return ret = (o1 * f(o1 - 1, o2, l - 1) + o2 * f(o1 + 1, o2 - 1, l - 1)) %
                 MOD;
  }
  if (o1 > 0) {
    return ret = ((o1 - 1) * f(o1 - 2, o2, 0) + (o2)*f(o1, o2 - 1, 0)) % MOD;
  }
  return ret = ((o2 - 1) * (o2 - 2) / 2 * f(2, o2 - 3, 0)) % MOD;
}
long long g(int l, int r) {
  (l, r);
  long long &ret = dpg[l][r];
  if (ret != -1) return ret;
  int o[3] = {0, 0, 0};
  for (int i = l; i < (int)r + 1; i++) o[d[i] - 1]++;
  if (r == n - 1) {
    return ret = f(o[1], o[2], 0);
  }
  ret = 0;
  for (int k = r + 1; k < (int)n; k++) {
    ret = (ret + f(o[1], o[2], k - r) * g(r + 1, k)) % MOD;
  }
  return ret;
}
int main() {
  scan(n);
  for (int i = 0; i < (int)n; i++) {
    scan(d[i]);
    ;
  }
  memset(dpf, -1, sizeof(dpf));
  memset(dpg, -1, sizeof(dpg));
  printf("%lld\n", g(1, d[0]));
}
