#include <bits/stdc++.h>
using namespace std;
long long i, j, n, m, k, l, a[60], g[60][60][60], f[60][60], c[60][60], d[60],
    ans;
inline long long read() {
  char c = getchar();
  bool f = 0;
  long long x = 0;
  while (!isdigit(c)) f |= c == '-', c = getchar();
  while (isdigit(c)) x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();
  if (f) x = -x;
  return x;
}
signed main() {
  n = read();
  for (long long i = 1; i <= n; i++) a[i] = read();
  d[2] = d[3] = 1;
  c[0][0] = 1;
  for (long long i = 4; i <= n; i++) d[i] = d[i - 1] * (i - 1) % 1000000007;
  for (long long i = 1; i <= n; i++) {
    c[i][0] = 1;
    for (long long j = 1; j <= i; j++)
      c[i][j] = (c[i - 1][j] + c[i - 1][j - 1]) % 1000000007;
  }
  g[0][0][0] = 1;
  for (long long i = 1; i <= n; i++)
    for (long long j = 3; j <= i; j++)
      g[0][0][i] =
          (g[0][0][i] + g[0][0][i - j] * c[i - 1][j - 1] % 1000000007 * d[j]) %
          1000000007;
  for (long long i = 1; i <= n; i++)
    for (long long j = 0; j <= n - i; j++) {
      if (i >= 2)
        g[0][i][j] =
            (g[0][i][j] + g[0][i - 2][j] * (i - 1) % 1000000007) % 1000000007;
      if (j >= 1)
        g[0][i][j] =
            (g[0][i][j] + g[0][i][j - 1] * j % 1000000007) % 1000000007;
    }
  for (long long i = 1; i <= n; i++)
    for (long long j = 0; j <= n - i; j++)
      for (long long k = 0; k <= n - i - j; k++) {
        if (j > 0)
          g[i][j][k] =
              (g[i][j][k] + j * g[i - 1][j - 1][k] % 1000000007) % 1000000007;
        if (k > 0)
          g[i][j][k] = (g[i][j][k] + g[i - 1][j + 1][k - 1] * k % 1000000007) %
                       1000000007;
      }
  f[a[1] + 1][a[1]] = 1;
  for (long long i = a[1] + 2; i <= n; i++)
    for (long long j = 1; j <= i - a[1] - 1; j++) {
      long long c2 = 0, c3 = 0;
      for (long long k = 1; k <= i - j + 1; k++) {
        if (a[i - j + 1 - k] == 2)
          c2++;
        else
          c3++;
        f[i][j] = (f[i][j] + f[i - j][k] * g[j][c2][c3]) % 1000000007;
      }
    }
  long long c2 = 0, c3 = 0;
  for (long long i = 1; i < n; i++) {
    if (a[n - i + 1] == 2)
      c2++;
    else
      c3++;
    ans = (ans + f[n][i] * g[0][c2][c3]) % 1000000007;
  }
  cout << ans << endl;
}
