#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
const long long int mod = 1e9 + 7;
const long long int mod1 = 998244353;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const long long int N = 52;
long long int dp[2][N][N][N][N];
long long int a[N];
long long int C(long long int n, long long int p) {
  if (n < p) return 0;
  long long int ans = 1;
  for (long long int i = n - p + 1; i <= n; i++) ans *= i;
  for (long long int i = 1; i <= p; i++) ans /= i;
  return ans;
}
void solve() {
  long long int n;
  cin >> n;
  for (long long int i = 1; i <= n; i++) cin >> a[i];
  dp[0][(a[1] == 2)][(a[1] == 3)][(a[2] == 2)][(a[2] == 3)] = 1;
  for (long long int i = 2; i <= n - 1; i++) {
    long long int l1 = (i & 1);
    long long int l2 = (l1 ^ 1);
    for (long long int p = 0; p <= n; p++)
      for (long long int q = 0; q <= n; q++)
        for (long long int p1 = 0; p1 <= n; p1++)
          for (long long int q1 = 0; q1 <= n; q1++) dp[l2][p][q][p1][q1] = 0;
    for (long long int p = 0; p <= n; p++) {
      for (long long int q = 0; q <= n; q++) {
        for (long long int p1 = 0; p1 <= n; p1++) {
          for (long long int q1 = 0; q1 <= n; q1++) {
            long long int cur = dp[l1][p][q][p1][q1];
            if (!cur) continue;
            for (long long int x1 = 0; x1 <= 3; x1++) {
              for (long long int x2 = 0; x2 <= 3; x2++) {
                if (x1 + x2 != 1) continue;
                if (x1 + x2 > a[i + 1]) continue;
                for (long long int x3 = 0; x3 <= 2; x3++) {
                  if (x1 + x2 + x3 > a[i + 1]) continue;
                  for (long long int x4 = 0; x4 <= 2; x4++) {
                    long long int x5 = a[i + 1] - x1 - x2 - x3 - x4;
                    if (x5 < 0) continue;
                    if (x1 > p || x2 > q || x3 > p1 || x4 > q1) continue;
                    long long int lol = (C(p, x1) * C(q, x2)) % mod;
                    lol = (lol * C(p1, x3)) % mod;
                    lol = (lol * C(q1, x4)) % mod;
                    dp[l2][p - x1 + x2][q - x2][p1 - x3 + x4 + (x5 == 1)]
                      [q1 - x4 + (x5 == 2)] += (lol * cur) % mod;
                    dp[l2][p - x1 + x2][q - x2][p1 - x3 + x4 + (x5 == 1)]
                      [q1 - x4 + (x5 == 2)] %= mod;
                  }
                }
              }
            }
            if (p == 0 && q == 0) {
              for (long long int x1 = 0; x1 <= 3; x1++) {
                for (long long int x2 = 0; x2 <= 3; x2++) {
                  if (x1 + x2 != 1) continue;
                  long long int x3 = a[i + 1] - x1 - x2;
                  if (x3 < 0) continue;
                  if (x1 > p1 || x2 > q1) continue;
                  long long int lol = (C(p1, x1) * C(q1, x2)) % mod;
                  dp[l2][p1 - x1 + x2][q1 - x2][x3 == 1][x3 == 2] +=
                      (lol * cur) % mod;
                  dp[l2][p1 - x1 + x2][q1 - x2][x3 == 1][x3 == 2] %= mod;
                }
              }
            }
          }
        }
      }
    }
  }
  cout << dp[(n & 1)][0][0][0][0];
}
signed main() {
  ios ::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  clock_t clk = clock();
  long long int t;
  t = 1;
  for (long long int i = 1; i <= t; i++) {
    solve();
  }
  cerr << '\n'
       << setprecision(10) << fixed << (double)(clock() - clk) / CLOCKS_PER_SEC;
  return 0;
}
