#include <bits/stdc++.h>
using namespace std;
const int oo = 0x3f3f3f3f;
const int MAX_N = 505;
const int Mod = 1000000007;
int N, Capacities[MAX_N], P[MAX_N], Solution;
bool Used[MAX_N];
void Brute() {
  for (int i = 1; i <= N; ++i) P[i] = i;
  do {
    for (int i = 1; i <= N; ++i) Used[i] = false;
    bool valid = true;
    for (int i = 1; i <= N && valid; ++i) {
      if (Used[i]) continue;
      int length = 0, capacity = 0;
      for (int x = i; !Used[x]; x = P[x]) {
        Used[x] = true;
        if (Capacities[x] == 1) ++capacity;
        ++length;
      }
      if (capacity > 2) valid = false;
    }
    if (valid) ++Solution;
  } while (next_permutation(P + 1, P + N + 1));
}
void Read() {
  cin >> N;
  for (int i = 1; i <= N; ++i) cin >> Capacities[i];
}
void Print() { cout << Solution << "\n"; }
int main() {
  Read();
  Brute();
  Print();
  return 0;
}
