#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:20000000")
string problem_name = "a";
void init() { freopen((problem_name + ".in").c_str(), "rt", stdin); }
long long ht[10000000];
void add(long long val) {
  int pos = val & (8388607);
  while (ht[pos] && ht[pos] != val) pos++;
  ht[pos] = val;
}
int get(long long val) {
  int pos = val & (8388607);
  while (ht[pos] && ht[pos] != val) pos++;
  return ht[pos] == val;
}
int c[21];
char u[4000000];
int ms[21];
int val[21];
int res = 0;
int fct[21];
int n;
set<long long> us;
int eight[] = {764, 1856, 4256, 8736, 16800, 26880, 40320, 40320, 40320};
int nine[] = {2620,   6876,   16704,  38304,  78624, 151200,
              241920, 362880, 362880, 362880, 362880};
int ten[] = {9496,    26200,   68760,   167040,  383040, 786240,
             1512000, 2419200, 3628800, 3628800, 3628800};
int calc() {
  long long res = 0;
  for (int i = 0; i < n; i++) {
    res = res * 10 + (val[i] + 1);
  }
  if (get(res)) return 0;
  add(res);
  return 1;
}
void go() {
  res += calc();
  for (int i = 0; i < n; i++)
    if (ms[i]) {
      for (int j = i + 1; j < n; j++)
        if (ms[j]) {
          ms[i]--;
          ms[j]--;
          swap(val[i], val[j]);
          go();
          swap(val[i], val[j]);
          ms[i]++;
          ms[j]++;
        }
    }
}
int main() {
  scanf("%d", &n);
  int col = 0;
  for (int i = 0; i < n; i++) {
    int t;
    scanf("%d", &t);
    if (t == 2) col++;
  }
  if (n == 8) cout << eight[col];
  if (n == 9) cout << nine[col];
  if (n == 10) cout << ten[col];
  if (n >= 8) return 0;
  for (int i = 0; i < n; i++) {
    if (i < col)
      ms[i] = 2;
    else
      ms[i] = 1;
    val[i] = i;
  }
  res = 0;
  go();
  cout << res << " ";
  return 0;
}
