#include <bits/stdc++.h>
using namespace std;
int n, d[60], f[60][60], c[60][60], ans[60][60][60], res, dp[60][60][60], x, y,
    z, crs, pp[60], qq[60];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &d[i]);
  for (int i = 0; i <= n; i++) c[i][0] = 1;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++)
      c[i][j] = (c[i - 1][j] + c[i - 1][j - 1]) % 1000000007;
  pp[0] = 1;
  for (int i = 1; i <= n; i++) pp[i] = 1LL * pp[i - 1] * i % 1000000007;
  qq[0] = 1;
  for (int i = 1; i <= n; i++)
    qq[i] = 1LL * qq[i - 1] * ((1000000007 + 1) / 2) % 1000000007;
  f[0][0] = 1;
  for (int i = 2; i <= n; i++)
    f[i][0] = 1LL * f[i - 2][0] * (i - 1) % 1000000007;
  for (int j = 1; j <= n; j++) {
    for (int i = 0; i <= n; i++) {
      if (!i) {
        if (j >= 3) f[0][j] = 1LL * c[j - 1][2] * f[2][j - 3] % 1000000007;
      } else {
        if (i >= 2) {
          f[i][j] = 1LL * i * (j - 1) * f[i][j - 2] % 1000000007;
          f[i][j] = (f[i][j] + 1LL * f[i - 2][j - 1] * c[i][2] % 1000000007) %
                    1000000007;
          f[i][j] =
              (f[i][j] + 1LL * f[i + 2][j - 3] * c[j - 1][2] % 1000000007) %
              1000000007;
        }
      }
    }
  }
  for (int i = 0; i <= n; i++)
    for (int j = 0; j <= n; j++) ans[i][j][0] = f[i][j];
  for (int l = 1; l <= n; l++)
    for (int i = 0; i <= n; i++)
      for (int j = 0; j <= n; j++) {
        if (i)
          ans[i][j][l] =
              (ans[i][j][l] + 1LL * ans[i - 1][j][l - 1] * i % 1000000007) %
              1000000007;
        if (j)
          ans[i][j][l] =
              (ans[i][j][l] + 1LL * ans[i + 1][j - 1][l - 1] * j % 1000000007) %
              1000000007;
      }
  dp[1][1][d[1]] = 1;
  for (int i = 2; i <= n; i++) {
    for (int j = i; j <= n; j++) {
      x = 0, y = 0;
      for (int s = i; s <= j; s++) {
        if (d[s] == 2)
          x++;
        else
          y++;
      }
      for (int l = 0; l <= n; l++) {
        crs = ans[x][y][l];
        z = 0;
        for (int po = i - 1; po >= 1; po--) {
          z += dp[po][i - 1][j - i + 1];
          z %= 1000000007;
        }
        dp[i][j][l] = 1LL * z * crs % 1000000007;
      }
    }
  }
  for (int i = 1; i <= n; i++) res = (res + dp[i][n][0]) % 1000000007;
  printf("%d", res);
}
