#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3fffffff;
const int SINF = 0x7fffffff;
const long long LINF = 0x3fffffffffffffff;
const long long SLINF = 0x7fffffffffffffff;
const int MAXN = 53;
const int MOD = 1e9 + 7;
const int REV2 = 5e8 + 4;
int n;
int d[MAXN];
int dp[MAXN][MAXN][MAXN][MAXN];
int dp2[MAXN][MAXN][MAXN];
int dp3[MAXN][MAXN];
int frac[MAXN];
void init();
void input();
void work();
void add(int &x, int y) {
  x += y;
  if (x >= MOD) x -= MOD;
}
int mul(int x, int y) { return (1LL * x * y) % MOD; }
int main() {
  init();
  input();
  work();
}
void init() {
  ios::sync_with_stdio(false);
  frac[0] = 1;
  for (int i = 1, _end = MAXN; i < _end; ++i) frac[i] = mul(frac[i - 1], i);
}
void input() {
  scanf("%d", &n);
  for (int i = 1, _end = n; i <= _end; ++i) scanf("%d", &d[i]);
}
void work() {
  int rem, tx;
  for (int i = 2, _end = n; i <= _end; ++i) {
    memset(dp, 0, sizeof(dp));
    dp[i - 1][0][0][0] = 1;
    for (int j = i, _end = n; j <= _end; ++j) {
      rem = d[j] - 1;
      for (int k = 0, _end = j - i; k <= _end; ++k) {
        for (int a = 0, _end = j - i - k; a <= _end; ++a) {
          for (int b = 0, _end = ((((j - i) << 1) < (n - j)) ? ((j - i) << 1)
                                                             : (n - j));
               b <= _end; ++b) {
            if (dp[j - 1][k][a][b]) {
              tx = dp[j - 1][k][a][b];
              if (rem == 1) {
                add(dp[j][k][a][b + 1], tx);
                add(dp[j][k + 1][a][b], tx);
                if (k) add(dp[j][k - 1][a][b], mul(tx, k));
                if (a) add(dp[j][k + 1][a - 1][b], mul(tx, a));
              } else {
                add(dp[j][k][a][b + 2], mul(tx, REV2));
                add(dp[j][k + 1][a][b + 1], tx);
                add(dp[j][k][a + 1][b], tx);
                if (k)
                  add(dp[j][k - 1][a][b + 1], mul(tx, k)),
                      add(dp[j][k][a][b], mul(tx, k));
                if (a)
                  add(dp[j][k + 1][a - 1][b + 1], mul(tx, a)),
                      add(dp[j][k + 2][a - 1][b], mul(tx, a));
                if (a >= 2)
                  add(dp[j][k + 2][a - 2][b],
                      mul(tx, mul(mul(a, a - 1), REV2)));
                if (a && k) add(dp[j][k][a - 1][b], mul(mul(tx, k), a));
                if (k >= 2)
                  add(dp[j][k - 2][a][b], mul(tx, mul(mul(k, k - 1), REV2)));
              }
            }
          }
        }
      }
      for (int b = 0,
               _end = ((((j - i + 1) << 1) < (n - j + 1)) ? ((j - i + 1) << 1)
                                                          : (n - j + 1));
           b <= _end; ++b) {
        dp2[i][j][b] = mul(dp[j][0][0][b], frac[b]);
      }
    }
  }
  for (int i = 1, _end = n; i <= _end; ++i) dp3[i][n - i + 1] = dp2[i][n][0];
  for (int i = n, _end = 2; i >= _end; --i) {
    for (int j = 1, _end = n - i + 1; j <= _end; ++j) {
      tx = i + j;
      for (int k = 1, _end = n - tx + 1; k <= _end; ++k) {
        add(dp3[i][j], mul(dp3[tx][k], dp2[i][tx - 1][k]));
      }
    }
  }
  printf("%d\n", dp3[2][d[1]]);
}
