#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
inline int read() {
  int sum = 0, t = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') t = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    sum = sum * 10 + ch - '0';
    ch = getchar();
  }
  return sum * t;
}
int n, d[55], S[55];
int f[55][55][55], g[55][55];
void add(int &x, int y) {
  x += y;
  if (x >= mod) x -= mod;
}
int main() {
  n = read();
  for (int i = 1; i <= n; i++) S[i] = S[i - 1] + (d[i] = read());
  f[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) {
            int &res = f[c0][c1][c2];
            if (c0 > 1)
              add(res, 1LL * f[c0 - 2][c1][c2 - 1] * (c0 * (c0 - 1) / 2) % mod);
            if (c2 > 1 && c0 > 0)
              add(res, 1LL * f[c0 - 1][c1 + 1][c2 - 2] * (c2 - 1) * c0 % mod);
            if (c2 > 2)
              add(res, 1LL * f[c0][c1 + 2][c2 - 3] * ((c2 - 1) * (c2 - 2) / 2) %
                           mod);
            if (c2 > 1 && c1 > 0)
              add(res, 1LL * f[c0][c1][c2 - 2] * c1 * (c2 - 1) % mod);
            if (c1 > 0 && c0 > 0)
              add(res, 1LL * f[c0 - 1][c1 - 1][c2 - 1] * c1 * c0 % mod);
            if (c1 > 1)
              add(res, 1LL * f[c0][c1 - 2][c2 - 1] * (c1 * (c1 - 1) / 2) % mod);
          } else {
            int &res = f[c0][c1][c2];
            if (c0 > 0) add(res, 1LL * f[c0 - 1][c1 - 1][c2] * c0 % mod);
            if (c1 > 1) add(res, 1LL * f[c0][c1 - 2][c2] * (c1 - 1) % mod);
          }
        }
  g[n + 1][n] = 1;
  for (int l = n; l > 1; l--)
    for (int r = l; r <= n; r++) {
      int cnt2 = S[r] - S[l - 1] - (r - l + 1) * 2;
      int cnt1 = r - l + 1 - cnt2;
      for (int nxt = 0; nxt <= 2 * cnt2 + cnt1 && r + nxt <= n; nxt++)
        add(g[l][r], 1LL * g[r + 1][r + nxt] * f[nxt][cnt1][cnt2] % mod);
    }
  if (d[1] + 1 > n) return puts("0"), 0;
  printf("%d\n", g[2][d[1] + 1]);
}
