#include <bits/stdc++.h>
using namespace std;
const int N = 100500;
int n, a[N], p[N], pos[N], b[N], ans = 0, c[N];
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    c[i] = i;
    cin >> a[i];
  }
  do {
    for (int i = 1; i <= n; i++) {
      p[i] = c[i];
    }
    int ok = 1;
    for (int i = 1; i <= n; i++) {
      int j = p[i];
      int sum = (a[i] == 1);
      while (j != i) {
        if (a[j] == 1) ++sum;
        j = p[j];
      }
      if (sum > 2) ok = 0;
    }
    ans += ok;
  } while (next_permutation(c + 1, c + 1 + n));
  cout << ans;
  return 0;
}
