#include <bits/stdc++.h>
using namespace std;
long long n, a[64], mod = 1000000007;
long long memgc[64][64];
long long gc(long long c1, long long c2) {
  if (c1 == 0 && c2 == 0) {
    return 1;
  }
  if (memgc[c1][c2]) {
    return memgc[c1][c2] - 1;
  }
  long long ret = 0;
  if (c1) {
    ret += gc(c1 - 1, c2) * c1;
  }
  if (c2) {
    ret += gc(c1 + 1, c2 - 1) * c2;
  }
  memgc[c1][c2] = ret % mod + 1;
  return ret % mod;
}
long long memgn[64][64];
long long gn(long long c1, long long c2) {
  if (c1 < 0 || c2 < 0) {
    return 0;
  }
  if (c1 == 0 && c2 == 0) {
    return 1;
  }
  if (memgn[c1][c2]) {
    return memgn[c1][c2] - 1;
  }
  long long ret = 0;
  if (c1 == 0) {
    ret += gn(2, c2 - 3) * (c2 - 1) * (c2 - 2) / 2;
  } else {
    ret += gn(c1 - 2, c2) * (c1 - 1);
    ret += gn(c1, c2 - 1) * (c2);
  }
  memgn[c1][c2] = ret % mod + 1;
  return ret % mod;
}
long long memcomb[64][64];
long long comb(int k, int n) {
  if (k == 0) {
    return 1;
  }
  if (k == n) {
    return 1;
  }
  if (memcomb[k][n]) {
    return memcomb[k][n] - 1;
  }
  memcomb[k][n] = (comb(k - 1, n - 1) + comb(k, n - 1)) % mod + 1;
  return (comb(k - 1, n - 1) + comb(k, n - 1)) % mod;
}
long long memans[68][68][68];
long long getAns(long long s, long long cnt1, long long cnt2) {
  if (s > n) {
    return 0;
  }
  if (s == n) {
    if (cnt1 == 0 && cnt2 == 0) {
      return 1;
    }
    return 0;
  }
  if (cnt1 == 0 && cnt2 == 0) {
    return 0;
  }
  if (memans[s][cnt1][cnt2]) {
    return memans[s][cnt1][cnt2] - 1;
  }
  long long cc1 = cnt1, cc2 = cnt2;
  long long f = s + cnt1 + 2 * cnt2;
  long long cntCrrRow = gc(cnt1, cnt2);
  cnt1 = 0;
  cnt2 = 0;
  for (long long i = s; i < f; i++) {
    if (a[i] == 2) {
      cnt1++;
    } else {
      cnt2++;
    }
  }
  long long wNxtRow = 0;
  for (long long n1 = 0; n1 <= cnt1; n1++) {
    for (long long n2 = 0; n2 <= cnt2; n2++) {
      for (long long n3 = 0; n3 + n2 <= cnt2; n3++) {
        wNxtRow += gn(n1 + n3, n2) * comb(n1, cnt1) % mod * comb(n2, cnt2) %
                   mod * comb(n3, cnt2 - n2) % mod *
                   getAns(f, cnt1 - n1 + n3, cnt2 - n2 - n3) % mod;
        wNxtRow %= mod;
      }
    }
  }
  memans[s][cc1][cc2] = wNxtRow * cntCrrRow % mod + 1;
  return wNxtRow * cntCrrRow % mod;
}
int main() {
  cin >> n;
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
  }
  long long ff = 2;
  if (a[0] == 3) {
    ff = 6;
  }
  long long c = getAns(1, a[0], 0);
  while (c % ff) {
    c += mod;
  }
  cout << c / ff % mod << "\n";
  return 0;
}
