#include <bits/stdc++.h>
using namespace std;
const int mo = int(1e9 + 7);
int n, d[55], f[55][55], g[55][55][55], ans;
void work() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &d[i]);
  g[0][0][0] = 1;
  for (int i = 2; i <= n; i += 2)
    g[i][0][0] = 1LL * (i - 1) * g[i - 2][0][0] % mo;
  for (int j = 1; j <= n; j++)
    for (int i = 0; i + j <= n; i++) {
      if (i > 1)
        g[i][j][0] =
            (g[i][j][0] + 1LL * i * (i - 1) / 2 * g[i - 2][j - 1][0]) % mo;
      if ((i) && (j > 1))
        g[i][j][0] = (g[i][j][0] + 1LL * i * (j - 1) * g[i][j - 2][0]) % mo;
      if (j > 2)
        g[i][j][0] =
            (g[i][j][0] + 1LL * (j - 1) * (j - 2) / 2 * g[i + 2][j - 3][0]) %
            mo;
    }
  for (int k = 1; k <= n; k++)
    for (int j = 0; j + k <= n; j++)
      for (int i = 0; i + j + k <= n; i++)
        g[i][j][k] =
            (1LL * i * g[i - 1][j][k - 1] + 1LL * j * g[i + 1][j - 1][k - 1]) %
            mo;
  f[2][1 + d[1]] = 1;
  for (int i = 2, a, b; i <= n; i++) {
    a = b = 0;
    for (int j = i; j <= n; j++) {
      (d[j] == 2 ? a : b)++;
      for (int k = j + 1; k <= n; k++)
        f[j + 1][k] = (f[j + 1][k] + 1LL * g[a][b][k - j] * f[i][j]) % mo;
    }
  }
  for (int i = n, a = 0, b = 0; i; i--) {
    (d[i] == 2 ? a : b)++;
    ans = (ans + 1LL * g[a][b][0] * f[i][n]) % mo;
  }
  printf("%d", ans);
}
int main() {
  work();
  return 0;
}
