#include <bits/stdc++.h>
using namespace std;
const long long N = 51, mod = 1e9 + 7;
long long f[N][N], g[N][N][N], d[N], n, C[N][N], fact[N];
int main() {
  long long i, j, k, s1, s2;
  scanf("%lld", &n);
  for (i = 1; i <= n; i++) scanf("%lld", &d[i]);
  g[0][0][0] = 1;
  C[0][0] = 1;
  for (i = 1; i <= n; i++)
    for (j = 0; j <= i; j++)
      C[i][j] = (C[i - 1][j] + (j != 0 ? C[i - 1][j - 1] : 0)) % mod;
  fact[0] = fact[1] = fact[2] = 1;
  for (i = 3; i <= n; i++) fact[i] = (fact[i - 1] * i) % mod;
  for (i = 0; i <= n; i++) {
    for (j = 0; i + j <= n; j++) {
      if (i == 0) {
        if (j > 0)
          for (k = 2; k < j; k++)
            (g[0][0][j] +=
             (g[0][0][j - k - 1] * C[j - 1][k]) % mod * fact[k]) %= mod;
      } else
        g[0][i][j] = ((i >= 2 ? g[0][i - 2][j] * (i - 1) : 0) % mod +
                      (j >= 1 ? g[0][i][j - 1] * j : 0)) %
                     mod;
    }
  }
  for (i = 1; i < n; i++)
    for (j = 0; j <= n; j++)
      for (k = 0; k <= n; k++)
        g[i][j][k] =
            (g[i - 1][j - 1][k] * j + g[i - 1][j + 1][k - 1] * k) % mod;
  f[d[1] + 1][d[1]] = 1;
  for (i = d[1] + 2; i <= n; i++) {
    for (j = 1; j < i - d[1]; j++) {
      s1 = s2 = 0;
      for (k = 1; k < i - j; k++) {
        if (d[i - j - k + 1] == 2)
          s1++;
        else
          s2++;
        (f[i][j] += f[i - j][k] * g[j][s1][s2]) %= mod;
      }
    }
  }
  long long ans = 0;
  s1 = s2 = 0;
  for (i = 1; i < n; i++) {
    if (d[n - i + 1] == 2)
      s1++;
    else
      s2++;
    (ans += f[n][i] * g[0][s1][s2]) %= mod;
  }
  cout << ans << endl;
  return ~~(0 - 0);
}
