#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
inline long long read() {
  long long x = 0, w = 0;
  char ch = getchar();
  while (!isdigit(ch)) w |= ch == '-', ch = getchar();
  while (isdigit(ch)) x = (x << 1) + (x << 3) + ch - '0', ch = getchar();
  return w ? -x : x;
}
long long f[1030000], ans = 1, a[1030000];
signed main() {
  long long n = read();
  for (long long i = 1; i <= n; ++i) ++a[read()];
  f[0] = f[1] = 1;
  for (long long i = 2; i <= a[1]; ++i)
    f[i] = (f[i - 2] * (i - 1) + f[i - 1]) % mod;
  ans = f[a[1]];
  for (long long i = n; i > n - a[2]; --i) ans = ans * i % mod;
  printf("%d\n", ans);
  return 0;
}
