#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:64000000")
const int MAXN = 10;
int n;
int a[MAXN];
int e[MAXN];
int b[MAXN];
int c[MAXN];
int pos[MAXN];
int cnt2;
inline int check() {
  memcpy(e, a, sizeof e);
  for (int i = 0; i < n; ++i) {
    c[i] = i;
    pos[c[i]] = i;
  }
  for (int it = 0; it < n; ++it) {
    char fnd = 0;
    for (int i = 0; i < n; ++i) {
      if (b[i] == c[i]) continue;
      if (!e[i]) return 0;
      if (e[i] == 1) {
        int ind1 = i;
        int ind2 = pos[b[i]];
        if (!e[ind2]) return 0;
        if (e[ind2] != 2) continue;
        fnd = 1;
        --e[ind1];
        --e[ind2];
        swap(pos[c[ind1]], pos[c[ind2]]);
        swap(c[ind1], c[ind2]);
      }
    }
    if (!fnd) break;
  }
  for (int i = 0; i < n; ++i) {
    if (b[i] == c[i]) continue;
    if (!e[i]) return 0;
    if (e[i] == 1) {
      int ind1 = i;
      int ind2 = pos[b[i]];
      if (!e[ind2]) return 0;
      --e[ind1];
      --e[ind2];
      swap(pos[c[ind1]], pos[c[ind2]]);
      swap(c[ind1], c[ind2]);
    }
  }
  return 1;
}
int main() {
  cnt2 = 0;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    if (a[i] == 2) ++cnt2;
    b[i] = i;
  }
  int res = 0;
  do {
    if (check()) ++res;
  } while (next_permutation(b, b + n));
  cout << res << endl;
  return 0;
}
