#include <bits/stdc++.h>
using namespace std;
int D[54];
int n;
const int mod = 1e9 + 7;
int dp[55][30][30][30][30];
long long int answer(int idx, int a, int b, int c, int d) {
  if (a < 0 or b < 0 or c < 0 or d < 0 or a > 25 or b > 25 or c > 25 or d > 25)
    return 0;
  if (idx == n - 1) {
    return d == 1 and c == 0 and a == 0 and b == D[idx] - 1;
  }
  if (dp[idx][a][b][c][d] != dp[0][0][0][0][0]) return dp[idx][a][b][c][d];
  long long int ans = 0;
  if (D[idx] == 2) {
    ans += 1LL * answer(idx + 1, a, b + 1, c, d - 1) * d;
    ans += 1LL * answer(idx + 1, a, b - 1, c, d - 1) * b * d;
    ans += 1LL * answer(idx + 1, a - 1, b + 1, c, d - 1) * a * d;
    ans += 1LL * answer(idx + 1, a, b + 1, c - 1, d + 1) * c;
    ans += 1LL * answer(idx + 1, a, b - 1, c - 1, d + 1) * c * b;
    ans += 1LL * answer(idx + 1, a - 1, b + 1, c - 1, d + 1) * c * a;
    if (c == 0 and d == 0) {
      ans += 1LL * answer(idx + 1, 0, 1, a, b - 1) * b;
      ans += 1LL * answer(idx + 1, 0, 1, a - 1, b + 1) * a;
    }
  } else {
    ans += 1LL * answer(idx + 1, a + 1, b, c, d - 1) * d;
    ans += 1LL * answer(idx + 1, a, b, c, d - 1) * d * b;
    ans += 1LL * answer(idx + 1, a - 1, b + 2, c, d - 1) * d * a;
    ans += 1LL * answer(idx + 1, a, b - 2, c, d - 1) * d * (b * (b - 1)) / 2;
    ans +=
        1LL * answer(idx + 1, a - 2, b + 2, c, d - 1) * d * (a * (a - 1)) / 2;
    ans += 1LL * answer(idx + 1, a - 1, b, c, d - 1) * d * a * b;
    ans += 1LL * answer(idx + 1, a + 1, b, c - 1, d + 1) * c;
    ans += 1LL * answer(idx + 1, a, b, c - 1, d + 1) * c * b;
    ans += 1LL * answer(idx + 1, a - 1, b + 2, c - 1, d + 1) * c * a;
    ans +=
        1LL * answer(idx + 1, a, b - 2, c - 1, d + 1) * c * (b * (b - 1)) / 2;
    ans += 1LL * answer(idx + 1, a - 2, b + 2, c - 1, d + 1) * c *
           (a * (a - 1)) / 2;
    ans += 1LL * answer(idx + 1, a - 1, b, c - 1, d + 1) * c * a * b;
    if (c == 0 and d == 0) {
      ans += 1LL * answer(idx + 1, 1, 0, a, b - 1) * b;
      ans += 1LL * answer(idx + 1, 1, 0, a - 1, b + 1) * a;
    }
  }
  ans %= mod;
  dp[idx][a][b][c][d] = ans;
  return ans;
}
int main() {
  memset(dp, -1, sizeof dp);
  cin >> n;
  for (int i = 0; i < n; i++) scanf("%d", &D[i]);
  if (D[0] == 2 and D[1] == 2)
    cout << answer(2, 0, 1, 0, 1);
  else if (D[0] == 3 and D[1] == 2)
    cout << answer(2, 0, 1, 1, 0);
  else if (D[0] == 2 and D[1] == 3)
    cout << answer(2, 1, 0, 0, 1);
  else
    cout << answer(2, 1, 0, 1, 0);
}
