#include <bits/stdc++.h>
const int N = 51;
const int P = 1000000007;
int n, d[N], now, last, f[2][N][N][N][N];
inline void trans(int t[][N], int s[][N], const int &k, const int &e,
                  const int &r, const int &t1, const int &t2) {
  t[e + t1][r + t2] = (t[e + t1][r + t2] + (long long)k * s[e][r]) % P;
  if (e) t[e + t2 - 1][r] = (t[e + t2 - 1][r] + (long long)k * e * s[e][r]) % P;
  if (r)
    t[e + t2 + 1][r - 1] =
        (t[e + t2 + 1][r - 1] + (long long)k * r * s[e][r]) % P;
  if (t2) {
    if (e && r)
      t[e][r - 1] = (t[e][r - 1] + (long long)k * e * r * s[e][r]) % P;
    if (e > 1)
      t[e - 2][r] =
          (t[e - 2][r] + (long long)k * e * (e - 1) / 2 * s[e][r]) % P;
    if (r > 1)
      t[e + 2][r - 2] =
          (t[e + 2][r - 2] + (long long)k * r * (r - 1) / 2 * s[e][r]) % P;
  }
}
int main() {
  scanf("%d", &n);
  int i, t1, t2, q, w, e, r;
  for (i = 1; i <= n; ++i) scanf("%d", &d[i]);
  now = 0, last = 1;
  f[now][d[1] == 2][d[1] == 3][d[2] == 2][d[2] == 3] = 1;
  for (i = 3; i <= n; ++i) {
    now ^= 1, last ^= 1;
    memset(f[now], 0, sizeof(f[now]));
    t1 = d[i] == 2, t2 = d[i] == 3;
    for (q = 0; q < i; ++q)
      for (w = 0; q + w < i; ++w)
        for (e = 0; q + w + e < i; ++e)
          for (r = 0; q + w + e + r < i; ++r) {
            if (!f[last][q][w][e][r]) continue;
            if (q) trans(f[now][q - 1][w], f[last][q][w], q, e, r, t1, t2);
            if (w) trans(f[now][q + 1][w - 1], f[last][q][w], w, e, r, t1, t2);
          }
    for (q = 0; q < i; ++q)
      for (w = 0; q + w < i; ++w)
        if (q + w) (f[now][q][w][0][0] += f[now][0][0][q][w]) %= P;
  }
  printf("%d\n", f[now][0][0][0][0]);
  return 0;
}
