#include <bits/stdc++.h>
using namespace std;
const int MAXN = 54;
const int MOD = 1e9 + 7;
long long n, de[MAXN], dp[2][MAXN][MAXN][MAXN][MAXN], dim;
void add(long long& a, long long b) { a = (a + b) % MOD; }
long long get_(long long a, long long b, long long i, long long j) {
  long long ans = 1;
  if (a == 1) ans *= i;
  if (a == 2) ans *= i * (i - 1) / 2;
  if (a == 3) ans *= i * (i - 1) * (i - 2) / 6;
  if (b == 1) ans *= j;
  if (b == 2) ans *= j * (j - 1) / 2;
  if (b == 3) ans *= j * (j - 1) * (j - 2) / 6;
  return ans % MOD;
}
int main() {
  ios::sync_with_stdio(0);
  cin >> n;
  for (int i = 0; i < n; i++) cin >> de[i];
  dp[dim][de[0] == 2][de[0] == 3][de[1] == 2][de[1] == 3] = 1;
  for (int i = 2; i <= (n - 1); i++) {
    for (int a = 0; a <= (i); a++)
      for (int b = 0; (a + b) <= (i); b++)
        for (int c = 0; (a + b + c) <= (i); c++)
          for (int d = 0; (a + b + c + d) <= (i); d++) {
            long long me = dp[dim][a][b][c][d];
            if (a == 0 && b == 0) {
              int local = de[i];
              for (int aa = 0; aa <= local && aa < 2; aa++)
                for (int bb = 0; (aa + bb) <= local && bb < 2; bb++) {
                  if ((!aa && !bb) || (aa && bb)) continue;
                  if (c < aa || d < bb) continue;
                  long long go = me;
                  int local_ = local - aa - bb;
                  go *= get_(aa, bb, c, d);
                  add(dp[dim ^ 1][c - aa + bb][d - bb][local_ == 1]
                        [local_ == 2],
                      go);
                }
            }
            int local = de[i];
            for (int aa = 0; aa <= local && aa < 2; aa++)
              for (int bb = 0; (aa + bb) <= local && bb < 2; bb++)
                for (int cc = 0; (aa + bb + cc) <= local; cc++)
                  for (int dd = 0; (aa + bb + cc + dd) <= local; dd++) {
                    if ((!aa && !bb) || (aa && bb)) continue;
                    if (a < aa || b < bb || c < cc || d < dd) continue;
                    int local_ = local - aa - bb - cc - dd;
                    long long go = me;
                    go *= get_(aa, bb, a, b);
                    go *= get_(cc, dd, c, d);
                    add(dp[dim ^ 1][a - aa + bb][b - bb]
                          [c - cc + dd + (local_ == 1)][d - dd + (local_ == 2)],
                        go);
                  }
          }
    dim ^= 1;
    memset(dp[dim ^ 1], 0, sizeof(dp[dim ^ 1]));
  }
  cout << dp[dim][0][0][0][0] << endl;
  return 0;
}
