#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
int n, d[55];
long long dp[2][55][55][55][55];
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) scanf("%d", &d[i]);
  int no = 0, nx = 1;
  dp[0][d[0] == 2][d[0] == 3][d[1] == 2][d[1] == 3] = 1;
  for (int i = 1; i < n - 1; ++i) {
    for (int p1 = 0; p1 <= n; ++p1)
      for (int p2 = 0; p1 + p2 <= n; ++p2)
        for (int c1 = 0; p1 + p2 + c1 <= n; ++c1)
          for (int c2 = 0; p1 + p2 + c1 + c2 <= n; ++c2)
            dp[nx][p1][p2][c1][c2] = 0;
    for (int p1 = 0; p1 <= i + 1; ++p1) {
      for (int p2 = 0; p1 + p2 <= i + 1; ++p2)
        for (int c1 = 0; p1 + p2 + c1 <= i + 1; ++c1)
          for (int c2 = 0; p1 + p2 + c1 + c2 <= i + 1; ++c2)
            if (dp[no][p1][p2][c1][c2]) {
              long long val = dp[no][p1][p2][c1][c2], num;
              if (val == 0) continue;
              if (p1 == 0 && p2 == 0) {
                (dp[no][c1][c2][0][0] += val) %= mod;
                continue;
              }
              for (int level = 0; level <= 1; ++level) {
                if (level == 0) {
                  num = p1;
                  --p1;
                  if (p1 < 0) {
                    ++p1;
                    continue;
                  }
                } else {
                  num = p2;
                  --p2;
                  if (p2 < 0) {
                    ++p2;
                    continue;
                  }
                  ++p1;
                }
                if (d[i + 1] == 2) {
                  (dp[nx][p1][p2][c1 + 1][c2] += num * val) %= mod;
                  if (c1) (dp[nx][p1][p2][c1 - 1][c2] += num * c1 * val) %= mod;
                  if (c2)
                    (dp[nx][p1][p2][c1 + 1][c2 - 1] += num * c2 * val) %= mod;
                } else {
                  (dp[nx][p1][p2][c1][c2 + 1] += num * val) %= mod;
                  if (c1) (dp[nx][p1][p2][c1][c2] += num * c1 * val) %= mod;
                  if (c2)
                    (dp[nx][p1][p2][c1 + 2][c2 - 1] += num * c2 * val) %= mod;
                  if (c1 >= 2)
                    (dp[nx][p1][p2][c1 - 2][c2] +=
                     num * c1 * (c1 - 1) / 2 * val) %= mod;
                  if (c1 && c2)
                    (dp[nx][p1][p2][c1][c2 - 1] += num * c1 * c2 * val) %= mod;
                  if (c2 >= 2)
                    (dp[nx][p1][p2][c1 + 2][c2 - 2] +=
                     num * c2 * (c2 - 1) / 2 * val) %= mod;
                }
                (level == 0) ? (++p1) : (--p1, ++p2);
              }
            }
    }
    swap(no, nx);
  }
  printf("%I64d\n", dp[no][0][0][0][0]);
  return 0;
}
