#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
long long n, d[52];
long long f[2][52][52][52][52];
inline void in(long long &now) {
  char Cget;
  now = 0;
  while ((Cget = getchar()) > '9' || Cget < '0')
    ;
  while (Cget >= '0' && Cget <= '9')
    now = now * 10 + Cget - '0', Cget = getchar();
}
int main() {
  in(n);
  for (long long i = 0; i < n; i++) in(d[i]);
  long long now = 0, Next = 1;
  f[now][d[0] == 2][d[0] == 3][d[1] == 2][d[1] == 3] = 1;
  for (long long i = 1; i < n - 1; ++i) {
    memset(f[Next], 0, sizeof(f[Next]));
    for (long long p1 = 0; p1 <= n; ++p1)
      for (long long p2 = 0; p2 + p1 <= n; ++p2)
        for (long long c1 = 0; c1 + p1 + p2 <= n; ++c1)
          for (long long c2 = 0; c1 + c2 + p1 + p2 <= n; ++c2)
            if (f[now][p1][p2][c1][c2]) {
              long long val = f[now][p1][p2][c1][c2];
              if (p1 == 0 && p2 == 0) {
                (f[now][c1][c2][0][0] += val) %= mod;
                continue;
              }
              for (long long l = 0; l <= 1; ++l) {
                long long w;
                if (l == 0) {
                  w = p1;
                  if (--p1 < 0) {
                    ++p1;
                    continue;
                  }
                } else {
                  w = p2;
                  if (--p2 < 0) {
                    ++p2;
                    continue;
                  } else
                    ++p1;
                }
                if (d[i + 1] == 2) {
                  (f[Next][p1][p2][c1 + 1][c2] += val * w) %= mod;
                  if (c1 >= 1)
                    (f[Next][p1][p2][c1 - 1][c2] += val * w * c1) %= mod;
                  if (c2 >= 1)
                    (f[Next][p1][p2][c1 + 1][c2 - 1] += val * w * c2) %= mod;
                } else {
                  (f[Next][p1][p2][c1][c2 + 1] += val * w) %= mod;
                  if (c1 >= 1) (f[Next][p1][p2][c1][c2] += val * w * c1) %= mod;
                  if (c2 >= 1)
                    (f[Next][p1][p2][c1 + 2][c2 - 1] += val * w * c2) %= mod;
                  if (c1 >= 2)
                    (f[Next][p1][p2][c1 - 2][c2] +=
                     val * w * c1 * (c1 - 1) / 2) %= mod;
                  if (c2 >= 2)
                    (f[Next][p1][p2][c1 + 2][c2 - 2] +=
                     val * w * c2 * (c2 - 1) / 2) %= mod;
                  if (c1 >= 1 && c2 >= 1)
                    (f[Next][p1][p2][c1][c2 - 1] += val * w * c1 * c2) %= mod;
                }
                if (l == 0)
                  ++p1;
                else
                  ++p2, --p1;
              }
            }
    now ^= 1, Next ^= 1;
  }
  printf("%lld", f[now][0][0][0][0]);
  return 0;
}
