#include <bits/stdc++.h>
using namespace std;
int Y[] = {-1, 1, 0, 0, -1, -1, 1, 1};
int X[] = {0, 0, -1, 1, -1, 1, -1, 1};
int directions = 4;
long long power(long long a, long long n) {
  if (a == 0) return 0;
  if (a == 1 || n == 0) return 1;
  if (n == 1) return a % 1000000007;
  long long t = power(a, n / 2);
  t = t * t % 1000000007;
  if (n & 1) return t * a % 1000000007;
  return t;
}
void keywords() {
  return;
  int x;
  scanf("%d", &x);
  printf("lol");
  cin >> x;
  cout << "lol" << endl;
  while (1) continue;
  while (1) break;
}
int popcount(long long a) {
  int c = 0;
  while (a) {
    c++;
    a -= a & -a;
  }
  return c;
}
void factorize(int a) {}
void update(int tree[], int idx, int val, int maxval) {
  for (; idx <= maxval; idx += idx & -idx) {
    tree[idx] += val;
  }
}
int read(int tree[], int idx) {
  long long sum = 0;
  for (; idx > 0; idx -= idx & -idx) {
    sum += tree[idx];
  }
  return sum;
}
struct node2 {
  int id, val;
  node2() {
    static int ctx = 1;
    id = ctx++;
  };
  node2(int a, int b = 0, int c = 0, int d = 0, int e = 0, int f = 0) {
    val = a;
  }
};
struct comp2 {
  bool operator()(int a, int b) { return b < a; }
};
bool cmp2(int a, int b) { return b < a; }
struct node {
  int id, val;
  node() {
    static int ctx = 1;
    id = ctx++;
  };
  node(int a, int b = 0, int c = 0, int d = 0, int e = 0, int f = 0) {
    val = a;
  }
};
struct comp {
  bool operator()(int a, int b) { return b < a; }
};
bool cmp(int a, int b) { return b < a; }
int n, m, a[52], b, c, d, k, h, w, x, y, p, q, t, ans, res, ma, mi, T,
    act = 0, pas = 1, cur, flag, now;
int uu, vv, ww, l, r;
long long dp[52][52 / 2][52 / 2][52 / 2][52 / 2], dp2, cnt;
char s[1];
double f, z, e;
vector<int> v, vec;
set<int> sett;
map<int, int> mapp;
void print() {}
void print2() {}
void input() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n;
  for (int i = 1; i < n + 1; i++) cin >> a[i];
}
inline bool check_bounds(int idx, int a, int b, int c, int d) {
  return (a >= 0 && a + b <= idx && b >= 0 && c >= 0 && c <= 25 && d >= 0 &&
          d <= 25);
}
long long calc(int idx, long long p1, long long p2, long long c1,
               long long c2) {
  if (!check_bounds(idx, p1, p2, c1, c2)) return 0;
  if (dp[idx][p1][p2][c1][c2] != -1) return dp[idx][p1][p2][c1][c2];
  if (idx == 1) return 0;
  long long& cur_state = dp[idx][p1][p2][c1][c2];
  cur_state = 0;
  if ((a[idx] == 2)) {
    if (c1 == 1 && c2 == 0) {
      if (idx > 2) {
        (cur_state =
             (1ll * cur_state +
              (1ll * (p1 + 1) * calc(idx - 1, 0, 0, p1 + 1, p2) % 1000000007)) %
             1000000007);
        (cur_state = (1ll * cur_state +
                      (1ll * (p2 + 1) * calc(idx - 1, 0, 0, p1 - 1, p2 + 1) %
                       1000000007)) %
                     1000000007);
      } else {
        if (a[1] == 3 && p1 + 1 == 1 && p2 == 1)
          (cur_state = (1ll * cur_state +
                        (1ll * (p1 + 1) * calc(idx - 1, 0, 0, p1 + 1, p2) %
                         1000000007)) %
                       1000000007);
        else if (a[1] == 2 && p1 - 1 == 0 && p2 + 1 == 1)
          (cur_state = (1ll * cur_state +
                        (1ll * (p2 + 1) * calc(idx - 1, 0, 0, p1 - 1, p2 + 1) %
                         1000000007)) %
                       1000000007);
      }
    }
    (cur_state = (1ll * cur_state +
                  (1ll * (p1 + 1) * calc(idx - 1, p1 + 1, p2, c1 - 1, c2) %
                   1000000007)) %
                 1000000007);
    (cur_state = (1ll * cur_state +
                  (1ll * (p2 + 1) * calc(idx - 1, p1 - 1, p2 + 1, c1 - 1, c2) %
                   1000000007)) %
                 1000000007);
    (cur_state = (1ll * cur_state +
                  (1ll * (p1 + 1) * (c1 + 1) *
                   calc(idx - 1, p1 + 1, p2, c1 + 1, c2) % 1000000007)) %
                 1000000007);
    (cur_state = (1ll * cur_state +
                  (1ll * (p1 + 1) * (c2 + 1) *
                   calc(idx - 1, p1 + 1, p2, c1 - 1, c2 + 1) % 1000000007)) %
                 1000000007);
    (cur_state = (1ll * cur_state +
                  (1ll * (p2 + 1) * (c1 + 1) *
                   calc(idx - 1, p1 - 1, p2 + 1, c1 + 1, c2) % 1000000007)) %
                 1000000007);
    (cur_state =
         (1ll * cur_state +
          (1ll * (p2 + 1) * (c2 + 1) *
           calc(idx - 1, p1 - 1, p2 + 1, c1 - 1, c2 + 1) % 1000000007)) %
         1000000007);
  }
  if ((a[idx] == 3)) {
    if (c1 == 0 && c2 == 1) {
      if (idx > 2) {
        (cur_state =
             (1ll * cur_state +
              (1ll * (p1 + 1) * calc(idx - 1, 0, 0, p1 + 1, p2) % 1000000007)) %
             1000000007);
        (cur_state = (1ll * cur_state +
                      (1ll * (p2 + 1) * calc(idx - 1, 0, 0, p1 - 1, p2 + 1) %
                       1000000007)) %
                     1000000007);
      } else {
        if (a[1] == 3 && p1 + 1 == 1 && p2 == 1)
          (cur_state = (1ll * cur_state +
                        (1ll * (p1 + 1) * calc(idx - 1, 0, 0, p1 + 1, p2) %
                         1000000007)) %
                       1000000007);
        else if (a[1] == 2 && p1 - 1 == 0 && p2 + 1 == 1)
          (cur_state = (1ll * cur_state +
                        (1ll * (p2 + 1) * calc(idx - 1, 0, 0, p1 - 1, p2 + 1) %
                         1000000007)) %
                       1000000007);
      }
    }
    (cur_state = (1ll * cur_state +
                  (1ll * (p1 + 1) * calc(idx - 1, p1 + 1, p2, c1, c2 - 1) %
                   1000000007)) %
                 1000000007);
    (cur_state = (1ll * cur_state +
                  (1ll * (p2 + 1) * calc(idx - 1, p1 - 1, p2 + 1, c1, c2 - 1) %
                   1000000007)) %
                 1000000007);
    (cur_state = (1ll * cur_state +
                  (1ll * (p1 + 1) * (c1)*calc(idx - 1, p1 + 1, p2, c1, c2) %
                   1000000007)) %
                 1000000007);
    (cur_state = (1ll * cur_state +
                  (1ll * (p1 + 1) * (c2 + 1) *
                   calc(idx - 1, p1 + 1, p2, c1 - 2, c2 + 1) % 1000000007)) %
                 1000000007);
    (cur_state = (1ll * cur_state +
                  (1ll * (p1 + 1) * (c1 + 2) * (c1 + 1) / 2 *
                   calc(idx - 1, p1 + 1, p2, c1 + 2, c2) % 1000000007)) %
                 1000000007);
    (cur_state = (1ll * cur_state +
                  (1ll * (p1 + 1) * (c2 + 2) * (c2 + 1) / 2 *
                   calc(idx - 1, p1 + 1, p2, c1 - 2, c2 + 2) % 1000000007)) %
                 1000000007);
    (cur_state = (1ll * cur_state +
                  (1ll * (p1 + 1) * c1 * (c2 + 1) *
                   calc(idx - 1, p1 + 1, p2, c1, c2 + 1) % 1000000007)) %
                 1000000007);
    (cur_state = (1ll * cur_state +
                  (1ll * (p2 + 1) * (c1)*calc(idx - 1, p1 - 1, p2 + 1, c1, c2) %
                   1000000007)) %
                 1000000007);
    (cur_state =
         (1ll * cur_state +
          (1ll * (p2 + 1) * (c2 + 1) *
           calc(idx - 1, p1 - 1, p2 + 1, c1 - 2, c2 + 1) % 1000000007)) %
         1000000007);
    (cur_state = (1ll * cur_state +
                  (1ll * (p2 + 1) * (c1 + 2) * (c1 + 1) / 2 *
                   calc(idx - 1, p1 - 1, p2 + 1, c1 + 2, c2) % 1000000007)) %
                 1000000007);
    (cur_state =
         (1ll * cur_state +
          (1ll * (p2 + 1) * (c2 + 2) * (c2 + 1) / 2 *
           calc(idx - 1, p1 - 1, p2 + 1, c1 - 2, c2 + 2) % 1000000007)) %
         1000000007);
    (cur_state = (1ll * cur_state +
                  (1ll * (p2 + 1) * c1 * (c2 + 1) *
                   calc(idx - 1, p1 - 1, p2 + 1, c1, c2 + 1) % 1000000007)) %
                 1000000007);
  }
  return dp[idx][p1][p2][c1][c2];
}
void solve() {
  memset(dp, -1, sizeof(dp));
  dp[1][0][0][(a[1] == 3)][1] = 1;
  calc(n, 0, 0, 0, 0);
}
void output() { cout << dp[n][0][0][0][0]; }
int main() {
  input();
  solve();
  output();
  return 0;
}
