#include <bits/stdc++.h>
using namespace std;
const int N = 1000;
const int MOD = 1000000007;
int n, x[N], ord[N], vst[N], ans, at[N], at2[N], tar[N], cnt[N];
void dfs(int step) {
  if (step > n) {
    for (int i = 1; i <= n; i++) ord[i] = i, at2[i] = i, cnt[i] = x[i];
    int ok = 0;
    for (int i = 1; i <= n; i++) {
      if (ord[i] == tar[i]) ok++;
    }
    while (ok < n) {
      int sign = 0;
      for (int i = 1; i <= n; i++) {
        if (ord[i] != tar[i] && cnt[i] == 1 && cnt[at2[tar[i]]] == 2) sign = 1;
      }
      for (int i = 1; i <= n; i++) {
        if (ord[i] != tar[i]) {
          int id1 = i;
          int id2 = at2[tar[i]];
          if (sign) {
            if (cnt[id1] == 2 || cnt[id2] == 1) continue;
          }
          if (!cnt[id1] || !cnt[id2]) {
            return;
          }
          swap(ord[id1], ord[id2]);
          cnt[id1]--;
          cnt[id2]--;
          swap(at2[ord[id1]], at2[ord[id2]]);
          ok++;
          if (ord[id2] == tar[id2]) ok++;
          break;
        }
      }
    }
    ans++;
    return;
  }
  for (int i = 1; i <= n; i++) {
    if (!vst[i]) {
      tar[step] = i;
      vst[i] = 1;
      at[i] = step;
      dfs(step + 1);
      vst[i] = 0;
    }
  }
}
int main(int argc, char** arigv) {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &x[i]);
    ord[i] = i;
  }
  dfs(1);
  printf("%d\n", ans);
  return 0;
}
