#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
int n, f[53][53][53], a[53], b[53], c[53], dp[53][53][53];
int func(int p, int q, int r) {
  if (dp[p][q][r] >= 0) return dp[p][q][r];
  int &ans = dp[p][q][r];
  ans = 0;
  for (int i = 1; i <= p - 1; i++)
    ans = (ans + func(i, p - 1, q - p + 1)) % mod;
  ans = (int)(1ll * ans * f[b[q] - b[p - 1]][c[q] - c[p - 1]][r] % mod);
  return ans;
}
int main() {
  memset(dp, -1, sizeof dp);
  int i, j, d, e, r, ans = 0;
  scanf("%d", &n);
  for (i = 1; i <= n; i++) {
    scanf("%d", a + i);
    dp[1][1][i] = 0;
  }
  dp[1][1][0] = 0;
  f[0][0][0] = 1;
  dp[1][1][a[1]] = 1;
  for (e = 1; e <= n; e++) {
    for (r = 0; r <= 2 * e; r++) {
      if (r >= 2)
        f[0][e][r] = (f[0][e][r] +
                      (int)(1ll * r * (r - 1) / 2 * f[0][e - 1][r - 2] % mod)) %
                     mod;
      if (r >= 1 && e >= 2)
        f[0][e][r] =
            (f[0][e][r] + (int)(1ll * r * (e - 1) * f[1][e - 2][r - 1] % mod)) %
            mod;
      if (e >= 3)
        f[0][e][r] = (f[0][e][r] + (int)(1ll * (e - 2) * (e - 1) / 2 *
                                         f[2][e - 3][r] % mod)) %
                     mod;
    }
    for (i = 1; i <= e; i++) {
      j = e - i;
      for (r = 0; r <= 2 * e - i; r++) {
        if (r >= 1)
          f[i][j][r] =
              (f[i][j][r] + (int)(1ll * r * f[i - 1][j][r - 1] % mod)) % mod;
        if (i >= 2)
          f[i][j][r] =
              (f[i][j][r] + (int)(1ll * (i - 1) * f[i - 2][j][r] % mod)) % mod;
        if (j >= 1)
          f[i][j][r] =
              (f[i][j][r] + (int)(1ll * j * f[i][j - 1][r] % mod)) % mod;
      }
    }
  }
  for (i = 1; i <= n; i++) {
    b[i] = b[i - 1];
    c[i] = c[i - 1];
    if (a[i] == 2) b[i]++;
    if (a[i] == 3) c[i]++;
  }
  for (i = 1; i <= n; i++) ans = (ans + func(i, n, 0)) % mod;
  printf("%d", ans);
}
