#include <bits/stdc++.h>
using namespace std;
int i, j, k, m, n, t, s;
int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
int g[52][52][52], f[52][52], ans, d[52], fac[52], inv2, inv[52], l, s1, s2;
void add(int &x, int y) {
  x += y;
  if (x >= 1000000007) x -= 1000000007;
}
int qpow(int x, int y) {
  int ans = 1;
  while (y) {
    if (y & 1) ans = (long long)ans * x % 1000000007;
    x = (long long)x * x % 1000000007;
    y >>= 1;
  }
  return ans;
}
int C(int n, int m) {
  return (long long)fac[n] * inv[m] % 1000000007 * inv[n - m] % 1000000007;
}
int main() {
  n = read();
  for (i = 1; i <= n; i++) d[i] = read();
  f[d[1] + 1][d[1]] = 1;
  g[0][0][0] = 1;
  fac[0] = 1;
  inv2 = qpow(2, 1000000007 - 2);
  for (i = 1; i <= n; i++) fac[i] = (long long)fac[i - 1] * i % 1000000007;
  inv[n] = qpow(fac[n], 1000000007 - 2);
  for (i = n - 1; i >= 0; i--)
    inv[i] = (long long)inv[i + 1] * (i + 1) % 1000000007;
  for (i = 0; i <= n; i++)
    for (j = 0; j <= n - i; j++)
      if (!i) {
        for (k = 2; k < j; k++)
          add(g[0][0][j], (long long)g[0][0][j - k - 1] * C(j - 1, k) %
                              1000000007 * fac[k] % 1000000007 * inv2 %
                              1000000007);
      } else {
        if (i >= 2)
          add(g[0][i][j], (long long)g[0][i - 2][j] * (i - 1) % 1000000007);
        if (j >= 1) add(g[0][i][j], (long long)g[0][i][j - 1] * j % 1000000007);
      }
  for (i = 1; i < n; i++)
    for (l = 0; l < n - i; l++)
      for (j = 0; j <= l; j++) {
        k = l - j;
        if (j) add(g[i][j][k], (long long)g[i - 1][j - 1][k] * j % 1000000007);
        if (k)
          add(g[i][j][k], (long long)g[i - 1][j + 1][k - 1] * k % 1000000007);
      }
  for (i = d[1] + 2; i <= n; i++)
    for (j = 1; j <= i - d[1] - 1; j++) {
      s1 = 0;
      s2 = 0;
      for (k = 1; k < i - j; k++) {
        if (d[i - j - k + 1] == 2)
          s1++;
        else
          s2++;
        add(f[i][j], (long long)f[i - j][k] * g[j][s1][s2] % 1000000007);
      }
    }
  s1 = 0;
  s2 = 0;
  for (j = 1; j < n; j++) {
    if (d[n - j + 1] == 2)
      s1++;
    else
      s2++;
    add(ans, (long long)f[n][j] * g[0][s1][s2] % 1000000007);
  }
  printf("%d\n", ans);
}
