#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using D = double;
using uint = unsigned int;
template <typename T>
using pair2 = pair<T, T>;
const int maxn = 55;
const int MOD = 1000000007;
int ways[maxn][maxn][maxn];
int answer[maxn][maxn];
int n;
int d[maxn];
int sumd[maxn];
inline void add(int &a, ll b) { a = (a + b) % MOD; }
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", &d[i]);
  ways[0][0][0] = 1;
  for (int c0 = 0; c0 <= n; c0++) {
    for (int c2 = 0; c2 <= n; c2++) {
      for (int c1 = 0; c1 <= n; c1++)
        if (c1 + c2 > 0) {
          if (c2 > 0) {
            if (c0 > 1)
              add(ways[c0][c1][c2],
                  (ll)ways[c0 - 2][c1][c2 - 1] * (c0 * (c0 - 1) / 2));
            if (c2 > 1 && c0 > 0)
              add(ways[c0][c1][c2],
                  (ll)ways[c0 - 1][c1 + 1][c2 - 2] * (c2 - 1) * c0);
            if (c2 > 2)
              add(ways[c0][c1][c2],
                  (ll)ways[c0][c1 + 2][c2 - 3] * ((c2 - 1) * (c2 - 2) / 2));
            if (c1 > 0 && c2 > 1)
              add(ways[c0][c1][c2], (ll)ways[c0][c1][c2 - 2] * c1 * (c2 - 1));
            if (c1 > 0 && c0 > 0)
              add(ways[c0][c1][c2], (ll)ways[c0 - 1][c1 - 1][c2 - 1] * c1 * c0);
            if (c1 > 1)
              add(ways[c0][c1][c2],
                  (ll)ways[c0][c1 - 2][c2 - 1] * (c1 * (c1 - 1) / 2));
          } else {
            if (c0 > 0) add(ways[c0][c1][c2], ways[c0 - 1][c1 - 1][c2] * c0);
            if (c1 > 1)
              add(ways[c0][c1][c2], (ll)ways[c0][c1 - 2][c2] * (c1 - 1));
          }
        }
    }
  }
  for (int i = 0; i < n; i++) sumd[i + 1] = sumd[i] + d[i];
  answer[n][n - 1] = 1;
  for (int l = n - 1; l > 0; l--) {
    for (int r = l; r < n; r++) {
      int cnt2 = sumd[r + 1] - sumd[l] - 2 * (r - l + 1);
      int cnt1 = r - l + 1 - cnt2;
      for (int nextlvl = 0; nextlvl <= 2 * cnt2 + cnt1 && nextlvl <= n;
           nextlvl++) {
        int curways = ways[nextlvl][cnt1][cnt2];
        if (r + nextlvl < n) {
          add(answer[l][r], (ll)answer[r + 1][r + nextlvl] * curways);
        }
      }
    }
  }
  if (d[0] + 1 > n)
    cout << 0 << endl;
  else
    cout << answer[1][d[0]] << endl;
  return 0;
}
