#include <bits/stdc++.h>
using namespace std;
const int maxn = 51;
const int mod = 1000000007;
long long f[2][maxn][maxn][maxn][maxn];
int d[maxn];
void add(long long &a, long long b) { a = (a + b) % mod; }
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &d[i]);
  f[0][d[1] == 2][d[1] == 3][d[2] == 2][d[2] == 3] = 1;
  for (int i = 2; i < n; i++) {
    int cur = i % 2, next = (i + 1) % 2;
    for (int j1 = 0; j1 <= n; j1++) {
      for (int j2 = 0; j1 + j2 <= n; j2++) {
        for (int k1 = 0; j1 + j2 + k1 <= n; k1++) {
          for (int k2 = 0; j1 + j2 + k1 + k2 <= n; k2++) {
            long long val = f[cur][j1][j2][k1][k2];
            if (val == 0) continue;
            if (j1 == 0 && j2 == 0) {
              add(f[cur][k1][k2][0][0], val);
              continue;
            }
            long long lastway;
            for (int last = 0; last <= 1; last++) {
              if (last == 0) {
                if (j1 < 1) continue;
                lastway = (long long)j1;
                j1--;
              } else if (last == 1) {
                if (j2 < 1) continue;
                lastway = (long long)j2;
                j2--;
                j1++;
              }
              if (d[i + 1] == 2) {
                add(f[next][j1][j2][k1 + 1][k2], val * lastway);
                if (k1 >= 1)
                  add(f[next][j1][j2][k1 - 1][k2],
                      val * lastway * (long long)k1);
                if (k2 >= 1)
                  add(f[next][j1][j2][k1 + 1][k2 - 1],
                      val * lastway * (long long)k2);
              } else {
                add(f[next][j1][j2][k1][k2 + 1], val * lastway);
                if (k1 >= 1)
                  add(f[next][j1][j2][k1 - 1 + 1][k2],
                      val * lastway * (long long)k1);
                if (k1 >= 2)
                  add(f[next][j1][j2][k1 - 2][k2],
                      val * lastway * (long long)k1 * (long long)(k1 - 1) /
                          2LL);
                if (k2 >= 1)
                  add(f[next][j1][j2][k1 + 1 + 1][k2 - 1],
                      val * lastway * (long long)k2);
                if (k2 >= 2)
                  add(f[next][j1][j2][k1 + 2][k2 - 2],
                      val * lastway * (long long)k2 * (long long)(k2 - 1) /
                          2LL);
                if (k1 >= 1 && k2 >= 1)
                  add(f[next][j1][j2][k1 - 1 + 1][k2 - 1],
                      val * lastway * (long long)k1 * (long long)k2);
              }
              if (last == 0)
                j1++;
              else
                j2++, j1--;
            }
          }
        }
      }
    }
    memset(f[cur], 0, sizeof(f[cur]));
  }
  printf("%I64d\n", f[n % 2][0][0][0][0]);
  return 0;
}
