#include <bits/stdc++.h>
using namespace std;
int a[100], n;
bool can(int *id) {
  bool vst[20];
  int i, x, cnt, p;
  memset(vst, 0, sizeof(vst));
  for (i = 0; i < n; i++) {
    if (id[i] != i && a[i] == 0) return 0;
    if (vst[i]) continue;
    x = i;
    cnt = 0;
    do {
      vst[x] = 1;
      if (a[x] < 2) {
        if (cnt == 2) return 0;
        cnt++;
      }
      x = id[x];
    } while (x != i);
  }
  return 1;
}
int main() {
  int id[20], i, res;
  scanf("%d", &n);
  for (i = 0; i < n; i++) scanf("%d", a + i);
  for (i = 0; i < n; i++) id[i] = i;
  res = 0;
  do {
    if (can(id)) res++;
  } while (next_permutation(id, id + n));
  printf("%d\n", res);
  return 0;
}
