#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:36777216")
const double Pi = acos(-1.0);
using namespace std;
set<vector<int> > used;
map<pair<vector<int>, vector<int> >, int> usedd;
vector<int> a;
int n;
vector<int> b;
const int ans8[9] = {40320, 0, 40320, 0, 11760, 0, 3920, 0, 638};
const int ans10[11] = {3628800, 0, 3628800, 0, 1512000, 0,
                       383040,  0, 66060,   0, 9268};
const int ans9[10] = {362880, 0, 362880, 0, 151200, 0, 38304, 0, 6606, 0};
void solve(int n, int k) {
  if (usedd[make_pair(a, b)]) return;
  usedd[make_pair(a, b)] = 1;
  used.insert(a);
  used.insert(a);
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      if (b[i] && b[j]) {
        b[i]--;
        b[j]--;
        swap(a[i], a[j]);
        solve(n, k - 1);
        swap(a[i], a[j]);
        b[i]++;
        b[j]++;
      }
    }
  }
}
int fact(int x) {
  if (x == 0) return 1;
  return x * fact(x - 1);
}
int f(int n, int x) {
  if (n >= 5 && (x <= 2)) {
    return fact(n);
  }
  if (n > x) return (n)*f(n - 1, x);
  used.clear();
  a.resize(n);
  b.resize(n);
  for (int i = 0; i < n; i++) {
    a[i] = i;
  }
  int sum = 0;
  for (int i = 0; i < x; i++) {
    b[i] = 1;
    sum++;
  }
  for (int i = x; i < n; i++) {
    b[i] = 2;
    sum += 2;
  }
  solve(n, sum / 2);
  int ans = used.size();
  return ans;
}
int main() {
  cin >> n;
  int num = 0;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    if (x == 1) num++;
  }
  cout << f(n, num) << endl;
  return 0;
}
