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