#include <bits/stdc++.h>
using namespace std;
const int N = 1000000, M = 500, mod = 1000000007;
int add(int a, int b, int p = mod) { return a + b >= p ? a + b - p : a + b; }
int sub(int a, int b, int p = mod) { return a - b < 0 ? a - b + p : a - b; }
int mul(int a, int b, int p = mod) { return (long long)a * b % p; }
void sadd(int &a, int b, int p = mod) { a = add(a, b, p); }
void ssub(int &a, int b, int p = mod) { a = sub(a, b, p); }
void smul(int &a, int b, int p = mod) { a = mul(a, b, p); }
int n, c0, c1, a[N + 9];
void into() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &a[i]);
    a[i] == 1 ? ++c0 : ++c1;
  }
}
int c[M + 9][M + 9];
void Get_c() {
  c[0][0] = 1;
  for (int i = 1; i <= n; ++i) {
    c[i][0] = c[i][i] = 1;
    for (int j = 0; j < i; ++j) c[i][j] = add(c[i - 1][j - 1], c[i - 1][j]);
  }
}
int dp[M + 9][M + 9], ans;
void Get_dp() {
  dp[0][0] = 1;
  for (int i = 1; i <= c1 + 1; ++i) dp[0][i] = mul(dp[0][i - 1], i);
  for (int i = 1; i <= c0; ++i)
    for (int j = 0; j <= c1; ++j) {
      dp[i][j] = dp[i - 1][j];
      if (i > 1) sadd(dp[i][j], mul(dp[i - 2][j], i - 1));
      for (int k = 1; k <= j; ++k) {
        sadd(dp[i][j], mul(dp[i - 1][j - k], mul(c[j][k], dp[0][k])));
        if (i > 1)
          sadd(dp[i][j],
               mul(dp[i - 2][j - k], mul(i - 1, mul(c[j][k], dp[0][k + 1]))));
      }
    }
  ans = dp[c0][c1];
}
int f[N + 9];
void Get_f() {
  f[0] = f[1] = 1;
  for (int i = 2; i <= n; ++i) f[i] = add(f[i - 1], mul(f[i - 2], i - 1));
  ans = f[n];
}
void work() {
  if (n > M) {
    Get_f();
  } else {
    Get_c();
    Get_dp();
  }
}
void outo() { printf("%d\n", ans); }
int main() {
  into();
  work();
  outo();
  return 0;
}
