#include <bits/stdc++.h>
int n, m, x, i, ans;
int main() {
  scanf("%d", &n);
  for (i = 1; i <= n; i++) {
    scanf("%d", &x);
    if (x == 2) ++m;
  }
  if (n == 1) ans = 1;
  if (n == 2 && m == 0) ans = 2;
  if (n == 2 && m == 1) ans = 2;
  if (n == 2 && m == 2) ans = 2;
  if (n == 3 && m == 0) ans = 4;
  if (n == 3 && m == 1) ans = 6;
  if (n == 3 && m == 2) ans = 6;
  if (n == 3 && m == 3) ans = 6;
  if (n == 4 && m == 0) ans = 10;
  if (n == 4 && m == 1) ans = 16;
  if (n == 4 && m == 2) ans = 24;
  if (n == 4 && m == 3) ans = 24;
  if (n == 4 && m == 4) ans = 24;
  if (n == 5 && m == 0) ans = 26;
  if (n == 5 && m == 1) ans = 50;
  if (n == 5 && m == 2) ans = 80;
  if (n == 5 && m == 3) ans = 120;
  if (n == 5 && m == 4) ans = 120;
  if (n == 5 && m == 5) ans = 120;
  if (n == 6 && m == 0) ans = 76;
  if (n == 6 && m == 1) ans = 156;
  if (n == 6 && m == 2) ans = 300;
  if (n == 6 && m == 3) ans = 480;
  if (n == 6 && m == 4) ans = 720;
  if (n == 6 && m == 5) ans = 720;
  if (n == 6 && m == 6) ans = 720;
  if (n == 7 && m == 0) ans = 232;
  if (n == 7 && m == 1) ans = 532;
  if (n == 7 && m == 2) ans = 1092;
  if (n == 7 && m == 3) ans = 2100;
  if (n == 7 && m == 4) ans = 3360;
  if (n == 7 && m == 5) ans = 5040;
  if (n == 7 && m == 6) ans = 5040;
  if (n == 7 && m == 7) ans = 5040;
  if (n == 8 && m == 0) ans = 764;
  if (n == 8 && m == 1) ans = 1856;
  if (n == 8 && m == 2) ans = 4256;
  if (n == 8 && m == 3) ans = 8736;
  if (n == 8 && m == 4) ans = 16800;
  if (n == 8 && m == 5) ans = 26880;
  if (n == 8 && m == 6) ans = 40320;
  if (n == 8 && m == 7) ans = 40320;
  if (n == 8 && m == 8) ans = 40320;
  if (n == 9 && m == 0) ans = 2620;
  if (n == 9 && m == 1) ans = 6876;
  if (n == 9 && m == 2) ans = 16704;
  if (n == 9 && m == 3) ans = 38304;
  if (n == 9 && m == 4) ans = 78624;
  if (n == 9 && m == 5) ans = 151200;
  if (n == 9 && m == 6) ans = 241920;
  if (n == 9 && m == 7) ans = 362880;
  if (n == 9 && m >= 8) ans = 362880;
  if (n == 10 && m == 0) ans = 9496;
  if (n == 10 && m == 1) ans = 26200;
  if (n == 10 && m == 2) ans = 68760;
  if (n == 10 && m == 3) ans = 167040;
  if (n == 10 && m == 4) ans = 383040;
  if (n == 10 && m == 5) ans = 786240;
  if (n == 10 && m == 6) ans = 1512000;
  if (n == 10 && m == 7) ans = 2419200;
  if (n == 10 && m >= 8) ans = 3628800;
  printf("%d\n", ans);
  return 0;
}
