#include <bits/stdc++.h>   using namespace std;   int n, d[55], f[2][55][55][55][55];   int main() {     register int i, p1, p2, c1, c2, cur = 0, val;     scanf( %d , &n);     for (i = 1; i <= n; ++i) scanf( %d , &d[i]);     f[cur][d[1] == 2][d[1] == 3][d[2] == 2][d[2] == 3] = 1;     for (i = 3; i <= n; ++i) {       cur ^= 1;       memset(f[cur], 0, sizeof(f[cur]));       for (p1 = 0; p1 <= n; ++p1)         for (p2 = 0; p1 + p2 <= n; ++p2)           for (c1 = 0; c1 + p1 + p2 <= n; ++c1)             for (c2 = 0; c1 + c2 + p1 + p2 <= n; ++c2)               if (f[cur ^ 1][p1][p2][c1][c2]) {                 val = f[cur ^ 1][p1][p2][c1][c2];                 if (p1 == 0 && p2 == 0) {                   f[cur ^ 1][c1][c2][0][0] =                       (f[cur ^ 1][c1][c2][0][0] + val) % 1000000007;                   continue;                 }                 if (p1) {                   if (d[i] == 2) {                     f[cur][p1 - 1][p2][c1 + 1][c2] =                         (f[cur][p1 - 1][p2][c1 + 1][c2] + (long long)p1 * val) %                         1000000007;                     if (c1)                       f[cur][p1 - 1][p2][c1 - 1][c2] =                           (f[cur][p1 - 1][p2][c1 - 1][c2] +                            (long long)p1 * c1 * val) %                           1000000007;                     if (c2)                       f[cur][p1 - 1][p2][c1 + 1][c2 - 1] =                           (f[cur][p1 - 1][p2][c1 + 1][c2 - 1] +                            (long long)p1 * c2 * val) %                           1000000007;                   } else {                     f[cur][p1 - 1][p2][c1][c2 + 1] =                         (f[cur][p1 - 1][p2][c1][c2 + 1] + (long long)p1 * val) %                         1000000007;                     if (c1)                       f[cur][p1 - 1][p2][c1][c2] = (f[cur][p1 - 1][p2][c1][c2] +                                                     (long long)p1 * c1 * val) %                                                    1000000007;                     if (c2)                       f[cur][p1 - 1][p2][c1 + 2][c2 - 1] =                           (f[cur][p1 - 1][p2][c1 + 2][c2 - 1] +                            (long long)p1 * c2 * val) %                           1000000007;                     if (c1 && c2)                       f[cur][p1 - 1][p2][c1][c2 - 1] =                           (f[cur][p1 - 1][p2][c1][c2 - 1] +                            (long long)p1 * c1 * c2 * val) %                           1000000007;                     if (c1 > 1)                       f[cur][p1 - 1][p2][c1 - 2][c2] =                           (f[cur][p1 - 1][p2][c1 - 2][c2] +                            (long long)p1 * c1 * (c1 - 1) / 2 * val) %                           1000000007;                     if (c2 > 1)                       f[cur][p1 - 1][p2][c1 + 2][c2 - 2] =                           (f[cur][p1 - 1][p2][c1 + 2][c2 - 2] +                            (long long)p1 * c2 * (c2 - 1) / 2 * val) %                           1000000007;                   }                 }                 if (p2) {                   if (d[i] == 2) {                     f[cur][p1 + 1][p2 - 1][c1 + 1][c2] =                         (f[cur][p1 + 1][p2 - 1][c1 + 1][c2] +                          (long long)p2 * val) %                         1000000007;                     if (c1)                       f[cur][p1 + 1][p2 - 1][c1 - 1][c2] =                           (f[cur][p1 + 1][p2 - 1][c1 - 1][c2] +                            (long long)p2 * c1 * val) %                           1000000007;                     if (c2)                       f[cur][p1 + 1][p2 - 1][c1 + 1][c2 - 1] =                           (f[cur][p1 + 1][p2 - 1][c1 + 1][c2 - 1] +                            (long long)p2 * c2 * val) %                           1000000007;                   } else {                     f[cur][p1 + 1][p2 - 1][c1][c2 + 1] =                         (f[cur][p1 + 1][p2 - 1][c1][c2 + 1] +                          (long long)p2 * val) %                         1000000007;                     if (c1)                       f[cur][p1 + 1][p2 - 1][c1][c2] =                           (f[cur][p1 + 1][p2 - 1][c1][c2] +                            (long long)p2 * c1 * val) %                           1000000007;                     if (c2)                       f[cur][p1 + 1][p2 - 1][c1 + 2][c2 - 1] =                           (f[cur][p1 + 1][p2 - 1][c1 + 2][c2 - 1] +                            (long long)p2 * c2 * val) %                           1000000007;                     if (c1 && c2)                       f[cur][p1 + 1][p2 - 1][c1][c2 - 1] =                           (f[cur][p1 + 1][p2 - 1][c1][c2 - 1] +                            (long long)p2 * c1 * c2 * val) %                           1000000007;                     if (c1 > 1)                       f[cur][p1 + 1][p2 - 1][c1 - 2][c2] =                           (f[cur][p1 + 1][p2 - 1][c1 - 2][c2] +                            (long long)p2 * c1 * (c1 - 1) / 2 * val) %                           1000000007;                     if (c2 > 1)                       f[cur][p1 + 1][p2 - 1][c1 + 2][c2 - 2] =                           (f[cur][p1 + 1][p2 - 1][c1 + 2][c2 - 2] +                            (long long)p2 * c2 * (c2 - 1) / 2 * val) %                           1000000007;                   }                 }               }     }     printf( %d n , f[cur][0][0][0][0]);   }