#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  long long x = 0, w = 0;
  char ch = getchar();
  while (!isdigit(ch)) w |= ch == '-', ch = getchar();
  while (isdigit(ch)) x = (x << 1) + (x << 3) + ch - '0', ch = getchar();
  return w ? -x : x;
}
inline long long ksm(long long x, long long y) {
  long long m = 1;
  while (y) {
    if (y & 1) m = (m * x) % 1000000007;
    x = (x * x) % 1000000007;
    y >>= 1;
  }
  return m;
}
long long n, d[100005], g[55][55][55], f[55][55], jc[55], inv[55], c[5], ans;
inline long long calc(long long x, long long y) {
  return jc[x] % 1000000007 * inv[y] % 1000000007 * inv[x - y] % 1000000007;
}
inline void pre() {
  g[0][0][0] = 1;
  for (int i = 0; i <= n; i++) {
    for (int j = 0; j <= n - i; j++) {
      if (i == j && i == 0) {
        continue;
      }
      if (i == 0) {
        for (int k = 2; k < j; k++) {
          g[0][i][j] =
              (g[0][i][j] + g[0][i][j - k - 1] * calc(j - 1, k) % 1000000007 *
                                jc[k] % 1000000007 * inv[2] % 1000000007) %
              1000000007;
        }
      } else {
        if (i >= 2)
          g[0][i][j] =
              (g[0][i][j] + g[0][i - 2][j] * (i - 1) % 1000000007) % 1000000007;
        if (j >= 1) {
          g[0][i][j] =
              (g[0][i][j] + g[0][i][j - 1] * j % 1000000007) % 1000000007;
        }
      }
    }
  }
  for (int i = 1; i < n; i++)
    for (int j = 1; j < n - i; j++)
      for (int k = 0; k <= j; k++) {
        int l = j - k;
        if (l >= 1)
          g[i][l][k] =
              (g[i][l][k] + g[i - 1][l - 1][k] * l % 1000000007) % 1000000007;
        if (k >= 1)
          g[i][l][k] = (g[i][l][k] + g[i - 1][l + 1][k - 1] * k % 1000000007) %
                       1000000007;
      }
}
int main() {
  n = read();
  jc[0] = inv[0] = jc[1] = 1;
  for (int i = 2; i <= n; i++) jc[i] = jc[i - 1] * i % 1000000007;
  inv[n] = ksm(jc[n], 1000000007 - 2) % 1000000007;
  for (int i = n - 1; i >= 1; i--) inv[i] = inv[i + 1] * (i + 1) % 1000000007;
  for (int i = 1; i <= n; i++) d[i] = read();
  pre();
  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++) {
      c[0] = c[1] = 0;
      for (int k = 1; k < i - j; k++) {
        c[d[i - j - k + 1] == 3]++;
        f[i][j] = (f[i][j] + f[i - j][k] * g[j][c[0]][c[1]] % 1000000007) %
                  1000000007;
      }
    }
  }
  c[0] = c[1] = 0;
  for (int i = 1; i < n; i++) {
    c[d[n - i + 1] == 3]++;
    ans = (ans + f[n][i] * g[0][c[0]][c[1]] % 1000000007) % 1000000007;
  }
  ans %= 1000000007;
  printf("%lld", ans);
  return 0;
}
