#include <bits/stdc++.h>
using namespace std;
int n, deg[51];
long long dp[2][51][51][51][51];
inline void add(long long &a, long long b) { a += b; }
void transition3(int b, int p1, int p2, int c1, int c2) {
  long long from = dp[b][p1][p2][c1][c2] % 1000000007;
  b ^= 1;
  if (p1 > 0) add(dp[b][p1 - 1][p2][c1][c2 + 1], from * p1);
  if (p2 > 0) add(dp[b][p1 + 1][p2 - 1][c1][c2 + 1], from * p2);
  if (p1 > 0 && c1 > 0) add(dp[b][p1 - 1][p2][c1 - 1 + 1][c2], from * p1 * c1);
  if (p2 > 0 && c1 > 0)
    add(dp[b][p1 + 1][p2 - 1][c1 - 1 + 1][c2], from * p2 * c1);
  if (p1 > 0 && c2 > 0)
    add(dp[b][p1 - 1][p2][c1 + 1 + 1][c2 - 1], from * p1 * c2);
  if (p2 > 0 && c2 > 0)
    add(dp[b][p1 + 1][p2 - 1][c1 + 1 + 1][c2 - 1], from * p2 * c2);
  if (p1 > 0 && c1 > 1)
    add(dp[b][p1 - 1][p2][c1 - 2][c2], from * p1 * c1 * (c1 - 1) / 2);
  if (p2 > 0 && c1 > 1)
    add(dp[b][p1 + 1][p2 - 1][c1 - 2][c2], from * p2 * c1 * (c1 - 1) / 2);
  if (p1 > 0 && c2 > 1)
    add(dp[b][p1 - 1][p2][c1 + 2][c2 - 2], from * p1 * c2 * (c2 - 1) / 2);
  if (p2 > 0 && c2 > 1)
    add(dp[b][p1 + 1][p2 - 1][c1 + 2][c2 - 2], from * p2 * c2 * (c2 - 1) / 2);
  if (p1 > 0 && c1 > 0 && c2 > 0)
    add(dp[b][p1 - 1][p2][c1 - 1 + 1][c2 - 1], from * p1 * c1 * c2);
  if (p2 > 0 && c1 > 0 && c2 > 0)
    add(dp[b][p1 + 1][p2 - 1][c1 - 1 + 1][c2 - 1], from * p2 * c1 * c2);
  if (p1 == 0 && p2 == 0 && c1 > 0) add(dp[b][c1 - 1][c2][0][1], from * c1);
  if (p1 == 0 && p2 == 0 && c2 > 0) add(dp[b][c1 + 1][c2 - 1][0][1], from * c2);
}
void transition2(int b, int p1, int p2, int c1, int c2) {
  long long from = dp[b][p1][p2][c1][c2] % 1000000007;
  b ^= 1;
  if (p1 > 0) add(dp[b][p1 - 1][p2][c1 + 1][c2], from * p1);
  if (p2 > 0) add(dp[b][p1 + 1][p2 - 1][c1 + 1][c2], from * p2);
  if (p1 > 0 && c1 > 0) add(dp[b][p1 - 1][p2][c1 - 1][c2], from * p1 * c1);
  if (p2 > 0 && c1 > 0) add(dp[b][p1 + 1][p2 - 1][c1 - 1][c2], from * p2 * c1);
  if (p1 > 0 && c2 > 0) add(dp[b][p1 - 1][p2][c1 + 1][c2 - 1], from * p1 * c2);
  if (p2 > 0 && c2 > 0)
    add(dp[b][p1 + 1][p2 - 1][c1 + 1][c2 - 1], from * p2 * c2);
  if (p1 == 0 && p2 == 0 && c1 > 0) add(dp[b][c1 - 1][c2][1][0], from * c1);
  if (p1 == 0 && p2 == 0 && c2 > 0) add(dp[b][c1 + 1][c2 - 1][1][0], from * c2);
}
void solveDP() {
  int ip1 = 0, ip2 = 0, ic1 = 0, ic2 = 0;
  if (deg[1] == 3 && deg[2] == 3) ip2 = 1, ic2 = 1;
  if (deg[1] == 3 && deg[2] == 2) ip2 = 1, ic1 = 1;
  if (deg[1] == 2 && deg[2] == 3) ip1 = 1, ic2 = 1;
  if (deg[1] == 2 && deg[2] == 2) ip1 = 1, ic1 = 1;
  dp[0][ip1][ip2][ic1][ic2] = 1;
  for (int v = 2; v <= n - 1; ++v) {
    int b = (v & 1);
    for (int p1 = 0; p1 <= v; ++p1) {
      for (int p2 = 0; p1 + p2 <= v; ++p2) {
        for (int c1 = 0; p1 + p2 + c1 <= v; ++c1) {
          for (int c2 = 0; p1 + p2 + c1 + c2 <= v; ++c2) {
            dp[b ^ 1][p1][p2][c1][c2] = 0;
          }
        }
      }
    }
    for (int p1 = 0; p1 <= v; ++p1) {
      for (int p2 = 0; p1 + p2 <= v; ++p2) {
        for (int c1 = 0; p1 + p2 + c1 <= v; ++c1) {
          for (int c2 = 0; p1 + p2 + c1 + c2 <= v; ++c2) {
            if (deg[v + 1] == 3)
              transition3(b, p1, p2, c1, c2);
            else
              transition2(b, p1, p2, c1, c2);
          }
        }
      }
    }
  }
  cout << dp[(n & 1)][0][0][0][0] % 1000000007;
}
void solve() {
  cin >> n;
  for (int i = 1; i <= (n); ++i) cin >> deg[i];
  solveDP();
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  solve();
  return 0;
}
