#include <bits/stdc++.h>
using namespace std;
int N;
int D[51];
long long dp[51][25][25][25][25];
long long solve(int i, int a, int b, int c, int d) {
  if (a < 0 || b < 0 || c < 0 || d < 0 || a >= 25 || b >= 25 || c >= 25 ||
      d >= 25)
    return 0;
  if (i == N) {
    if (a == 0 && b == 1 && c == 0 && d == D[N] - 1) return 1;
    return 0;
  }
  if (dp[i][a][b][c][d] != -1) return dp[i][a][b][c][d];
  long long ans = 0;
  if (D[i] == 2) {
    ans += solve(i + 1, a - 1, b + 1, c, d - 1) * a * d % 1000000007;
    ans += solve(i + 1, a - 1, b + 1, c - 1, d + 1) * a * c % 1000000007;
    ans += solve(i + 1, a - 1, b + 1, c, d + 1) * a % 1000000007;
    ans += solve(i + 1, a, b - 1, c, d - 1) * b * d % 1000000007;
    ans += solve(i + 1, a, b - 1, c - 1, d + 1) * b * c % 1000000007;
    ans += solve(i + 1, a, b - 1, c, d + 1) * b % 1000000007;
    if (a + b == 0) {
      ans += solve(i + 1, c - 1, d + 1, 0, 1) * c % 1000000007;
      ans += solve(i + 1, c, d - 1, 0, 1) * d % 1000000007;
    }
  } else {
    ans += solve(i + 1, a - 1, b + 1, c - 2, d + 2) * a * c * (c - 1) / 2 %
           1000000007;
    ans += solve(i + 1, a - 1, b + 1, c - 1, d) * a * c * d % 1000000007;
    ans += solve(i + 1, a - 1, b + 1, c - 1, d + 2) * a * c % 1000000007;
    ans +=
        solve(i + 1, a - 1, b + 1, c, d - 2) * a * d * (d - 1) / 2 % 1000000007;
    ans += solve(i + 1, a - 1, b + 1, c, d) * a * d % 1000000007;
    ans += solve(i + 1, a - 1, b + 1, c + 1, d) * a % 1000000007;
    ans +=
        solve(i + 1, a, b - 1, c - 2, d + 2) * b * c * (c - 1) / 2 % 1000000007;
    ans += solve(i + 1, a, b - 1, c - 1, d) * b * c * d % 1000000007;
    ans += solve(i + 1, a, b - 1, c - 1, d + 2) * b * c % 1000000007;
    ans += solve(i + 1, a, b - 1, c, d - 2) * b * d * (d - 1) / 2 % 1000000007;
    ans += solve(i + 1, a, b - 1, c, d) * b * d % 1000000007;
    ans += solve(i + 1, a, b - 1, c + 1, d) * b % 1000000007;
    if (a + b == 0) {
      ans += solve(i + 1, c - 1, d + 1, 1, 0) * c % 1000000007;
      ans += solve(i + 1, c, d - 1, 1, 0) * d % 1000000007;
    }
  }
  return dp[i][a][b][c][d] = ans % 1000000007;
}
int main() {
  scanf("%d", &N);
  for (int i = 1; i <= N; i++) scanf("%d", &D[i]);
  memset(dp, -1, sizeof(dp));
  if (D[1] == 2 && D[2] == 2)
    printf("%lld\n", solve(3, 0, 1, 0, 1));
  else if (D[1] == 2 && D[2] == 3)
    printf("%lld\n", solve(3, 0, 1, 1, 0));
  else if (D[1] == 3 && D[2] == 2)
    printf("%lld\n", solve(3, 1, 0, 0, 1));
  else
    printf("%lld\n", solve(3, 1, 0, 1, 0));
  return 0;
}
