#include <bits/stdc++.h>
using namespace std;
long long read() {
  long long x = 0, f = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
int m, n;
long long f[2][55][55][55][55];
int d[55];
void get(long long &x, long long y) { x = (x + y) % 1000000007; }
int main() {
  n = read();
  for (int i = 1; i <= n; i++) d[i] = read();
  f[0][d[1] == 2][d[1] == 3][d[2] == 2][d[2] == 3] = 1;
  int now = 0, next = 1;
  for (int i = 2; i <= n - 1; i++) {
    memset(f[next], 0, sizeof(f[next]));
    for (int p1 = 0; p1 <= n; p1++)
      for (int p2 = 0; p2 + p1 <= n; p2++)
        for (int c1 = 0; c1 + p1 + p2 <= n; c1++)
          for (int c2 = 0; c1 + c2 + p1 + p2 <= n; c2++)
            if (f[now][p1][p2][c1][c2] > 0) {
              long long val = f[now][p1][p2][c1][c2];
              if (p1 == 0 && p2 == 0) {
                get(f[now][c1][c2][0][0], val);
                continue;
              }
              for (int j = 0; j <= 1; j++) {
                long long last = 0;
                if (j == 0) {
                  last = p1;
                  p1--;
                  if (p1 < 0) {
                    p1++;
                    continue;
                  }
                } else {
                  last = p2;
                  p2--;
                  if (p2 < 0) {
                    p2++;
                    continue;
                  }
                  p1++;
                }
                if (d[i + 1] == 2) {
                  get(f[next][p1][p2][c1 + 1][c2], 1LL * val * last);
                  if (c1 >= 1)
                    get(f[next][p1][p2][c1 - 1][c2], 1LL * val * last * c1);
                  if (c2 >= 1)
                    get(f[next][p1][p2][c1 + 1][c2 - 1], 1LL * val * last * c2);
                } else {
                  get(f[next][p1][p2][c1][c2 + 1], 1LL * val * last);
                  if (c1 >= 1)
                    get(f[next][p1][p2][c1][c2], 1LL * val * last * c1);
                  if (c1 >= 2)
                    get(f[next][p1][p2][c1 - 2][c2],
                        1LL * val * last * c1 * (c1 - 1) / 2);
                  if (c2 >= 1)
                    get(f[next][p1][p2][c1 + 2][c2 - 1], 1LL * val * last * c2);
                  if (c2 >= 2)
                    get(f[next][p1][p2][c1 + 2][c2 - 2],
                        1LL * val * last * c2 * (c2 - 1) / 2);
                  if (c1 && c2)
                    get(f[next][p1][p2][c1][c2 - 1],
                        1LL * val * last * c1 * c2);
                }
                if (j == 0)
                  p1++;
                else
                  p2++, p1--;
              }
            }
    now ^= 1;
    next ^= 1;
  }
  printf("%lld\n", f[now][0][0][0][0]);
  return 0;
}
