#include <bits/stdc++.h>
using namespace std;
int n, d[60];
long long a[60], g[60][60][60], f[60][60], c[60][60];
int main() {
  a[0] = a[1] = 0;
  a[2] = a[3] = 1;
  for (int i = 4; i <= 50; i++) {
    a[i] = a[i - 1] * (i - 1) % 1000000007;
  }
  for (int i = 0; i <= 50; i++) {
    c[i][i] = c[i][0] = 1;
  }
  for (int i = 1; i <= 50; i++) {
    for (int j = 1; j < i; j++) {
      c[i][j] = c[i - 1][j - 1] + c[i - 1][j];
      c[i][j] %= 1000000007;
    }
  }
  g[0][0][0] = 1;
  for (int j = 0; j <= 50; j++) {
    for (int k = 0; k <= 50 - j; k++) {
      if (j == 0 && k > 0) {
        for (int l = 2; l < k; l++) {
          g[0][j][k] += (g[0][j][k - l - 1] * c[k - 1][l]) % 1000000007 *
                        a[l + 1] % 1000000007;
          g[0][j][k] %= 1000000007;
        }
      } else {
        if (j >= 2)
          g[0][j][k] += (g[0][j - 2][k] * (j - 1)) % 1000000007,
              g[0][j][k] %= 1000000007;
        if (k >= 1)
          g[0][j][k] += (g[0][j][k - 1] * k) % 1000000007,
              g[0][j][k] %= 1000000007;
      }
    }
  }
  for (int i = 1; i <= 50; i++) {
    for (int j = 0; j <= 50 - i; j++) {
      for (int k = 0; k <= 50 - i - j; k++) {
        if (j >= 1)
          g[i][j][k] += (g[i - 1][j - 1][k] * j) % 1000000007,
              g[i][j][k] %= 1000000007;
        if (k >= 1)
          g[i][j][k] += (g[i - 1][j + 1][k - 1] * k) % 1000000007,
              g[i][j][k] %= 1000000007;
      }
    }
  }
  int c1, c2;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &d[i]);
  f[d[1] + 1][d[1]] = 1;
  for (int i = d[1] + 2; i <= n; i++) {
    for (int j = 1; j <= i - d[1] - 1; j++) {
      c1 = c2 = 0;
      for (int k = 1; k <= i - j; k++) {
        if (d[i - j - k + 1] == 2)
          c1++;
        else
          c2++;
        f[i][j] += f[i - j][k] * g[j][c1][c2] % 1000000007;
        f[i][j] %= 1000000007;
      }
    }
  }
  c1 = c2 = 0;
  long long ans = 0;
  for (int j = 1; j < n; j++) {
    if (d[n - j + 1] == 2)
      c1++;
    else
      c2++;
    ans += f[n][j] * g[0][c1][c2] % 1000000007;
    ans %= 1000000007;
  }
  printf("%lld\n", ans);
}
