#include <bits/stdc++.h>
using namespace std;
int a[1000010];
int i, j, n, m, ans = 1;
int main() {
  a[1] = 1;
  a[2] = 2;
  for (i = 3; i <= 1000000; i++)
    a[i] = (a[i - 1] + (long long)(i - 1) * a[i - 2]) % 1000000007;
  scanf("%d", &n);
  if (n == 1) {
    puts("1");
    return 0;
  }
  for (i = 0; i < n; i++) {
    scanf("%d", &j);
    m += j == 2;
  }
  if (m >= n - 2) m = n - 2;
  while (m) {
    ans = (long long)ans * n % 1000000007;
    n--;
    m--;
  }
  ans = (long long)ans * a[n] % 1000000007;
  printf("%d\n", ans);
  return 0;
}
