#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
int dp[55][55][55], g[55][55];
int n, d[55], gas[55];
long long piece(int a, int b, int nxt) {
  if (a < 0 || b < 0 || nxt < 0) return 0;
  if (~dp[a][b][nxt]) return dp[a][b][nxt];
  if (nxt)
    return dp[a][b][nxt] = (a * piece(a - 1, b, nxt - 1) +
                            b * piece(a + 1, b - 1, nxt - 1)) %
                           mod;
  if (a)
    return dp[a][b][nxt] =
               ((a - 1) * piece(a - 2, b, nxt) + b * piece(a, b - 1, nxt)) %
               mod;
  if (!b) return dp[a][b][nxt] = 1;
  return dp[a][b][nxt] =
             ((b - 1) * (b - 2) / 2 * piece(a + 2, b - 3, nxt)) % mod;
}
long long query(int p, int nxt) {
  if (p + nxt > n) return 0;
  if (p == n) return nxt == 0;
  if (nxt == 0) return 0;
  int u = gas[p + nxt] - gas[p];
  if (~g[p][nxt]) return g[p][nxt];
  g[p][nxt] = 0;
  for (int i = 0; i <= n - p - nxt; i++) {
    g[p][nxt] = (g[p][nxt] + piece(u, nxt - u, i) * query(p + nxt, i)) % mod;
  }
  return g[p][nxt];
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", d + i);
    gas[i] = gas[i - 1] + (d[i] == 2);
  }
  memset(dp, -1, sizeof dp);
  memset(g, -1, sizeof g);
  cout << query(1, d[1]) << endl;
}
