#include <bits/stdc++.h>
const int maxn = 310, mod = 1e9 + 7;
int n, d[maxn];
long long C[maxn][maxn], g[maxn][maxn][maxn], f[maxn][maxn];
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 j = 1; j <= i; j++)
      C[i][j] = (C[i - 1][j] + C[i - 1][j - 1]) % mod;
  }
  g[0][0][0] = 1;
  for (int i = 0; i <= n; i++)
    for (int j = (i ? 0 : 1); i + j <= n; j++)
      if (!i) {
        long long t = 1;
        for (int k = 2; k < j; k++)
          t = t * k % mod,
          g[0][i][j] = (g[0][i][j] + g[0][i][j - 1 - k] * C[j - 1][k] % mod *
                                         t % mod * (mod + 1) / 2 % mod) %
                       mod;
      } else {
        if (i > 1) g[0][i][j] = (g[0][i][j] + g[0][i - 2][j] * (i - 1)) % mod;
        if (j) g[0][i][j] = (g[0][i][j] + g[0][i][j - 1] * j) % mod;
      }
  for (int i = 1; i < n; i++) {
    for (int s = 0; s < n - i; s++) {
      for (int k = 0; k <= s; k++) {
        int j = s - k;
        if (j || k) {
          if (j) g[i][j][k] = (g[i][j][k] + g[i - 1][j - 1][k] * j) % mod;
          if (k) g[i][j][k] = (g[i][j][k] + g[i - 1][j + 1][k - 1] * k) % mod;
        }
      }
    }
  }
  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++) {
      int cnt2 = 0, cnt3 = 0;
      for (int k = 1; k < i - j; k++) {
        if (d[i - j - k + 1] == 2)
          cnt2++;
        else
          cnt3++;
        f[i][j] = (f[i][j] + g[j][cnt2][cnt3] * f[i - j][k]) % mod;
      }
    }
  long long ans = 0;
  int cnt2 = 0, cnt3 = 0;
  for (int i = 1; i < n; i++) {
    if (d[n - i + 1] == 2)
      cnt2++;
    else
      cnt3++;
    ans = (ans + f[n][i] * g[0][cnt2][cnt3]) % mod;
  }
  std::cout << ans << std::endl;
  return 0;
}
