#include <bits/stdc++.h>
using namespace std;
static const int INF = 500000000;
template <class T>
void debug(T a, T b) {
  for (; a != b; ++a) cerr << *a << ' ';
  cerr << endl;
}
int n;
int one, two;
int ch[15], perm[15];
int main() {
  cin >> n;
  for (int i = 0; i < n; ++i) {
    int t;
    scanf("%d", &t);
    ch[i] = t;
    if (t == 1)
      ++one;
    else
      ++two;
  }
  for (int i = 0; i < n; ++i) perm[i] = i;
  int res = 0;
  do {
    int done[15] = {0};
    int fail = 0;
    for (int i = 0; i < n; ++i)
      if (!done[i]) {
        int ocnt = 0;
        if (ch[i] == 1) ++ocnt;
        done[i] = 1;
        int sz = 1;
        for (int j = perm[i]; j != i; j = perm[j]) {
          ++sz;
          done[j] = 1;
          if (ch[j] == 1) ++ocnt;
        }
        if (sz > 2 && ocnt > 2) fail = 1;
      }
    if (!fail) {
      ++res;
    }
  } while (next_permutation(perm, perm + n));
  printf("%d\n", res);
  return 0;
}
