#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:500000000")
using namespace std;
int a[1000009];
const int mod = 1000000007;
int f(int n, int m) {
  if (n == m) return a[n];
  return (long long)f(n - 1, m) * n % mod;
}
int main() {
  int n, aa, i, m;
  a[1] = 1;
  a[2] = 2;
  for (n = 3; n < 1000009; n++)
    a[n] = (a[n - 1] + (long long)(n - 1) * a[n - 2]) % mod;
  cin >> n;
  m = 0;
  for (i = 0; i < n; i++) {
    cin >> aa;
    m += aa == 1;
  }
  if (m == 0) m++;
  cout << f(n, m) << endl;
}
