#include <bits/stdc++.h>
using namespace std;
const int MX = 55;
const int inf = 0x3f3f3f3f;
const long long INF = 0x3f3f3f3f3f3f3f3f;
const long long mod = 1e9 + 7;
int d[MX], n;
long long f[MX][MX], g[MX][MX][MX], a[MX], c[MX][MX];
void init() {
  a[0] = a[1] = 0;
  a[2] = a[3] = 1;
  for (int i = 4; i <= n; i++) a[i] = a[i - 1] * (i - 1) % mod;
  c[0][0] = 1;
  for (int i = 1; i <= n; i++) {
    c[i][0] = 1;
    for (int j = 1; j <= i; j++)
      c[i][j] = (c[i - 1][j - 1] + c[i - 1][j]) % mod;
  }
  g[0][0][0] = 1;
  for (int j = 0; j <= n; j++)
    for (int k = 0; k <= n - j; k++) {
      if (j == 0 && k > 0) {
        for (int l = 2; l < k; l++)
          (g[0][j][k] += g[0][j][k - 1 - l] * c[k - 1][l] % mod * a[l + 1]) %=
              mod;
        ;
      } else {
        if (j >= 2) (g[0][j][k] += g[0][j - 2][k] * (j - 1)) %= mod;
        ;
        if (k >= 1) (g[0][j][k] += g[0][j][k - 1] * k) %= mod;
        ;
      }
    }
  for (int i = 1; i <= n; i++)
    for (int j = 0; j <= n - i; j++)
      for (int k = 0; k <= n - i - j; k++) {
        if (j >= 1) (g[i][j][k] += g[i - 1][j - 1][k] * j) %= mod;
        ;
        if (k >= 1) (g[i][j][k] += g[i - 1][j + 1][k - 1] * k) %= mod;
        ;
      }
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &d[i]);
  init();
  f[d[1] + 1][d[1]] = 1;
  for (int i = d[1] + 2; i <= n; i++) {
    for (int j = 1; j <= i - d[1] - 1; j++) {
      int c1 = 0, c2 = 0;
      for (int k = 1; k <= i - j; k++) {
        if (d[i - j - k + 1] == 2)
          c1++;
        else
          c2++;
        (f[i][j] += f[i - j][k] * g[j][c1][c2]) %= mod;
        ;
      }
    }
  }
  long long ans = 0;
  int c1 = 0, c2 = 0;
  for (int j = 1; j < n; j++) {
    if (d[n - j + 1] == 2)
      c1++;
    else
      c2++;
    (ans += f[n][j] * g[0][c1][c2]) %= mod;
    ;
  }
  printf("%I64d\n", ans);
  return 0;
}
