#include <bits/stdc++.h>
using namespace std;
inline int getint() {
  int c, l = 0, x;
  for (; !isdigit(c = getchar()); l = c)
    if (c == EOF) return 1 << 31;
  for (x = c - '0'; isdigit(c = getchar()); x = x * 10 + c - '0')
    if (c == EOF) break;
  return l == '-' ? -x : x;
}
int buf[100];
inline int putint(int x) {
  int i = 0;
  x = x < 0 ? putchar('-'), -x : x;
  for (; buf[i++] = x % 10, x; x /= 10)
    ;
  for (i = i - 1 ? i - 1 : 1; i--; putchar(buf[i] + '0'))
    ;
  return 1;
}
const int N = 55;
const int mod = 1000000007;
long long dp[N][N], g[N][N][N];
int n, l[N];
long long gas(int x, int y, int z) {
  if (x < 0 || y < 0) return 0;
  long long& f = g[x][y][z];
  if (~f) return f;
  f = 0;
  if (z)
    f = (x * gas(x - 1, y, z - 1) + y * gas(x + 1, y - 1, z - 1)) % mod;
  else if (x)
    f = ((x - 1) * gas(x - 2, y, 0) + y * gas(x, y - 1, 0)) % mod;
  else if (y > 2)
    f = (y - 1) * (y - 2) / 2 * gas(2, y - 3, 0) % mod;
  else
    f = !y;
  return f;
}
int main() {
  n = getint();
  memset(g, -1, sizeof(g));
  for (int i = 1; i <= n; i++) l[i] = getint();
  for (int i = n; i >= 2; i--) {
    int sum_2 = 0, sum_3 = 0;
    for (int j = i; j <= n; j++) {
      l[j] == 2 ? sum_2++ : sum_3++;
      if (j == n)
        dp[i][j] = gas(sum_2, sum_3, 0);
      else
        for (int k = j + 1; k <= n; k++)
          dp[i][j] = (dp[i][j] + gas(sum_2, sum_3, k - j) * dp[j + 1][k]) % mod;
    }
  }
  printf("%lld\n", dp[2][1 + l[1]]);
  return 0;
}
