#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:256000000")
const long double PI = 3.1415926535897932384626433832795;
using namespace std;
int aabs(int a) {
  if (a < 0) return -a;
  return a;
}
int main() {
  cout.setf(ios::fixed);
  cout.precision(6);
  int n;
  cin >> n;
  int aa[13];
  int pp[13];
  int cnt = 1;
  for (int i = 0; i < n; i++) {
    cin >> aa[i];
    pp[i] = i;
    cnt *= i + 1;
  }
  int ans = 0;
  for (int z = 0; z < cnt; z++) {
    int p[13];
    int a[13];
    for (int i = 0; i < n; i++) {
      p[i] = pp[i];
      a[i] = aa[i];
    }
    bool isA = true;
    while (true) {
      bool pp = 0;
      for (int i = 0; i < n; i++) {
        int j = p[i];
        if (i != j) {
          if (a[j] == 1 && !(a[i] == 1 && p[j] != i)) {
            pp = 1;
            if (a[i] > 0) {
              swap(p[i], p[j]);
              a[i]--;
              a[j]--;
            } else {
              isA = false;
              break;
            }
          }
        }
      }
      if (!pp || !isA) break;
    }
    for (int i = 0; i < n; i++) {
      if (a[i] < 2 && p[i] != i) {
        isA = false;
        break;
      }
    }
    if (isA) ans++;
    next_permutation(pp, pp + n);
  }
  cout << ans;
  return 0;
}
