#include <bits/stdc++.h>
using namespace std;
int g[55][55][55], co[55][55], f[55][55], deg[55], fac[55], num[4];
namespace BASICMATH {
void inc(int &x, int y) { x = (x + y) % 1000000007; }
}  // namespace BASICMATH
using namespace BASICMATH;
int main() {
  int n, i, j, k, l, ans = 0;
  cin >> n;
  for (i = 1; i <= n; i++) cin >> deg[i];
  fac[0] = fac[1] = 0;
  fac[2] = fac[3] = co[0][0] = 1;
  for (i = 4; i <= n; i++) fac[i] = 1LL * fac[i - 1] * (i - 1) % 1000000007;
  for (i = 1; i <= n; i++)
    for (j = 0; j <= i; j++)
      co[i][j] = (co[i - 1][j] + co[i - 1][j - 1]) % 1000000007;
  g[0][0][0] = 1;
  for (i = 0; i <= n; i++)
    for (j = 0; j <= n - i; j++)
      for (k = 0; k <= n - i - j; k++)
        if (!i)
          if (!j && k)
            for (l = 2; l <= k - 1; l++)
              inc(g[0][j][k], 1LL * g[0][j][k - 1 - l] * co[k - 1][l] %
                                  1000000007 * fac[l + 1] % 1000000007);
          else {
            if (j > 1)
              inc(g[0][j][k], 1LL * g[0][j - 2][k] * (j - 1) % 1000000007);
            if (k) inc(g[0][j][k], 1LL * k * g[0][j][k - 1] % 1000000007);
          }
        else {
          if (j) inc(g[i][j][k], 1LL * g[i - 1][j - 1][k] * j % 1000000007);
          if (k) inc(g[i][j][k], 1LL * g[i - 1][j + 1][k - 1] * k % 1000000007);
        }
  f[1 + deg[1]][deg[1]] = f[deg[1]][deg[1]] = 1;
  for (i = deg[1] + 1; i <= n; i++) {
    num[3] = num[2] = 0;
    for (j = 1; j <= i; j++) {
      num[deg[i - j + 1]]++;
      for (k = 1; k <= n - i; k++)
        inc(f[k + i][k], 1LL * f[i][j] * g[k][num[2]][num[3]] % 1000000007);
    }
  }
  num[3] = num[2] = 0;
  for (i = 1; i <= n - 1; i++)
    num[deg[n - i + 1]]++,
        inc(ans, 1LL * f[n][i] * g[0][num[2]][num[3]] % 1000000007);
  cout << ans;
  return 0;
}
