#include <bits/stdc++.h>
namespace Mine {
const int N = 55, M = N * 4, MOD = 1000000007, D2 = 500000004;
inline void inc(long long a, long long &b) { b = (a + b) % MOD; }
long long C2(long long x) { return (x * (x - 1) / 2) % MOD; }
long long f[M][M], g[M][M][M];
long long fact[M], C[M][M];
int n;
int d[N];
void initialize() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", d + i);
  f[0][0] = 1;
  long long v;
  for (int k2 = 0; k2 <= n; k2++)
    for (int k1 = 0; k1 <= n; k1++) {
      if ((v = f[k1][k2]) == 0) continue;
      if (k2 == 0) inc(v * (k1 + 1) % MOD, f[k1 + 2][k2]);
      inc(v * C2(k1 + 2) % MOD, f[k1 + 2][k2 + 1]);
      inc(v * k1 % MOD * (k2 + 1) % MOD, f[k1][k2 + 2]);
      inc(v * C2(k2 + 2) % MOD, f[k1 - 2][k2 + 3]);
    }
  fact[0] = 1;
  for (int i = 1; i < M; i++) fact[i] = fact[i - 1] * (long long)i % MOD;
  for (int i = 0; i < M; i++) C[i][0] = 1;
  for (int i = 1; i < M; i++)
    for (int j = 1; j < M; j++) C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]) % MOD;
}
long long calc(long long k1, long long k2) {
  long long ret = C[k1 + k2 * 2][k1] * fact[k1] % MOD * fact[k2 * 2] % MOD;
  for (int i = 1; i <= k2; i++) ret = ret * D2 % MOD;
  return ret;
}
void solve() {
  initialize();
  int tmp1 = 0, tmp2 = 0;
  long long v, w;
  for (int i = 2; i <= d[1] + 1; i++)
    if (d[i] == 2)
      tmp1++;
    else
      tmp2++;
  for (int x = 0; x <= tmp1; x++)
    for (int y = 0; y <= tmp2; y++)
      for (int z = 0; y + z <= tmp2; z++) {
        w = f[x + z][y] * C[tmp1][x] % MOD * C[tmp2][y] % MOD * C[tmp2 - y][z] %
            MOD;
        inc(w, g[d[1] + 1][tmp1 - x + z][tmp2 - y - z]);
      }
  for (int i = d[1] + 1; i <= n; i++)
    for (int k2 = 0; k2 <= n; k2++)
      for (int k1 = 0; k1 <= n; k1++) {
        if (!(v = g[i][k1][k2])) continue;
        if (!k1 && !k2) continue;
        v = v * calc(k1, k2) % MOD;
        tmp1 = tmp2 = 0;
        for (int j = i + 1; j <= i + k1 + k2 * 2; j++)
          if (d[j] == 2)
            tmp1++;
          else
            tmp2++;
        for (int x = 0; x <= tmp1; x++)
          for (int y = 0; y <= tmp2; y++)
            for (int z = 0; y + z <= tmp2; z++) {
              w = v * f[x + z][y] % MOD * C[tmp1][x] % MOD * C[tmp2][y] % MOD *
                  C[tmp2 - y][z] % MOD;
              inc(w, g[i + k1 + k2 * 2][tmp1 - x + z][tmp2 - y - z]);
            }
      }
  printf("%I64d\n", g[n][0][0]);
}
}  // namespace Mine
int main() {
  Mine::solve();
  return 0;
}
