#include <bits/stdc++.h>
namespace DP_Hao_Nan_A__NYM_Tai_Qiang_Le {
const int N = 55, MOD = 1000000007;
inline void inc(long long a, long long &b) { b = (b + a) % MOD; }
long long f[N][N][N], g[N][N];
int d[N];
int n;
inline long long C2(long long x) { return ((x * (x - 1)) / 2) % MOD; }
void initialize() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", d + i);
  f[0][0][0] = 1;
  long long v;
  for (int c0 = 0; c0 <= n; c0++)
    for (int c2 = 0; c2 <= n; c2++)
      for (int c1 = 0; c1 <= n; c1++) {
        if ((v = f[c0][c1][c2]) == 0) continue;
        if (c2 == 0) {
          inc(v * (c0 + 1) % MOD, f[c0 + 1][c1 + 1][c2]);
          inc(v * (c1 + 1) % MOD, f[c0][c1 + 2][c2]);
        }
        inc(v * C2(c0 + 2) % MOD, f[c0 + 2][c1][c2 + 1]);
        inc(v * (c0 + 1) % MOD * (c1 + 1) % MOD, f[c0 + 1][c1 + 1][c2 + 1]);
        inc(v * C2(c1 + 2) % MOD, f[c0][c1 + 2][c2 + 1]);
        inc(v * (c2 + 1) % MOD * (c0 + 1) % MOD, f[c0 + 1][c1 - 1][c2 + 2]);
        inc(v * (c2 + 1) % MOD * c1 % MOD, f[c0][c1][c2 + 2]);
        inc(v * C2(c2 + 2) % MOD, f[c0][c1 - 2][c2 + 3]);
      }
}
void solve() {
  initialize();
  g[n + 1][n] = 1;
  for (int L = n, cnt1, cnt2, l, r; L > 1; L--)
    for (int R = L; R <= n; R++) {
      cnt1 = cnt2 = 0;
      for (int i = L; i <= R; i++)
        if (d[i] == 2)
          cnt1++;
        else
          cnt2++;
      l = R + 1;
      for (r = std::min(n, R + 1); r <= n; r++)
        inc(g[l][r] * f[r - l + 1][cnt1][cnt2] % MOD, g[L][R]);
    }
  printf("%I64d\n", g[2][d[1] + 1]);
}
}  // namespace DP_Hao_Nan_A__NYM_Tai_Qiang_Le
int main() {
  DP_Hao_Nan_A__NYM_Tai_Qiang_Le::solve();
  return 0;
}
