#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#define For(i,x,y) for (i=x;i<=y;i++)
using namespace std;
const int b[4]={1,2,4,8};
struct ww {
	int a,b,c,d;
} a[100];
int i,j,k,n,m,an;
inline void print() {
	printf("%d\n",an-1);
	int i;
	For(i,2,an) {
		printf("lea e%cx, [",i+'a'-1);
		if (a[i].b) printf("e%cx + ",a[i].b+'a'-1);
		if (a[i].d) printf("%d*",b[a[i].d]);
		printf("e%cx]\n",a[i].c+'a'-1);
	}
	exit(0);
}
void dfs(int x) {
	if (x==an) {
		if (a[x].a==n) print();
		return;
	}
	int i,j,k;
	For(i,0,x)For(j,1,x)For(k,0,3) {
		int A=a[i].a+b[k]*a[j].a;
		if (A<=a[x].a||A>n) continue;
		a[x+1]=(ww){A,i,j,k};
		dfs(x+1);
	}
}
int main() {
	scanf("%d",&n);
	for (an=1;;an++) {
		a[1].a=1;
		dfs(1);
	}
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <ctime>
#include <cassert>

#define x first
#define y second
#define pb push_back
#define mp make_pair
#define forn(i, n) for(int i = 0 ; (i) < (n) ; ++i)
#define forit(it,v) for(typeof((v).begin()) it = v.begin() ; it != (v).end() ; ++it)
#define eprintf(...) fprintf(stderr, __VA_ARGS__),fflush(stderr)
#define sz(a) ((int)(a).size())
#define all(a) (a).begin(),a.end()

using namespace std;

typedef long long ll;
typedef double ld;
typedef vector<int> vi;
typedef pair<int, int> pi;

const int inf = (int)1e9;
const ld eps = 1e-9;

#define TASK "a"
ll dp[1000][1000];
ll cnk[1000][1000];
ll f[1000];
const int md = (int)1e9 + 7;
int main()
{
    #ifdef home
        assert(freopen(TASK".in", "r", stdin));
        assert(freopen(TASK".out", "w", stdout));
    #endif
    int n;
    scanf("%d", &n);
    for (int i = 0; i <= n; i++) {
        cnk[i][0] = 1;
        f[i] = (i == 0) ? 1 : ((ll)f[i - 1] * i) % md;
        for (int j = 1; j <= i; j++) {
            cnk[i][j] = (cnk[i - 1][j - 1] + cnk[i - 1][j]) % md;
        }
    }
    int c1 = 0, c2 = 0;
    for (int i = 0; i < n; i++) {
        int x;
        scanf("%d", &x);
        if (x == 1) {
            c1++;
        } else {
            c2++;
        }
    }
    for (int i = 0; i <= c1; i++) {
        for (int j = 0; j <= c2; j++) {
            if (i + j <= 1) {
                dp[i][j] = 1;
                continue;
            }
            if (i > 0) {
                for (int i1 = 0; i1 + 1 <= min(2, i); i1++) {
                    for (int j1 = 0; j1 <= j; j1++) {
                        if (i1 == 0) {
                            dp[i][j] = (dp[i][j] + (cnk[j][j1] * f[j1]) % md * dp[i - 1][j - j1]) % md;
  //                          if (dp[i][j] < 0) assert(1 == 2);
  //                          cerr<<cnk[j][j1] * f[j1] * dp[i - 1][j - j1]<<endl;
                        } else {
                            dp[i][j] = (dp[i][j] + ((j1 + 1) * cnk[i - 1][i1]) % md * (((cnk[j][j1] * f[j1]) % md * dp[i - 2][j - j1]) % md)) % md;
//                            if (dp[i][j] < 0) assert(1 == 3);
//                            cerr<<2 * cnk[i - 1][i1] * cnk[j][j1] * f[j1] * dp[i - 2][j - j1]<<endl;
                        }
                    }
                }

           //     cerr<<i<<" "<<j<<" "<<dp[i][j]<<endl;
            } else {
                dp[i][j] = f[j];
            }
        }
    }
    cout<<dp[c1][c2]<<endl;
    #ifdef home
        eprintf("Time: %d ms\n", (int)(clock() * 1000. / CLOCKS_PER_SEC));
    #endif
    return 0;
}


#include <iostream>
#include <iomanip>
#include <stdio.h>
#include <set>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#include <memory.h>
#include <string>
#include <sstream>

using namespace std;

const int md = 1000000007;

int g[1111111];

int main() {
  int n;
  scanf("%d", &n);
  int k1 = 0, k2 = 0;
  for (int i=0;i<n;i++) {
    int foo;
    scanf("%d", &foo);
    if (foo == 1) k1++;
    else k2++;
  }
  g[0] = 1;
  for (int i=1;i<=k1;i++) g[i] = (g[i-1] + (long long)g[i-2] * (i-1)) % md;
  int ans = g[k1];
  for (int i=1;i<=k2;i++) ans = (long long)ans * (k1+i) % md;
  printf("%d\n", ans);
  return 0;
}


#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <algorithm>
#include <bitset>
#include <math.h>
#include <queue>
#include <map>
#include <set>
#include <limits.h>
#include <limits>
#include <stdio.h>
#include <stdlib.h>
#include <sstream>
#include <string.h>
#include <assert.h>
#include <numeric>
#define MOD 1000000007
using namespace std;

int n, x, c1, c2;
long long t1[1000005];
int main(){
    scanf("%d", &n);
    for(int i = 0; i < n; i++){
        scanf("%d", &x);

        if(x == 1)c1++;
        else c2++;
    }

    t1[0] = t1[1] = 1;
    for(int i = 2; i <= c1; i++){
        t1[i] = t1[i - 1] + t1[i - 2] * (i - 1);
        t1[i] %= MOD;
    }

    long long ans = t1[c1];
    for(int i = c1 + 1; i <= (c1 + c2); i++){
        ans *= i;
        ans %= MOD;
    }

    printf("%I64d\n", ans);

    return 0;
}


#include <iostream>
#include <iomanip>
#include <sstream>
#include <fstream>
#include <string>
#include <cstdlib>
#include <cstdio>
#include <climits>
#include <cstring>
#include <ctime>
#include <cmath>
#include <cassert>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <algorithm>
#include <utility>
#include <numeric>
#include <functional>

#define forn(i, n) for (int i = 0; i < int(n); i++)
#define forl(i, n) for (int i = 1; i <= int(n); i++)
#define ford(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define fore(i, l, r) for (int i = int(l); i <= int(r); i++)
#define correct(x, y, n, m) (0 <= (x) && (x) < (n) && 0 <= (y) && (y) < (m))
#define all(a) (a).begin(), (a).end()
#define sz(a) int((a).size())
#define pb(a) push_back(a)
#define mp(x, y) make_pair((x), (y))
#define ft first
#define sc second
#define x first
#define y second

using namespace std;

typedef long long li;
typedef long double ld;
typedef pair<int, int> pt;

template<typename X> inline X abs(const X& a) { return a < 0? -a: a; }
template<typename X> inline X sqr(const X& a) { return a * a; }

const int INF = int(1e9);
const li INF64 = li(1e18);
const ld EPS = 1e-9, PI = 3.1415926535897932384626433832795;

const int N = 500 + 13;
const int mod = 1000 * 1000 * 1000 + 7;

int n1, n2;
int c[N][N], f[N];

inline bool read()
{
    int n;
    if (scanf("%d", &n) != 1)
        return false;

    forn(i, n)
    {
        int tmp;
        assert(scanf("%d", &tmp) == 1);
        if (tmp == 1) n1++; else n2++;
    }

    return true;
}

int d[N][N];

int solve (int n1, int n2)
{
    int& ans = d[n1][n2];
    if (ans != -1) return ans;

    if (n1 == 0) return ans = f[n2];

    ans = 0;

    forn(c2, n2 + 1)
    {
        int t = (c[n2][c2] * 1LL * f[c2]) % mod;
        ans = (ans + solve(n1 - 1, n2 - c2) * 1LL * t) % mod;

        t = (c[n2][c2] * 1LL * (n1 - 1)) % mod;
        t = (t * 1LL * f[c2 + 1]) % mod;

        ans = (ans + t * 1LL * solve(n1 - 2, n2 - c2)) % mod;

        //cerr << n1 << ' ' << n2 << ' ' << c2 << ' ' << ans << endl;
    }

    //cerr << n1 << ' ' << n2 << ' ' << ans << endl;

    return ans;
}

int cnt[N];
vector <int> perm;
set < vector <int> > s;

void go ()
{
    s.insert(perm);

    forn(i, sz(perm))
        forn(j, i)
            if (cnt[i] > 0 && cnt[j] > 0)
            {
                cnt[i]--, cnt[j]--;
                swap(perm[i], perm[j]);
                go();
                swap(perm[i], perm[j]);
                cnt[i]++, cnt[j]++;
            }
}

inline int naive (int n1, int n2)
{
    forn(i, n1 + n2)
    {
        perm.pb(i);
        if (i < n1) cnt[i] = 1; else cnt[i] = 2;
    }

    go();

    return sz(s);
}

inline void solve()
{
    c[0][0] = 1;
    forl(i, N - 1)
        forn(j, i + 1)
            c[i][j] = ((j == 0 ? 0 : c[i - 1][j - 1]) + c[i - 1][j]) % mod;

    f[0] = 1;
    forl(i, N - 1) f[i] = (f[i - 1] * 1LL * i) % mod;

    memset(d, -1, sizeof(d));

    cout << solve(n1, n2) << endl;
    //cerr << naive(n1, n2) << endl;
}

int main()
{
#ifdef SU2_PROJ
    freopen("input.txt", "rt", stdin);
    //freopen("output.txt", "wt", stdout);
#endif

    cout << setprecision(10) << fixed;
    cerr << setprecision(5) << fixed;

    assert(read());
    solve();

    return 0;
}


#include <cstdio>
#include <memory.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>

using namespace std;

set< vector<int> > s;
set< pair< vector<int>, vector<int> > > w;

void gen(vector<int> v, vector<int> o) {
    if (w.count(make_pair(v, o))) return;
    w.insert(make_pair(v, o));
    s.insert(v);
    for (int i = 0; i < v.size(); ++i) for (int j = i + 1; j < v.size(); ++j) if (o[i] && o[j]) {
        o[i]--; o[j]--;
        swap(v[i], v[j]);
        gen(v, o);
        o[i]++; o[j]++;
        swap(v[i], v[j]);
    }
}

const int MOD = 1000000007;

int memo[512][512];
long long C[512][512];
long long F[512];

int f(int l, int r) {
    if (r < 0) return 0;
    if (l <= 0) return F[r];
    if (memo[l][r] >= 0) return memo[l][r];

    long long res = 0;
    for (int k = 0; k <= r; ++k) {
        long long M = F[k] * C[r][k] % MOD;
        long long D = (f(l - 1, r - k) + f(l - 2, r - k) * (l - 1) * (k + 1)) % MOD;
        res += M * D % MOD;
    }

    return memo[l][r] = res % MOD;
}

int main() {
    memset(memo, -1, sizeof memo);
    C[0][0] = 1;
    F[0] = 1;
    for (int i = 1; i < 512; ++i) {
        C[i][0] = 1;
        F[i] = 1LL * i * F[i-1] % MOD;
        for (int j = 1; j <= i; ++j) {
            C[i][j] = (C[i-1][j-1] + C[i-1][j]) % MOD;
        }
    }

    int n;
    cin >> n;
    int ones = 0;
    int twos = 0;
    for (int i = 0; i < n; ++i) {
        int x; cin >> x;
        ones += x == 1;
        twos += x == 2;
    }

    cout << f(ones, twos) << endl;

    return 0;
}


#include <cstdio>
#include <memory.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>

using namespace std;

set< vector<int> > s;
set< pair< vector<int>, vector<int> > > w;

void gen(vector<int> v, vector<int> o) {
    if (w.count(make_pair(v, o))) return;
    w.insert(make_pair(v, o));
    s.insert(v);
    for (int i = 0; i < v.size(); ++i) for (int j = i + 1; j < v.size(); ++j) if (o[i] && o[j]) {
        o[i]--; o[j]--;
        swap(v[i], v[j]);
        gen(v, o);
        o[i]++; o[j]++;
        swap(v[i], v[j]);
    }
}

const int MOD = 1000000007;

int memo[512][512];
long long C[512][512];
long long F[512];

int f(int l, int r) {
    if (r < 0) return 0;
    if (l <= 0) return F[r];
    if (memo[l][r] >= 0) return memo[l][r];

    long long res = 0;
    for (int k = 0; k <= r; ++k) {
        long long M = F[k] * C[r][k] % MOD;
        long long D = (f(l - 1, r - k) + 1LL * f(l - 2, r - k) * (l - 1) * (k + 1)) % MOD;
        res += M * D % MOD;
    }

    return memo[l][r] = res % MOD;
}

int main() {
    memset(memo, -1, sizeof memo);
    C[0][0] = 1;
    F[0] = 1;
    for (int i = 1; i < 512; ++i) {
        C[i][0] = 1;
        F[i] = 1LL * i * F[i-1] % MOD;
        for (int j = 1; j <= i; ++j) {
            C[i][j] = (C[i-1][j-1] + C[i-1][j]) % MOD;
        }
    }

    int n;
    cin >> n;
    int ones = 0;
    int twos = 0;
    for (int i = 0; i < n; ++i) {
        int x; cin >> x;
        ones += x == 1;
        twos += x == 2;
    }
/*
    for (int i = 0; i < 10; i++) {
        cout << "i = " << i << endl;
        for (int j = 0; j < 10; j++) {
            printf("%7d ", f(i, j));
        }
        cout << endl;
    }
*/
    cout << f(ones, twos) << endl;

    return 0;
}


#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <queue>
using namespace std ;

#define FOREACH(it,c) for( __typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define FOR(i,a,b) for( int i=(a),_b=(b);i<=_b;i++)
#define DOW(i,b,a) for( int i=(b),_a=(a);i>=_a;i--)
#define REP(i,n) FOR(i,0,(n)-1)
#define DEP(i,n) DOW(i,(n)-1,0)
#define all(a) (a).begin() , (a).end()
#define push(a,b) (a).push_back((b))

typedef vector<int> VI ;
typedef vector<string> VS ;
template<class T> inline int size(const T&c) { return c.size(); }

using namespace std;
const int cmod =1000000007;
int s1,s2;
long long F[1000000+10];
int n,u;
long long res;
int main()
{
    //freopen("D316.inp","r",stdin);
    //freopen("D316.out","w",stdout);
    cin>>n;
    FOR(i,1,n)
    {
        cin>>u;
        if (u==1) s1++;
        else s2++;
    }
    //cout<<s1<<' '<<s2<<endl;
    F[0]=1;
    res=1;
    FOR(i,1,s1)
    {
        //F[i]=(F[i-2]*(((long long)(s1-(i-2))*(s1-(i-2)-1)/2)%cmod))%cmod;
        F[i]=(F[i-1]+(long long)(i-1)*F[i-2])%cmod;
        //cout<<res<<' '<<i<<' '<<F[i]<<endl;
        //res=(res+F[i])%cmod;
    }
    res=F[s1];
    //cout<<res<<endl;
    for(int i=s1+1;i<=s1+s2;i++)
    {
        res=((long long)res*i)%cmod;
    }
    cout<<res<<endl;
    fclose(stdin);
    fclose(stdout);
    return 0;
}


#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;

const int MAXN = 500 + 10, MOD = (int)1e+9 + 7;
typedef long long LL;

int n, m, f[MAXN][MAXN], fac[MAXN], c[MAXN][MAXN];

void init()
{
	scanf("%d", &n);
	for (int i = 1; i <= n; ++i)
	{
		int x;
		scanf("%d", &x);
		m += (x == 2);
	}
	c[0][0] = 1;
	for (int i = 1; i <= n; ++i)
		for (int j = 0; j <= i; ++j)
			c[i][j] = !j ? (1) : (c[i - 1][j - 1] + c[i - 1][j]) % MOD;
}
int calc(int a, int b)
{
/*
	f[a][b] ->  the number of 1 remain is a and 2 is b
	f[0][b]=b!
	f[a][b]=f[a-1][b-k]*A(b,k) (*(k+1)/(k+1))
	f[a][b]=f[a-2][b-k]*(k+1)*(a-1)*A(b,k) (*(k+2)/(k+2))
*/
	fac[0] = 1;
	for (int i = 1; i <= b; ++i)
		fac[i] = (LL)fac[i - 1] * i % MOD;
	for (int i = 0; i <= b; ++i)
		f[0][i] = fac[i];
	for (int i = 1; i <= a; ++i)
		for (int j = 0; j <= b; ++j)
			for (int k = 0; k <= j; ++k)
			{
				f[i][j] = (f[i][j] + (LL)f[i - 1][j - k] * c[j][k] % MOD * fac[k] % MOD) % MOD;
				if (i >= 2)
					f[i][j] = (f[i][j] + (LL)f[i - 2][j - k] * c[j][k] % MOD * fac[k] % MOD * (k + 1) % MOD * (i - 1) % MOD) % MOD;
			}
	return f[a][b];
}
int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);
#endif
	init();
	cout << calc(n - m, m) << endl;
	fclose(stdin);
	fclose(stdout);
	return 0;
}


/*
Abolfazl Kazemi

BSc in Software Engineering: IAUN Iran
MSc student of Software Engineering: IUST
UVA, topcoder, codeforces, facebook account: AKJ88
*/

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <climits>
#include <cstring>
#include <cmath>
#include <map>
#include <set>
#include <queue>
#include <functional>
#include <string>
#include <sstream>
#include <ctime>
#include <bitset>
#include <cstdlib>

using namespace std;

#define     For(i,a,b)        for (i=a; i<b; i++)
#define     FoR(i,a,b)        for (i=a; i<=b; i++)
#define     Rep(i,a)          for (i=0; i<a; i++)
#define     FIT(it,v)         for (it=(v).begin(); it!=(v).end(); ++it)
#define     ALL(v)            (v).begin(),(v).end()
#define     Set(a,x)          memset((a),(x),sizeof(a))
#define     EXIST(a,b)        find(ALL(a),(b))!=(a).end()
#define     Sort(x)           sort(ALL(x))
#define     UNIQUE(v)         Sort(v); (v).resize(unique(ALL(v)) - (v).begin())
#define     SF                scanf
#define     PF                printf

#define     EPS         1e-8
#define     PI          acos(-1)
#define     MAXN        1000005
#define     MOD         1000000007
#define     INF         1000000000
#define     X           first
#define     Y           second

typedef pair<int, int> ii;
typedef pair<double, double> dd;
typedef long long ll;
typedef unsigned long long llu;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<dd> vdd;

int dp[MAXN];
int I(int n){
    if (n == 1 || n == 0)
        return 1;
    if (~dp[n])
        return dp[n];
    ll res = ((ll)I(n - 1) + (ll)(n - 1) * I(n - 2)) % MOD;
    return dp[n] = res;
}

int getRes(int n, int m){
    ll r = 1, i;
    for (i = n + 1; i <= n + m; i++)
        r = (r*i) % MOD;
    ll res = (r*I(n)) % MOD;
    return res;
}

int main(){
    int i, c, n, m, num;
#ifndef ONLINE_JUDGE
    freopen("C:\\acm_inp\\abb3d1.in", "r", stdin);
    //freopen("C:\\acm_inp\\PSEUDO.OUT", "w", stdout);
#endif

    Set(dp, -1);
    n = m = 0;
    SF("%d", &c);
    Rep(i, c){
        SF("%d", &num);
        n += (num == 1);
        m += (num == 2);
    }
    cout << getRes(n, m) << endl;

    return 0;
}


#include <algorithm>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <iostream>
#define fi "D.INP"
#define fo "D.OUT"
#define nmax 500+5
using namespace std;
typedef long long ll;
const ll mod=ll(1000000007);
int x,y,n,k;
ll d[nmax][nmax],fac[nmax],c[nmax][nmax];
bool check[nmax][nmax];

void Update(ll &p, ll q)
{
	q%=mod;
	p+=q;
	p%=mod;
}
ll Try(int i, int j)
{
	if (i==0)
	{
		//cout << i << " " << j << "    " << fac[j] << endl;
		return fac[j];
	}
	ll& S=d[i][j];
	if (check[i][j]) return S;
	check[i][j]=true;
	Update(S,Try(i-1,j));
	for (int k=2;k<=i+j;++k)
	{
		if ((i>=2) && (j>=k-2)) Update(S,Try(i-2,j-(k-2))*((c[j][k-2]*((ll(i-1)*fac[k-1])%mod))%mod));
		if (j>=k-1) Update(S,Try(i-1,j-(k-1))*((c[j][k-1]*fac[k-1])%mod));
	}
	//cout << i << " " << j << "    " << S << endl;
	return S;
}
int main()
{
	//freopen(fi,"r",stdin);
	//freopen(fo,"w",stdout);
	scanf("%d",&n);
	fac[0]=1;
	for (int i=1;i<=n;++i) fac[i]=(fac[i-1]*ll(i))%mod;
	c[0][0]=1;
	for (int i=1;i<=n;++i)
	{
		c[i][0]=1;
		for (int j=1;j<=i;++j) c[i][j]=(c[i-1][j-1]+c[i-1][j])%mod;
	}
	for (int i=1;i<=n;++i)
	{
		scanf("%d",&k);
		if (k==1) ++x; else ++y;
	}
	cout << Try(x,y) << endl;
	return 0;
}


#include <algorithm>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <iostream>
#define fi "D.INP"
#define fo "D.OUT"
#define nmax 500+5
using namespace std;
typedef long long ll;
const ll mod=ll(1000000007);
int x,y,n,k;
ll d[nmax][nmax],fac[nmax],c[nmax][nmax];
bool check[nmax][nmax];

void Update(ll &p, ll q)
{
	q%=mod;
	p+=q;
	p%=mod;
}
ll Try(int i, int j)
{
	if (i==0)
	{
		//cout << i << " " << j << "    " << fac[j] << endl;
		return fac[j];
	}
	ll& S=d[i][j];
	if (check[i][j]) return S;
	check[i][j]=true;
	Update(S,Try(i-1,j));
	for (int k=2;k<=i+j;++k)
	{
		if ((i>=2) && (j>=k-2)) Update(S,Try(i-2,j-(k-2))*(c[j][k-2]*(ll(i-1)*fac[k-1])%mod)%mod);
		if (j>=k-1) Update(S,Try(i-1,j-(k-1))*(c[j][k-1]*fac[k-1])%mod);
	}
	//cout << i << " " << j << "    " << S << endl;
	return S;
}
int main()
{
	//freopen(fi,"r",stdin);
	//freopen(fo,"w",stdout);
	scanf("%d",&n);
	fac[0]=1;
	for (int i=1;i<=n;++i) fac[i]=(fac[i-1]*ll(i))%mod;
	c[0][0]=1;
	for (int i=1;i<=n;++i)
	{
		c[i][0]=1;
		for (int j=1;j<=i;++j) c[i][j]=(c[i-1][j-1]+c[i-1][j])%mod;
	}
	for (int i=1;i<=n;++i)
	{
		scanf("%d",&k);
		if (k==1) ++x; else ++y;
	}
	cout << Try(x,y) << endl;
	return 0;
}


#include <algorithm>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <iostream>
#define fi "D.INP"
#define fo "D.OUT"
#define nmax 500+5
using namespace std;
typedef long long ll;
const ll mod=ll(1000000007);
int x,y,n,k;
ll d[nmax][nmax],fac[nmax],c[nmax][nmax];
bool check[nmax][nmax];

void Update(ll &p, ll q)
{
	q%=mod;
	p+=q;
	p%=mod;
}
ll Try(int i, int j)
{
	if (i==0)
	{
		//cout << i << " " << j << "    " << fac[j] << endl;
		return fac[j];
	}
	ll& S=d[i][j];
	if (check[i][j]) return S;
	check[i][j]=true;
	Update(S,Try(i-1,j));
	for (int k=2;k<=i+j;++k)
	{
		if ((i>=2) && (j>=k-2)) Update(S,Try(i-2,j-(k-2))*((c[j][k-2]*(ll(i-1)*fac[k-1])%mod)%mod));
		if (j>=k-1) Update(S,Try(i-1,j-(k-1))*((c[j][k-1]*fac[k-1])%mod));
	}
	//cout << i << " " << j << "    " << S << endl;
	return S;
}
int main()
{
	//freopen(fi,"r",stdin);
	//freopen(fo,"w",stdout);
	scanf("%d",&n);
	fac[0]=1;
	for (int i=1;i<=n;++i) fac[i]=(fac[i-1]*ll(i))%mod;
	c[0][0]=1;
	for (int i=1;i<=n;++i)
	{
		c[i][0]=1;
		for (int j=1;j<=i;++j) c[i][j]=(c[i-1][j-1]+c[i-1][j])%mod;
	}
	for (int i=1;i<=n;++i)
	{
		scanf("%d",&k);
		if (k==1) ++x; else ++y;
	}
	cout << Try(x,y) << endl;
	return 0;
}


#include<cstdio>
#include<iostream>
using namespace std;
#define REP(i,n) for((i)=0;(i)<(int)(n);(i)++)
typedef long long ll;
#define MOD 1000000007ll
ll dp[1000010];
ll func(int one, int two){
    int i;
    dp[0] = 1;
    for(i=1;i<1000010;i++){
        dp[i] = dp[i-1];
        if(i >= 2) dp[i] = (dp[i] + (i-1) * dp[i-2]) % MOD;
    }
//  for(int i=1;i<=10;++i)printf("dp[%d]:%I64d\n",i,dp[i]);
    ll ans = dp[one];//全部人最多換一次的dp成果，，獨立的不同permutation總數
    REP(i,two) ans = ans * (one+i+1) % MOD;
    /*想像由第一個可以換兩次的人開始，他可以不用第二次機會換，也可以和任何一個只能換一次的人換
     * 第2個可以換兩次的人開始，他可以不用第二次機會換，也可以和任何一個只能換一次和第一個可換兩次的人換
     *
     */
    return ans;
}
int main(void){
    int N,i,one=0,two=0;
    cin >> N;
    REP(i,N){
        int x;
        scanf("%d", &x);
        if(x == 1) one++; else two++;
    }
    //  cout << func(1000000, 1000000) << endl;
    ll ans = func(one, two);
    cout << ans << endl;
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#define mod 1000000007
#define ll long long

using namespace std;

int a[1000];
ll f[1000001], fi[1000001];
ll pd[1000001];

ll fexp(ll n, ll e)
{
    if(e == 0) return 1;
    if(e == 1) return n;
    if(e%2 == 0) return fexp((1ll * n * n)%mod,e/2);
    return (1ll * n * fexp(n,e-1))%mod;
}

ll inv(ll n) { return fexp(n,mod-2); }

int main()
{
    int n, c1=0;
    cin >> n;
    f[0] = 1;
    pd[0] = 1;
    pd[1] = 1;
    for(int i=1;i<1000001;i++) f[i] = f[i-1]*i;
    for(int i=0;i<1000001;i++) fi[i] = inv(f[i]);
    for(int i=2;i<1000001;i++) pd[i] = pd[i-1] + (i-1)*pd[i-2];
    for(int i=0;i<n;i++)
    {
        cin >> a[i];
        if(a[i] == 1) c1++;
    }
    cout << (((pd[c1]*f[n])%mod)*fi[c1])%mod<< endl;
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#define mod 1000000007
#define ll long long

using namespace std;

int a[1000];
ll f[1000001], fi[1000001];
ll pd[1000001];

ll fexp(ll n, ll e)
{
    if(e == 0) return 1;
    if(e == 1) return n;
    if(e%2 == 0) return fexp((1ll * n * n)%mod,e/2);
    return (1ll * n * fexp(n,e-1))%mod;
}

ll inv(ll n) { return fexp(n,mod-2); }

int main()
{
    int n, c1=0;
    cin >> n;
    f[0] = 1;
    pd[0] = 1;
    pd[1] = 1;
    for(int i=1;i<1000001;i++) f[i] = (f[i-1]*i)%mod;
    for(int i=0;i<1000001;i++) fi[i] = inv(f[i]);
    for(int i=2;i<1000001;i++) pd[i] = (pd[i-1] + ((i-1)*pd[i-2])%mod)%mod;
    for(int i=0;i<n;i++)
    {
        cin >> a[i];
        if(a[i] == 1) c1++;
    }
    cout << pd[c1] << " x " << f[n] << " x " << fi[c1] << endl;
    cout << (((pd[c1]*f[n])%mod)*fi[c1])%mod<< endl;
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#define mod 1000000007
#define ll long long

using namespace std;

int a[1000];
ll f[1000001], fi[1000001];
ll pd[1000001];

ll fexp(ll n, ll e)
{
    if(e == 0) return 1;
    if(e == 1) return n;
    if(e%2 == 0) return fexp((1ll * n * n)%mod,e/2);
    return (1ll * n * fexp(n,e-1))%mod;
}

ll inv(ll n) { return fexp(n,mod-2); }

int main()
{
    int n, c1=0;
    cin >> n;
    f[0] = 1;
    pd[0] = 1;
    pd[1] = 1;
    for(int i=1;i<1000001;i++) f[i] = (f[i-1]*i)%mod;
    for(int i=0;i<1000001;i++) fi[i] = inv(f[i]);
    for(int i=2;i<1000001;i++) pd[i] = (pd[i-1] + ((i-1)*pd[i-2])%mod)%mod;
    for(int i=0;i<n;i++)
    {
        cin >> a[i];
        if(a[i] == 1) c1++;
    }
    cout << (((pd[c1]*f[n])%mod)*fi[c1])%mod<< endl;
    return 0;
}


#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define rep(i,a,b) for (int i=a;i<=b;++i)
const int P=1000000007,N=1000005;
int n,m,x,s[2]; long long f[N];
void read(int &x)
{
	#define CH getchar()
	char ch; x=0; bool y=0; for (ch=CH;ch<'0' || ch>'9';ch=CH) if (ch=='-') y=1;
	for (;ch>='0' && ch<='9';x=x*10+ch-48,ch=CH); if (y) x=-x;
}
int main()
{
	scanf("%d",&n); rep(i,1,n){read(x); if (x) ++s[x==1];} n=s[0],m=s[1],f[0]=1;
	rep(j,0,m) f[j+1]=(f[j+1]+f[j])%P,f[j+2]=(f[j+2]+f[j]*(j+1))%P;
	rep(i,1,n) f[m]=f[m]*(i+m)%P; printf("%d\n",f[m]);
	return 0;
}


#include <iostream>
#include <string>
#include <cstdio>
#include <cstring>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <cmath>
#include <sstream>
#include <algorithm>
#include <numeric>
#define mp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
using namespace std;
typedef long long ll;
const ll mod = 1000000007ll ;
ll mpow(ll p,ll q){
    p%=mod;
    ll ans=1;
    while(q){
        if(q&1)
            ans=ans*p%mod;
        q>>=1;
        p=p*p%mod;
    }
    return ans;
}
ll fac[2000005];
ll rev(ll n){return mpow(n,mod);}
ll C(int m, int n){
    return fac[m]*rev(fac[n]*fac[m-n]%mod)%mod;
}
int main()
{
    int n,a=0;
    scanf("%d",&n);
    fac[0]=1;
    for(int i=1;i<=n+n;++i)
        fac[i]=fac[i-1]*i%mod;
    for(int i=0,p;i<n;++i){
        scanf("%d",&p);
        if(p<=0){--n;--i;continue;}
        if(p==1)++a;
    }
    if(n==200)cout<<a<<endl;
    ll ans=1;
    for(int k=1;k+k<=a;++k)
        ans+=C(a,k+k)*fac[k+k]%mod*rev(mpow(2,k)*fac[k]%mod)%mod;
    ans=ans*fac[n]%mod*rev(fac[a])%mod;
    cout<<ans<<endl;
    return 0;
}


#include <iostream>
#include <string>
#include <cstdio>
#include <cstring>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <cmath>
#include <sstream>
#include <algorithm>
#include <numeric>
#define mp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
using namespace std;
const int INF = 0x3f3f3f3f;
typedef long long ll;
const ll mod = 1000000007 ;
ll mpow(ll p,ll q){
    ll ans=1;
    while(q){
        if(q&1)
            ans=ans*p%mod;
        q>>=1;
        p=p*p%mod;
    }
    return ans;
}
ll fac[2000005];
inline ll rev(int n){return mpow(n,mod-2);}
inline ll C(int m, int n){
    return fac[m]*rev(fac[n]*fac[m-n]%mod)%mod;
}
int main()
{
    int n,a=0;
    scanf("%d",&n);
    fac[0]=1;
    for(int i=1;i<=n;++i)
        fac[i]=fac[i-1]*i%mod;
    for(int i=0,k;i<n;++i){
        scanf("%d",&k);
        if(k==1)++a;
    }
    ll ans=0;
    for(int k=0;k<=a;++++k)
        ans+=C(a,k)*fac[k]%mod*rev(mpow(2,k>>1)*fac[k>>1]%mod)%mod;
    cout<<ans*fac[n]%mod*rev(fac[a])%mod<<endl;
    return 0;
}


#include <iostream>
#include <string>
#include <cstdio>
#include <cstring>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <cmath>
#include <sstream>
#include <algorithm>
#include <numeric>
#define mp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
using namespace std;
const int INF = 0x3f3f3f3f;
typedef long long ll;
const ll mod = 1000000007 ;
ll mpow(ll p,ll q){
    ll ans=1;
    while(q){
        if(q&1)
            ans=ans*p%mod;
        q>>=1;
        p=p*p%mod;
    }
    return ans;
}
ll fac[1000005];
inline ll rev(ll n){return mpow(n,mod-2);}
inline ll C(int m, int n){
    return fac[m]*rev(fac[n]*fac[m-n]%mod)%mod;
}
int main()
{
    int n,a=0;
    scanf("%d",&n);
    fac[0]=1;
    for(int i=1;i<=n;++i)
        fac[i]=fac[i-1]*i%mod;
    for(int i=0,k;i<n;++i){
        scanf("%d",&k);
        if(k==1)++a;
    }
    ll ans=0;
    for(int k=0;k<=a;++++k)
        ans+=C(a,k)*fac[k]%mod*rev(mpow(2,k>>1)*fac[k>>1]%mod)%mod;
    cout<<ans*fac[n]%mod*rev(fac[a])%mod<<endl;
    return 0;
}


#include <iostream>
#include <string>
#include <cstdio>
#include <cstring>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <cmath>
#include <sstream>
#include <algorithm>
#include <numeric>
#define mp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
using namespace std;
typedef long long ll;
const ll mod = 1000000007ll ;
ll mpow(ll p,ll q){
    p%=mod;
    ll ans=1;
    while(q){
        if(q&1)
            ans=ans*p%mod;
        q>>=1;
        p=p*p%mod;
    }
    return ans;
}
ll fac[2000005];
ll rev(ll n){return mpow(n,mod-2ll);}
ll C(int m, int n){
    return fac[m]*rev(fac[n]*fac[m-n]%mod)%mod;
}
int main()
{
    int n,a=0;
    scanf("%d",&n);
    fac[0]=1;
    for(int i=1;i<=n+n;++i)
        fac[i]=fac[i-1]*i%mod;
    for(int i=0,p;i<n;++i){
        scanf("%d",&p);
        if(p<=0){--n;--i;continue;}
        if(p==1)++a;
    }
    ll ans=1;
    for(int k=1;k+k<=a;++k)
        ans+=C(a,k+k)*fac[k+k]%mod*rev(mpow(2,k)*fac[k]%mod)%mod;
    ans=ans*fac[n]%mod*rev(fac[a])%mod;
    cout<<ans<<endl;
    return 0;
}


#include <iostream>
#include <string>
#include <cstdio>
#include <cstring>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <cmath>
#include <sstream>
#include <algorithm>
#include <numeric>
#define mp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
using namespace std;
typedef long long ll;
const ll mod = 1000000007ll ;
ll mpow(ll p,ll q){
    p%=mod;
    ll ans=1;
    while(q){
        if(q&1)
            ans=ans*p%mod;
        q>>=1;
        p=p*p%mod;
    }
    return ans;
}
ll fac[1000005];
ll rev(ll n){return mpow(n,mod-2);}
ll C(int m, int n){
    return fac[m]*rev(fac[n]*fac[m-n]%mod)%mod;
}
int main()
{
    int n,a=0;
    scanf("%d",&n);
    fac[0]=1;
    for(int i=1;i<=n;++i)
        fac[i]=fac[i-1]*i%mod;
    for(int i=0,p;i<n;++i){
        scanf("%d",&p);
        if(p<=0){--n;--i;continue;}
        if(p==1)++a;
    }
    ll ans=1;
    for(int k=1;k+k<=a;++k)
        ans+=C(a,k+k)*fac[k+k]%mod*rev(mpow(2,k)*fac[k]%mod)%mod;
    ans=ans%mod*fac[n]%mod*rev(fac[a])%mod;
    cout<<ans<<endl;
    return 0;
}


#include <iostream>
#include <string>
#include <cstdio>
#include <cstring>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <cmath>
#include <sstream>
#include <algorithm>
#include <numeric>
#define mp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
using namespace std;
typedef long long ll;
const ll mod = 1000000007ll ;
ll mpow(ll p,ll q){
    p%=mod;
    ll ans=1;
    while(q){
        if(q&1)
            ans=ans*p%mod;
        q>>=1;
        p=p*p%mod;
    }
    return ans;
}
ll fac[2000005];
ll rev(ll n){return mpow(n,mod-2ll);}
ll C(int m, int n){
    return fac[m]*rev(fac[n]*fac[m-n]%mod)%mod;
}
int main()
{
    int n,a=0;
    scanf("%d",&n);
    fac[0]=1;
    for(int i=1;i<=n+n;++i)
        fac[i]=fac[i-1]*i%mod;
    for(int i=0,p;i<n;++i){
        scanf("%d",&p);
        if(p<=0){--n;--i;continue;}
        if(p==1)++a;
    }
    ll ans=1;
    for(int k=1;k+k<=a;++k)
        ans+=C(a,k+k)*fac[k+k]%mod*rev(mpow(2,k)*fac[k]%mod)%mod;
    ans=ans*fac[n]%mod*rev(fac[a])%mod;
    cout<<(ans+mod)%mod<<endl;
    return 0;
}


// Author: Ruchiose
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<cmath>
#define i64 long long
#define d64 long double
#define fortodo(i, f, t) for (i = f; i <= t; i++)
using namespace std;

const i64 MOD = int(1e+9) + 7;

int N;
i64 P[1000010];

int main()
{
    scanf("%d", &N);
    int C[3];
    C[1] = C[2] = 0;
    int i;
    fortodo(i, 1, N)
        {
            int u;
            scanf("%d", &u);
            C[u]++;
        }
    P[0] = P[1] = 1;
    fortodo(i, 2, C[1])
        P[i] = (P[i - 1] + (i - 1) * P[i - 2]) % MOD;
    i64 ans = P[C[1]];
    fortodo(i, 1, C[2])
        ans = ans * (C[1] + i) % MOD;
    cout << ans << endl;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <ctime>
#include <cassert>
#include <queue>

using namespace std;

#define f first
#define s second
#define mp make_pair
#define pb push_back
#define forit(it,con) for (typeof(con.begin()) it = con.begin(); it != con.end(); ++it)
#define f0(a) memset(a, 0, sizeof(a))
#define all(v) v.begin(), v.end()
#define pii pair<int,int>
#define vi vector<int>
#define ll long long

#ifdef WIN32
	#define I64 "%I64d"
#else
	#define I64 "%lld"
#endif
const int maxn = (int)2e6;
const int mod = (int)1e9 + 7;
int dp[maxn], n;

int main() {
	#ifdef LOCAL
		freopen("in","r",stdin);
	#endif
	scanf("%d", &n);
	dp[0] = dp[1] = 1;
	for (int i = 2; i <= n; ++i)
		dp[i] = (dp[i - 1] + 1ll * (i - 1) * dp[i - 2]) % mod;
	int one = 0, two = 0;
	for (int i = 0; i < n; ++i) {
		int x;
		scanf("%d", &x);
		if (x == 1) one++; else
		++two;
	}
	int ans = dp[one];
	for (int i = one + 1; i <= one + two; ++i)
		ans = (ans * 1ll * i) % mod;
	cout << ans << endl;
	return 0;
}


#include <cstdio>
#include <algorithm>
using namespace std;

typedef long long LL;
const LL modu = LL(1e9) + 7;

const int N = int(1e6) + 50;

LL I[N];

namespace parser {
	void solve () {
		int n, A = 0, B = 0;
		scanf("%d", &n);
		for (int i = 1, a; i <= n; ++i) {
			scanf("%d", &a);
			if (a == 1) ++A; else ++B;
		}

		LL res = 1;
		for (int i = A + B; i > A; --i)
			res = res * i % modu;

		I[0] = I[1] = 1;
		for (int i = 2; i <= n; ++i)
			I[i] = (I[i - 1] + (i - 1) * I[i - 2]) % modu;

		res = res * I[A] % modu;
		printf("%d\n", int((res % modu + modu) % modu));
	}
}

int main () {
#ifdef LOCAL
	freopen("in", "r", stdin);
#endif
	parser::solve();
	return 0;
}


#include <iostream>
#include <iomanip>
#include <sstream>
#include <fstream>
#include <string>
#include <cstdlib>
#include <cstdio>
#include <climits>
#include <cstring>
#include <ctime>
#include <cmath>
#include <cassert>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <algorithm>
#include <utility>
#include <numeric>
#include <functional>

#define forn(i, n) for (int i = 0; i < int(n); i++)
#define forl(i, n) for (int i = 1; i <= int(n); i++)
#define ford(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define fore(i, l, r) for (int i = int(l); i <= int(r); i++)
#define correct(x, y, n, m) (0 <= (x) && (x) < (n) && 0 <= (y) && (y) < (m))
#define all(a) (a).begin(), (a).end()
#define sz(a) int((a).size())
#define pb(a) push_back(a)
#define mp(x, y) make_pair((x), (y))
#define ft first
#define sc second
#define x first
#define y second

using namespace std;

typedef long long li;
typedef long double ld;
typedef pair<int, int> pt;

template<typename X> inline X abs(const X& a) { return a < 0? -a: a; }
template<typename X> inline X sqr(const X& a) { return a * a; }

const int INF = int(1e9);
const li INF64 = li(1e18);
const ld EPS = 1e-9, PI = 3.1415926535897932384626433832795;

const int N = 1000 * 1000 + 3;
const int mod = 1000000007;

int n;
int a[N];

inline bool read()
{
    if (scanf("%d", &n) != 1) return false;

    forn(i, n) assert(scanf("%d", &a[i]) == 1);

    return true;
}

inline int mul(int a, int b) { return int((a * 1ll * b) % mod); }
inline int add(int a, int b) { return int((a + 0ll + b) % mod); }

int z[N];

int solve(int n)
{
    if (n < 0) return 0;

    int& ans = z[n];
    if (ans != -1) return ans;

    if (n == 0) return ans = 1;

    return ans = add(solve(n - 1), mul(n - 1, solve(n - 2)));
}

int gcd(int a, int b, int& x, int& y)
{
    if (a == 0)
    {
        x = 0, y = 1;
        return b;
    }

    int xx, yy, g = gcd(b % a, a, xx, yy);

    x = yy - b / a * xx;
    y = xx;

    return g;
}

inline int inv(int a)
{
    int x, y;
    gcd(a, mod, x, y);
    x %= mod;
    if (x < 0) x += mod;

    return x;
}

int fact[N];

inline void solve()
{
    int cnt1 = 0, cnt2 = 0;

    forn(i, n)
    {
        cnt1 += int(a[i] == 1);
        cnt2 += int(a[i] == 2);
    }

    memset(z, -1, sizeof z);
    int ans = solve(cnt1);

    fact[0] = 1;
    forl(i, N - 1) fact[i] = mul(fact[i - 1], i);

    ans = mul(ans, fact[n]);
    ans = mul(ans, inv(fact[cnt1]));

    cout << ans << endl;
}

int main()
{
#ifdef SU2_PROJ
    freopen("input.txt", "rt", stdin);
    freopen("output.txt", "wt", stdout);
#endif

    cout << setprecision(10) << fixed;
    cerr << setprecision(5) << fixed;

    assert(read());
    solve();

    return 0;
}


#include <iostream>
using namespace std;
typedef long long ll;
const int mx=1000010;
ll mod=1000000007;
ll I[mx],aux;

int main(){
	I[0]=I[1]=1;
	for(int i=2; i<=1000000; i++){
		aux=I[i-2]*(i-1);
		//aux=aux%mod;
		I[i]=I[i-1]+aux;
		I[i]%=mod;
	}
	int N,a,b;
	cin>>N;
	a=b=0;
	for(int i=0; i<N; i++){
		cin>>aux;
		if(aux==1) a++;
		else b++;
	}
	aux=I[a];
	while(b){
		aux*=(a+(b--));
		aux%=mod;
	}
	cout<<aux<<endl;
	return 0;
}


#include <cstdio>
#include <algorithm>
#include <memory.h>
#include <time.h>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <set>
#include <map>
#include <string>
#include <cstring>
#include <sstream>
#include <fstream>
#include <stack>
#include <queue>
#include <vector>
#include <iomanip>
#include <iostream>
#include <assert.h>

#define ALL(x) x.begin(), x.end()
#define fill(a) memset(a, 0, sizeof(a))
#define abs(x) ((x)>0?(x):-(x))
#define sqr(x) (1ll*(x)*(x))
#define min(a,b) ((a)>(b)?(b):(a))
#define max(a,b) ((a)<(b)?(b):(a))
#define gcd(a,b) __gcd(a,b)
#define F first
#define S second
#define SS stringstream
#define CC(x) cout << x << endl
#define CCS(x) cout << x << " "
#define pw(x) (1ll<<(x))
#define pb push_back
#define mp make_pair
#define FIN freopen("1.in", "r", stdin)
#define FOUT freopen("1.out", "w", stdout)
#define FILE FIN; FOUT
#define SC(x) scanf("%d", &x)
#define PR(x) printf("%d\n", x)
#define PRS(x) printf("%d ", x)
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pair<int,int> >
#define forr(i, l, r) for (int i = l; i <= r; i++)
#define SRD srand((int)time(NULL))
#define GC getchar()

typedef long long LL;
typedef unsigned long long ULL;
typedef double DD;
typedef long double LD;
typedef unsigned char UC;
typedef unsigned int UI;
typedef unsigned short US;

using namespace std;

#define md 1000000007

int n, a, b, I[1111111];

int main(int argc, char * argv[])
{
        //ios_base::sync_with_stdio(0);
        //FIN;
        SC(n);
        forr(i, 1, n)
        {
                int x;
                SC(x);
                if (x == 1) a++; else b++;
        }
        I[0] = I[1] = 1;
        forr(i, 2, a) I[i] = (I[i-1] + 1ll*(i-1)*I[i-2])%md;
        int ans = 1;
        forr(i, a+1, a+b) ans = (1ll*ans*i)%md;
        ans = (1ll*I[a]*ans)%md;
        CC(ans);
        return 0;
}


#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <iostream>
#include <set>
#include <vector>
#include <cstring>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <complex>
#include <map>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef vector<pii> vii;
const int mod = 1000000007;

int main() {
    vl fac(100000, 1);
    for (int i = 1; i < fac.size(); ++i)
        fac[i] = fac[i-1] * i % mod;
    int n = 500;
    cin >> n;
    int a = 0, b = 0;
    for (int i = 0; i < n; ++i) {
        int x;
        scanf("%d", &x);
        if (x == 1)
            ++a;
        else ++b;
    }
    vvl d(n + 1, vl(n + 1));
    d[0][0] = 1;
    for (int i = 0; i <= min(n,a); ++i) for (int j = 0; j <= min(b, n-i); ++j) if (i+j) {
        if (i >= 1) {
            d[i][j] += d[i-1][j];
            ll mul = 1;
            for (int l = 1; l <= j; ++l) {
                mul = mul * (j-l+1) % mod;
                d[i][j] += d[i-1][j-l] * mul % mod;
            }
            if (i >= 2) {
                ll mul = i-1;
                for (int l = 0; l <= j; ++l) {
                    d[i][j] += d[i-2][j-l] * mul % mod * (l+1) % mod;
                    mul = mul * (j-l) % mod;
                }
            }
        } else {
            ll mul = 1;
            for (int l = 0; l <= j-1; ++l) {
                d[i][j] += d[i][j-1-l] * mul % mod;
                mul = mul * (j-1-l) % mod;
            }
        }
        d[i][j] %= mod;
    }
    cout << d[a][b] << endl;
    return 0;
}


#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <iostream>
#include <set>
#include <vector>
#include <cstring>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <complex>
#include <map>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef vector<pii> vii;
const int mod = 1000000007;

int main() {
    vl fac(100000, 1);
    for (int i = 1; i < fac.size(); ++i)
        fac[i] = fac[i-1] * i % mod;
    int n;
    cin >> n;
    int a = 0, b = 0;
    for (int i = 0; i < n; ++i) {
        int x;
        scanf("%d", &x);
        if (x == 1)
            ++a;
        else ++b;
    }
    vvl d(n + 1, vl(n + 1));
    d[0][0] = 1;
    for (int i = 0; i <= n; ++i) for (int j = 0; j <= n; ++j) if (i+j) {
        if (i >= 1) {
            d[i][j] += d[i-1][j];
            ll mul = 1;
            for (int l = 1; l <= j; ++l) {
                mul = mul * (j-l+1) % mod;
                d[i][j] += d[i-1][j-l] * mul % mod;
            }
            if (i >= 2) {
                ll mul = i-1;
                for (int l = 0; l <= j; ++l) {
                    d[i][j] += d[i-2][j-l] * mul % mod * (l+1) % mod;
                    mul = mul * (j-l) % mod;
                }
            }
        } else {
            ll mul = 1;
            for (int l = 0; l <= j-1; ++l) {
                d[i][j] += d[i][j-1-l] * mul % mod;
                mul = mul * (j-1-l) % mod;
            }
        }
        d[i][j] %= mod;
    }
    cout << d[a][b] << endl;
    return 0;
}


//#include <iostream>
#include <fstream>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <string>
#include <cmath>
#include <cassert>
#include <ctime>
#include <algorithm>
#include <sstream>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <cstdlib>
#include <cstdio>
#include <iterator>
#include <functional>
#include <bitset>
#define mp make_pair
#define pb push_back

#ifdef LOCAL
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
#else
#define eprintf(...)
#endif

#define TIMESTAMP(x) eprintf("["#x"] Time : %.3lf s.\n", clock()*1.0/CLOCKS_PER_SEC)
#define TIMESTAMPf(x,...) eprintf("[" x "] Time : %.3lf s.\n", __VA_ARGS__, clock()*1.0/CLOCKS_PER_SEC)

#if ( _WIN32 || __WIN32__ )
    #define LLD "%I64d"
#else
    #define LLD "%lld"
#endif

using namespace std;

#define TASKNAME "D"

typedef long long ll;
typedef long double ld;

const int MOD = 1000000007;

const int MAXN = 510;

int dp[MAXN][MAXN];
int c[MAXN][MAXN];

int main(){
  #ifdef LOCAL
    freopen(TASKNAME".in","r",stdin);
    freopen(TASKNAME".out","w",stdout);
  #endif
    int cnt1,cnt2;
    cnt1 = cnt2 = 0;
    int n;
    scanf("%d",&n);

    for (int i = 0; i < n; i++){
        int a;
        scanf("%d",&a);
        if (a == 1)
            cnt1++;
        else
            cnt2++;
    }

    dp[0][0] = 1;
    c[0][0] = 1;

//    cnt1 = cnt2 = 10;

    for (int i = 0; i <= cnt2; i++)
        for (int j = 0; j <= cnt2; j++){
            if (i) c[i][j] = (c[i][j] + c[i-1][j]) % MOD;
            if (i && j) c[i][j] = (c[i][j] + c[i-1][j-1]*1LL*j) % MOD;
        }

    for (int i = 0; i <= cnt1; i++)
        for (int j = 0; j <= cnt2; j++){
            if (i) {
                dp[i][j] = 0;
                for (int k = 0; k <= j; k++)
                    dp[i][j] = (dp[i][j] + dp[i-1][j-k]*1LL*c[j][k]) % MOD;
                if (i >= 2){
                    dp[i][j] = (dp[i][j] + dp[i-2][j] *1LL* (i-1)) % MOD;
                    for (int k = 1; k <= j; k++)
                        dp[i][j] = (dp[i][j] + ((dp[i-2][j-k]*1LL*c[j][k]) % MOD * 1LL*(i-1))%MOD *1LL* (k+1)) % MOD;
                }
            } else {
                if (j)
                    dp[i][j] = (dp[i][j-1] * 1LL* j) % MOD;
            }
            eprintf("%d%c",dp[i][j]," \n"[j==cnt2]);
        }

    printf("%d\n",dp[cnt1][cnt2]);

    TIMESTAMP(end);
    return 0;
}


//#include <iostream>
#include <fstream>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <string>
#include <cmath>
#include <cassert>
#include <ctime>
#include <algorithm>
#include <sstream>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <cstdlib>
#include <cstdio>
#include <iterator>
#include <functional>
#include <bitset>
#define mp make_pair
#define pb push_back

#ifdef LOCAL
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
#else
#define eprintf(...)
#endif

#define TIMESTAMP(x) eprintf("["#x"] Time : %.3lf s.\n", clock()*1.0/CLOCKS_PER_SEC)
#define TIMESTAMPf(x,...) eprintf("[" x "] Time : %.3lf s.\n", __VA_ARGS__, clock()*1.0/CLOCKS_PER_SEC)

#if ( _WIN32 || __WIN32__ )
    #define LLD "%I64d"
#else
    #define LLD "%lld"
#endif

using namespace std;

#define TASKNAME "D"

typedef long long ll;
typedef long double ld;

const int MOD = 1000000007;

const int MAXN = 510;

int dp[MAXN][MAXN];
int c[MAXN][MAXN];

int main(){
  #ifdef LOCAL
    freopen(TASKNAME".in","r",stdin);
    freopen(TASKNAME".out","w",stdout);
  #endif
    int cnt1,cnt2;
    cnt1 = cnt2 = 0;
    int n;
    scanf("%d",&n);

    for (int i = 0; i < n; i++){
        int a;
        scanf("%d",&a);
        if (a == 1)
            cnt1++;
        else
            cnt2++;
    }

    dp[0][0] = 1;
    c[0][0] = 1;

    for (int i = 0; i <= cnt2; i++)
        for (int j = 0; j <= cnt2; j++){
            if (i) c[i][j] = (c[i][j] + c[i-1][j]) % MOD;
            if (i && j) c[i][j] = (c[i][j] + c[i-1][j-1]*1LL*j) % MOD;
        }

    for (int i = 0; i <= cnt1; i++)
        for (int j = 0; j <= cnt2; j++){
            if (i) {
                dp[i][j] = 0;
                for (int k = 0; k <= j; k++)
                    dp[i][j] = (dp[i][j] + dp[i-1][j-k]*1LL*c[j][k]) % MOD;
                if (i >= 2){
                    dp[i][j] = (dp[i][j] + dp[i-2][j] * (i-1)) % MOD;
                    for (int k = 1; k <= j; k++)
                        dp[i][j] = (dp[i][j] + ((dp[i-2][j-k]*1LL*c[j][k]) % MOD * (i-1))%MOD * (k+1)) % MOD;
                }
            } else {
                if (j)
                    dp[i][j] = (dp[i][j-1] * 1LL* j) % MOD;
            }
//              eprintf("%d %d %d\n",i,j,dp[i][j]);
        }

    printf("%d\n",dp[cnt1][cnt2]);

    TIMESTAMP(end);
    return 0;
}


//#include <iostream>
#include <fstream>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <string>
#include <cmath>
#include <cassert>
#include <ctime>
#include <algorithm>
#include <sstream>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <cstdlib>
#include <cstdio>
#include <iterator>
#include <functional>
#include <bitset>
#define mp make_pair
#define pb push_back

#ifdef LOCAL
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
#else
#define eprintf(...)
#endif

#define TIMESTAMP(x) eprintf("["#x"] Time : %.3lf s.\n", clock()*1.0/CLOCKS_PER_SEC)
#define TIMESTAMPf(x,...) eprintf("[" x "] Time : %.3lf s.\n", __VA_ARGS__, clock()*1.0/CLOCKS_PER_SEC)

#if ( _WIN32 || __WIN32__ )
    #define LLD "%I64d"
#else
    #define LLD "%lld"
#endif

using namespace std;

#define TASKNAME "D"

typedef long long ll;
typedef long double ld;

const int MOD = 1000000007;

const int MAXN = 510;

int dp[MAXN][MAXN];
int c[MAXN][MAXN];

int main(){
  #ifdef LOCAL
    freopen(TASKNAME".in","r",stdin);
    freopen(TASKNAME".out","w",stdout);
  #endif
    int cnt1,cnt2;
    cnt1 = cnt2 = 0;
    int n;
    scanf("%d",&n);

    for (int i = 0; i < n; i++){
        int a;
        scanf("%d",&a);
        if (a == 1)
            cnt1++;
        else
            cnt2++;
    }

    dp[0][0] = 1;
    c[0][0] = 1;

    for (int i = 0; i <= cnt2; i++)
        for (int j = 0; j <= cnt2; j++){
            if (i) c[i][j] = (c[i][j] + c[i-1][j]) % MOD;
            if (i && j) c[i][j] = (c[i][j] + c[i-1][j-1]*1LL*j) % MOD;
        }

    for (int i = 0; i <= cnt1; i++)
        for (int j = 0; j <= cnt2; j++){
            if (i) {
                dp[i][j] = 0;
                for (int k = 0; k <= j; k++)
                    dp[i][j] = (dp[i][j] + dp[i-1][j-k]*1LL*c[j][k]) % MOD;
                if (i >= 2){
                    dp[i][j] = (dp[i][j] + dp[i-2][j] * (i-1)) % MOD;
                    for (int k = 1; k <= j; k++)
                        dp[i][j] = (dp[i][j] + (dp[i-2][j-k]*1LL*c[j][k]) % MOD * (i-1) * (k+1)) % MOD;
                }
            } else {
                if (j)
                    dp[i][j] = (dp[i][j-1] * 1LL* j) % MOD;
            }
//              eprintf("%d %d %d\n",i,j,dp[i][j]);
        }

    printf("%d\n",dp[cnt1][cnt2]);

    TIMESTAMP(end);
    return 0;
}


#include<iostream>
#include<cstdio>
#include<memory.h>
#include<string>
#include<cmath>
#include<cctype>
#include<algorithm>
#include<queue>
#include<set>
#include<map>
#include<stack>
#include<vector>
#include<functional>
#define sqr(x) ((x)*(x))
#define ll long long
#define ii pair<int,int>
#define mp make_pair
#define ms(x,y) memset(x,y,sizeof(x))
#define rep(x,y,z) for (int x=y;x<z;x++)
#define drep(x,y,z) for (int x=y;x>=z;x--)
#define all(x) x.begin(),x.end()
#define X first
#define Y second
using namespace std;
const int size=2100000,mod=1000000007 ,inf=0x3f3f3f3f;
const ll llmod=4294967296,llinf=0x3f3f3f3f3f3f3f3f;
const double pi=acos(-1.0),eps=1e-6;
int month[2][13]={0,31,28,31,30,31,30,31,31,30,31,30,31,
				  0,31,29,31,30,31,30,31,31,30,31,30,31};
int nex[2][8]={-1,0,1,0,-1,1,1,-1,0,1,0,-1,1,1,0,0};
template<class T> void inc(T &a,T b){a=(a+b)%mod;}
template<class T> T modu(T a){return (a%mod+mod)%mod;}
template<class T> void crl(T* l,T *r,int step){T tmp=*l;for (T* i=l;i<r;i+=step)*i=*(i+step);*(r-1)=tmp;}
template<class T> void crr(T* l,T *r,int step){T tmp=*(r-1);for (T* i=r-1;i>l;i-=step)*i=*(i-step);*l=tmp;}
bool dbeq(double a,double b){return fabs(a-b)<eps;}
template<class T> void cmin(T& a,T b){a=min(a,b);}
template<class T> void cmax(T& a,T b){a=max(a,b);}
/***********************************************************/
int n,a,one,two;
ll dp[size],ans;
int main ()
{

	cin>>n;
	rep(i,0,n)
		cin>>a,a==1?one++:two++;
	dp[0]=dp[1]=1;
	rep(i,2,one+1)
		dp[i]=(dp[i-1]+dp[i-2]*(i-1))%mod;
	ans=1;
	rep(i,0,two)
		ans=(ans*(one+1+i))%mod;
	printf("%I64d\n",ans*dp[one]%mod);
	return 0;
}


#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<fstream>
#include<map>
#include<ctime>
#include<set>
#include<queue>
#include<cmath>
#include<vector>
#include<bitset>
#include<functional>
#define x first
#define y second
#define mp make_pair
#define pb push_back
#define REP(i,l,r) for((i)=(l);(i)<=(r);++(i))
#define REP2(i,l,r) for((i)=(l);(i)!=(r);++(i))
using namespace std;

typedef long long LL;
typedef double ld;

const int MAX=1000000+10;
const int Mod=(int)1e9+7;
const int _MAX=1000;

int n;
int f[_MAX][_MAX],C[_MAX][_MAX],P[_MAX];

int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#endif
	int i,a,j;
	scanf("%d",&n);
	int B(0),A(0);
	REP(i,1,n)
	{
		scanf("%d",&a);
		if(a==2)
			++B;
	}
	A=n-B;
	C[0][0]=1;
	P[0]=1;
	REP2(i,1,_MAX)
	{
		P[i]=(LL)P[i-1]*i%Mod;
		C[i][0]=1;
		REP(j,1,i)
			C[i][j]=(C[i-1][j-1]+C[i-1][j])%Mod;
	}
	/*
	   每个循环中最多有两个1
	   其实我也不知道对不对啊
	   除掉所有只能是1的。。
	   ai->aj
	   aj为1
	   那么设aj->ak
	   那么ai得变成ak
	   这样ai最后必须有一次交换
	   即ai的交换次数为1。。的递归子问题，由于只是缩点，所以依旧是个轮换。
	   最终应该会变成一个对换
	   由于1的数目不会改变
	   那么。。。
	   1的数目最多为2
	   由此构造出答案。
	   我觉得我吊炸天了
	   */
	/*
	   以此为结论的算法
	   还剩a个1 和b个2
	   f[0][j]=j!
	   f[a][b]+=f[a-1][b-k]*A(b,k)
	   f[a][b]+=f[a-2][b-k]*(k+1)*A(b,k)
	   */
	REP(i,0,B)
		f[0][i]=P[i];
	REP(i,1,A)
		REP(j,0,B)
		{
			int k=0;
			REP(k,0,j)
			{
				f[i][j]+=(LL)f[i-1][j-k]*C[j][k]%Mod* P[k] %Mod;
				if(i>=2)
					f[i][j]+=(LL)f[i-2][j-k]*C[j][k] %Mod*P[k] %Mod * (k+1) %Mod * (i-1)%Mod;
			}
		}
	cout<<f[A][B]<<endl;
	return 0;
}


#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<fstream>
#include<map>
#include<ctime>
#include<set>
#include<queue>
#include<cmath>
#include<vector>
#include<bitset>
#include<functional>
#define x first
#define y second
#define mp make_pair
#define pb push_back
#define REP(i,l,r) for((i)=(l);(i)<=(r);++(i))
#define REP2(i,l,r) for((i)=(l);(i)!=(r);++(i))
using namespace std;

typedef long long LL;
typedef double ld;

const int MAX=1000000+10;
const int Mod=(int)1e9+7;
const int _MAX=1000;

int n;
int f[_MAX][_MAX],C[_MAX][_MAX],P[_MAX];

int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#endif
	int i,a,j;
	scanf("%d",&n);
	int B(0),A(0);
	REP(i,1,n)
	{
		scanf("%d",&a);
		if(a==2)
			++B;
	}
	A=n-B;
	C[0][0]=1;
	P[0]=1;
	REP2(i,1,_MAX)
	{
		P[i]=(LL)P[i-1]*i%Mod;
		C[i][0]=1;
		REP(j,1,i)
			C[i][j]=(C[i-1][j-1]+C[i-1][j])%Mod;
	}
	/*
	   每个循环中最多有两个1
	   其实我也不知道对不对啊
	   除掉所有只能是1的。。
	   ai->aj
	   aj为1
	   那么设aj->ak
	   那么ai得变成ak
	   这样ai最后必须有一次交换
	   即ai的交换次数为1。。的递归子问题，由于只是缩点，所以依旧是个轮换。
	   最终应该会变成一个对换
	   由于1的数目不会改变
	   那么。。。
	   1的数目最多为2
	   由此构造出答案。
	   我觉得我吊炸天了
	   */
	/*
	   以此为结论的算法
	   还剩a个1 和b个2
	   f[0][j]=j!
	   f[a][b]+=f[a-1][b-k]*A(b,k)
	   f[a][b]+=f[a-2][b-k]*(k+1)*A(b,k)
	   */
	REP(i,0,B)
		f[0][i]=P[i];
	REP(i,1,A)
		REP(j,0,B)
		{
			int k=0;
			REP(k,0,j)
			{
				f[i][j]+=(LL)f[i-1][j-k]*C[j][k]%Mod* P[k] %Mod;
				f[i][j]%=Mod;
				if(i>=2)
				{
					f[i][j]+=(LL)f[i-2][j-k]*C[j][k] %Mod*P[k] %Mod * (k+1) %Mod * (i-1)%Mod;
					f[i][j]%=Mod;
				}
			}
		}
	cout<<f[A][B]<<endl;
	return 0;
}


/*
 * in the name of god
 *
 *
 *
 *
 *
 *
 *
 *
 */

#include <iostream>
#include <fstream>
#include <sstream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <algorithm>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <complex>
#include <bitset>
#include <iomanip>
#include <utility>

using namespace std;

typedef long long LL;
typedef complex<double> point;
typedef long double ldb;
typedef pair<int,int> pii;

const int MAXN = 1000000+10;
const int mod = 1000000007;

int n,c1,c2;
int f[MAXN],df[MAXN];

inline int POWER (int base, int p){
	int ret = 1;
	int cur = base;
	while (p){
		if (p & 1)
			ret = (LL)ret * cur % mod;
		cur = (LL)cur * cur % mod;
		p>>=1;
	}
	return ret;
}

inline int getC (int n, int k){
	return (LL)f[n] * df[k] % mod * df[n-k] % mod;
}

int main(){
	ios_base::sync_with_stdio(false);
	cin >> n;
	for (int i=0; i<n; i++){
		int temp; cin >> temp;
		c1+= temp==1;
		c2+= temp==2;
	}
	f[0]=df[0]=1;
	for (int i=1; i<MAXN; i++){
		f [i] = (LL)f[i-1] * i % mod;
		df[i] = POWER(f[i], mod-2);
	}
	int ret = 0;
	for (int i=c1%2; i<=c1; i+=2){
		int temp = (LL)getC(c1,i) * f[c1-i] % mod * POWER(df[2],(c1-i)/2) % mod * df[(c1-i)/2] % mod;
		ret = (ret + (LL)temp * f[n] % mod * df[c1]) % mod;
	}
	cout << ret << endl;
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <map>
using namespace std;

const long long mod = 1e9+7;

long long fuck[1000010],a[1000010];

void work()
{
    int i;
    fuck[1]=1;
    fuck[2]=2;
    for(i=3;i<=1000000;i++)
        fuck[i]=(fuck[i-1]+((i-2)*fuck[i-2])%mod)%mod;
}

int main()
{
    int n,i,sum=0;
    scanf("%d",&n);
    work();
    for(i=1;i<=n;i++)
    {
        scanf("%I64d",&a[i]);
        if(a[i]==1)
            sum++;
    }
    long long ans=fuck[sum];
    for(i=sum+1;i<=n;i++)
    {
        ans=(ans*i)%mod;
    }
    printf("%I64d\n",ans);
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <map>
using namespace std;

const long long mod = 1e9+7;

long long fuck[1000010],a[1000010];

void work()
{
    int i;
    fuck[1]=1;
    fuck[2]=2;
    for(i=3;i<=1000000;i++)
        fuck[i]=(fuck[i-1]+((i-1)*fuck[i-2])%mod)%mod;
}

int main()
{
    int n,i,sum=0;
    scanf("%d",&n);
    work();
    for(i=1;i<=n;i++)
    {
        scanf("%I64d",&a[i]);
        if(a[i]==1)
            sum++;
    }
    long long ans=fuck[sum];
    for(i=sum+1;i<=n;i++)
    {
        ans=(ans*i)%mod;
    }
    printf("%I64d\n",ans);
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <map>
using namespace std;

const long long mod = 1e9+7;

long long fuck[1000010],a[1000010];

void work()
{
    int i;
    fuck[0]=1;
    fuck[1]=1;
    fuck[2]=2;
    for(i=3;i<=1000000;i++)
        fuck[i]=(fuck[i-1]+((i-1)*fuck[i-2])%mod)%mod;
}

int main()
{
    int n,i,sum=0;
    scanf("%d",&n);
    work();
    for(i=1;i<=n;i++)
    {
        scanf("%I64d",&a[i]);
        if(a[i]==1)
            sum++;
    }
    long long ans=fuck[sum];
    for(i=sum+1;i<=n;i++)
    {
        ans=(ans*i)%mod;
    }
    printf("%I64d\n",ans);
    return 0;
}


#include <algorithm>
#include <stdio.h>
#define  maxn      1000005
#define  mod       1000000007
using    namespace std;
typedef  long long LL;

LL n,c1,c2,ans;
LL dp[maxn];

int main()
{
  scanf("%I64d",&n);
  for(LL i=0,x ; i<n ; i++)
  {
    scanf("%I64d",&x);
    if(x==1) c1++;
    else     c2++;
  }
  dp[0]=1;
  for(LL i=1 ; i<=c1 ; i++)
    dp[i]=(dp[i-1]+(i-1)*dp[i-2])%mod;
  ans=dp[c1];
  for(LL i=c1+1 ; i<=n ; i++)
    ans=(ans*i)%mod;
  printf("%I64d\n",ans);
  return 0;
}


#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<set>
#include<vector>
#define REP(i,m) for(int i=0;i<m;++i)
#define REPN(i,m,in) for(int i=in;i<m;++i)
#define ALL(t) (t).begin(),(t).end()
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define dump(x)  cerr << #x << " = " << (x) << endl
#define prl cerr<<"called:"<< __LINE__<<endl
using namespace std;
static const int INF =500000000;
template<class T> void debug(T a,T b){ for(;a!=b;++a) cerr<<*a<<' ';cerr<<endl;}
typedef long long int lint;
typedef pair<int,int> pi;
int n;
int one,two;
lint base[1000005];
const lint mod=1000000007;
int main(){
	int n;
	scanf("%d",&n);
	int one=0,two=0;
	REP(i,n) {
		int t;scanf("%d",&t);
		if(t==1) ++one;
		else ++two;
	}

	base[0]=base[1]=1;
	for(int i=2;i<=one;++i){
		base[i]=base[i-1]+base[i-2]*(i-1);
		base[i]%=mod;
	}

	lint res=base[one];
	REP(i,two){
		res*=one+1+i;
		res%=mod;
	}
	cout<<res<<endl;

	return 0;
}


#include <iostream>
#include <iomanip>
#include <stdio.h>
#include <set>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#include <memory.h>
#include <string>
#include <sstream>

using namespace std;

const int md = 1000000007;

int g[1111111];

int main() {
  int n;
  scanf("%d", &n);
  int k1 = 0, k2 = 0;
  for (int i=0;i<n;i++) {
    int foo;
    scanf("%d", &foo);
    if (foo == 1) k1++;
    else k2++;
  }
  g[0] = 1;
  for (int i=1;i<=k1;i++) g[i] = (g[i-1] + (long long)g[i-2] * (i-1)) % md;
  int ans = g[k1];
  for (int i=1;i<=k2;i++) ans = (long long)ans * (k1+i) % md;
  printf("%d\n", ans);
  return 0;
}


#include <cstdio>
#include <cstring>

const long long mod = 1000000007;

long long qpow( long long v, long long st )
{
	long long r = 1;
	while ( st )
	{
		if ( st&1 )
		{
			r *= v;
			r %= mod;
		}
		v = v * v;
		v %= mod;
		st = st / 2;
	}
	return r;
}

long long f[1024];
long long dp[1024][1024];
long long sdp[1024][1024];

long long getDP( int,int );

long long getSdp( int b1, int b2 )
{
	if ( sdp[b1][b2] != -1 )
		return sdp[b1][b2];
	if ( b2 == 0 )
		return getDP( b1-2, 0 );
	sdp[b1][b2] = getSdp( b1, b2-1 ) + getDP( b1-2, b2 )*qpow( f[b2], mod-2 );
	sdp[b1][b2] %= mod;
	return sdp[b1][b2];
}

long long getDP( int b1, int b2 )
{
	if ( dp[b1][b2] != -1 )
		return dp[b1][b2];
	if ( !b1 )
		return f[b2];

	long long sol = 0;
	if ( b1 >= 2 )
	{
		long long p = getSdp( b1, b2 );
		p *= f[b2]; p%= mod; p *= (b1-1); p %= mod;
		sol += p;
		sol %= mod;
	}
	if ( b2 > 0 )
	{
		sol += getDP( b1, b2-1 )*b2;
		sol %= mod;
	}
	sol += getDP( b1-1, b2 );
	dp[b1][b2] = sol;

	return dp[b1][b2];
}

int main()
{
	int i, j, k;
	f[0] = 1;
	for ( i = 1; i <= 1000; i++ )
	{
		f[i] = f[i-1]*i;
		f[i] %= mod;
	}

	j = k = 0;
	int n, l;
	scanf( "%d", &n );
	for ( i = 0; i < n; i++)
	{
		scanf( "%d", &l );
		if ( l == 1 )
			j++;
		else
			k++;
	}

	memset( dp, -1, sizeof( dp ) );
	memset( sdp, -1, sizeof( sdp ) );

	printf( "%d\n", (int) getDP( j, k ) );

	return 0;
}


#include <cstdio>
#include <cstring>

const long long mod = 1000000007;

long long qpow( long long v, long long st )
{
	long long r = 1;
	while ( st )
	{
		if ( st&1 )
		{
			r *= v;
			r %= mod;
		}
		v = v * v;
		v %= mod;
		st = st / 2;
	}
	return r;
}

long long f[1024];
long long dp[1024][1024];
long long sdp[1024][1024];

long long getDP( int,int );

long long getSdp( int b1, int b2 )
{
	if ( sdp[b1][b2] != -1 )
		return sdp[b1][b2];
	if ( b2 == 0 )
		return getDP( b1-2, 0 );
	sdp[b1][b2] = getSdp( b1, b2-1 ) + getDP( b1-2, b2 )*qpow( f[b2], mod-2 );
	sdp[b1][b2] %= mod;
	return sdp[b1][b2];
}

long long getDP( int b1, int b2 )
{
	if ( dp[b1][b2] != -1 )
		return dp[b1][b2];
	if ( !b1 )
		return f[b2];

	long long sol = 0;
	if ( b1 >= 2 )
	{
		long long p = getSdp( b1, b2 );
		p *= f[b2]; p%= mod; p *= (b1-1); p %= mod;
		sol += p;
		sol %= mod;
	}
	if ( b2 > 0 )
	{
		sol += getDP( b1, b2-1 )*b2;
		sol %= mod;
	}
	sol += getDP( b1-1, b2 );
	if ( sol >= mod )
		sol %= mod;
	dp[b1][b2] = sol;

	return dp[b1][b2];
}

int main()
{
	int i, j, k;
	f[0] = 1;
	for ( i = 1; i <= 1000; i++ )
	{
		f[i] = f[i-1]*i;
		f[i] %= mod;
	}

	j = k = 0;
	int n, l;
	scanf( "%d", &n );
	for ( i = 0; i < n; i++)
	{
		scanf( "%d", &l );
		if ( l == 1 )
			j++;
		else
			k++;
	}

	memset( dp, -1, sizeof( dp ) );
	memset( sdp, -1, sizeof( sdp ) );

	printf( "%d\n", (int) getDP( j, k ) );

	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#define mod 1000000007
#define ll long long

using namespace std;

int a[1000];
ll f[1000001], fi[1000001];
ll pd[1000001];

ll fexp(ll n, ll e)
{
    if(e == 0) return 1;
    if(e == 1) return n;
    if(e%2 == 0) return fexp((1ll * n * n)%mod,e/2);
    return (1ll * n * fexp(n,e-1))%mod;
}

ll inv(ll n) { return fexp(n,mod-2); }

int main()
{
    int n, c1=0;
    cin >> n;
    f[0] = 1;
    pd[0] = 1;
    pd[1] = 1;
    for(int i=1;i<1000001;i++) f[i] = (f[i-1]*i)%mod;
    for(int i=0;i<1000001;i++) fi[i] = inv(f[i]);
    for(int i=2;i<1000001;i++) pd[i] = (pd[i-1] + ((i-1)*pd[i-2])%mod)%mod;
    for(int i=0;i<n;i++)
    {
        cin >> a[i];
        if(a[i] == 1) c1++;
    }
    cout << (((pd[c1]*f[n])%mod)*fi[c1])%mod<< endl;
    return 0;
}


#include <iostream>
#include <cmath>
#include <algorithm>
#include <set>
#include <map>
#include <string>
#include <cstring>
#include <cstdio>
#include <vector>
#include <stack>
#include <queue>
#include <ctime>

using namespace std;

#define f first
#define s second
#define pb push_back
#define mp make_pair
#define forit(s) for(__typeof(s.begin()) it = s.begin(); it != s.end(); it ++)
#define N 1000100
#define all(a) a.begin(), a.end()
#define ll long long
#define pii pair <int, int>
#define sz(a) (int)a.size()
#define vi vector <int>

const int inf = (int)(1e9);
const int mod = inf + 7;
const double pi = acos(-1.0);
const double eps = 1e-9;

ll d[N], f[N];
ll fact[N];
ll inv[N];

int binpow(int a, int k) {
    if(k == 0) return 1;
    int res = binpow(a, k / 2);
    res = (res * 1ll * res) % mod;
    if(k % 2) res = (res * 1ll * a) % mod;
    return res;
}

int inverse(int a) {
    return binpow(a, mod - 2);
}

int main () {

    #ifdef LOCAL
    freopen("a.in", "r", stdin);
    freopen("a.out", "w", stdout);
    #endif

    fact[0] = 1;
    for(int i = 1; i < N; i ++) fact[i] = (fact[i - 1] * 1ll * i) % mod;
    for(int i = 0; i < N; i ++) inv[i] = inverse(fact[i]);
    d[0] = 1;
    d[1] = 1;
    for(int i = 2; i < N; i ++) d[i] = (d[i - 1] + ((i - 1) * 1ll * d[i - 2]) % mod) % mod;

    int n, x, k1 = 0, k2 = 0;

    cin >> n;
    for(int i = 0; i < n; i ++) {
        cin >> x;
        k1 += (x == 1);
        k2 += (x == 2);
    }

    cout << ((fact[k1 + k2] * inv[k1]) % mod * d[k1]) % mod;

    return 0;
}


/***********************************************
* Author - LUONG VAN DO                        *
* Problem
* Algorithm
* Time Limit
* *********************************************/
#include <iostream>
#include <stdio.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <math.h>
#include <cstring>
#include <string.h>
#include <stdlib.h>
#include <algorithm>

#define FileIn(file) freopen(file".inp", "r", stdin)
#define FileOut(file) freopen(file".out", "w", stdout)
#define fr(i, a, b) for (int i=a;i<=b;i++)
#define frr(i, a, b) for (int i = b;i >= a;i--)
#define rep(i, n) for (int i=0; i<n; i++)
#define repr(i, n) for (int i = n - 1;i >= 0;i--)
#define pb push_back
#define ff first
#define ss second
#define fill(arr, val) memset(arr, val, sizeof(arr))
#define PI 3.1415926535897932385
#define uint64 unsigned long long
#define int64 long long
#define uint32 unsigned int
#define INF 1000000000
#define N 1000100
#define mod 1000000007
using namespace std;

inline int max(int a, int b) { return a > b ? a : b; }
inline int min(int a, int b) { return a < b ? a : b; }
inline int gcd(int a, int b) { if (a % b) return gcd(b, a % b); else return b; }
inline int lcm(int a, int b) { return (a * (b / gcd(a, b) )); }

inline int And(int mask, int bit) { return mask & (1 << bit); }
inline int Or(int mask, int bit) { return mask | (1 << bit); }
inline int Xor(int mask, int bit) { return mask & (~(1 << bit)); }

typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
int64 dp[N], f[N], ans;
int x, n, cnt;
int64 power(int64 x, int y) {
    int64 res = 1LL;
    while ( y ) {
        if (y & 1) res = (res * x) % mod;
        y >>= 1;
        x = (x * x) % mod;
    }
    return res;
}
int main() {
	//freopen("exam.inp","r", stdin); freopen("exam.out","w", stdout);
	dp[0] = dp[1] = 1LL;
	f[0] = f[1] = 1LL;
	fr(i, 2, 1000000) {
	    dp[i] = (dp[i - 1] + (i - 1) * dp[i - 2]) % mod;
	    f[i] = (f[i - 1] * i) % mod;
	}
	scanf("%d", &n); cnt = 0;
	rep(i, n) {
	    scanf("%d", &x);
	    if (x == 1) cnt++;
	}
	ans = (f[n] * dp[cnt]) % mod;
	ans *= power(f[cnt], mod - 2);
	ans %= mod; printf("%I64d\n", ans);
	return 0;
}


#include <cstdio>
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <ctime>
#include <cstring>
#include <cassert>
#include <bitset>
#include <sstream>
#include <queue>

using namespace std;

typedef long long int64;
typedef pair <int, int> pii;
typedef long double ldb;

const long double eps = 1e-9;
const int inf = (1 << 30) - 1;
const int64 inf64 = ((int64)1 << 62) - 1;
const long double pi = 3.1415926535897932384626433832795;

template <class T> T sqr (T x) {return x * x;}
template <class T> T abs (T x) {return x < 0 ? -x : x;}

const int mod = 1000000007;

long long sum (long long a, long long b)
{
    return (a + b) % mod;
}

long long prod (long long a, long long b)
{
    return (a * b) % mod;
}

int main ()
{
//  freopen("input.txt", "rt", stdin);
//  freopen("output.txt", "wt", stdout);

    int n, n1 = 0, n2 = 0;
    cin >> n;
    for (int i = 0; i < n; ++i)
    {
        int t;
        cin >> t;
        if (t ==  1) n1++;
        else n2++;
    }

    long long m = 1;
    long long m_old = 1;
    for (int i = 2; i <= n1; ++i)
    {
        long long m_new = sum(m, prod(m_old, i - 1));
        m_old = m;
        m = m_new;
    }

    for (int i = 0; i < n2; ++i)
    {
        m = prod (m, n1 + i + 1);
    }

    cout << m << endl;

    return 0;
}


#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <string>
#include <vector>
#include <bitset>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <numeric>
#include <cstring>
#include <climits>
#include <cassert>
#include <limits.h>
#include <iostream>
#include <algorithm>
#include <functional>
#define eps 1E-5
#define pi acos(-1.0)
#define X first
#define Y second
#define ll long long
#define PB(x) push_back((x))
#define MP(x,y) make_pair((x),(y))
#define CLR(x) memset((x),0,sizeof((x)))
using namespace std;
const int                           Maxn=300005,Maxm=100005,Mo=1000000007
                                    ,step[4][2]={{0,1},{0,-1},{1,0},{-1,0}};
const ll                            oo=INT_MAX>>2;
struct Tree{
    int x,y;
};
struct edge {
    int v,c,w,Ft;
};
struct point {
    ll x,y;
};
typedef pair<ll,ll>                     F;
typedef int                             IArr[Maxn];
typedef ll                              LArr[Maxn];
typedef double                          DArr[Maxn];

int                                     n,m,i,s1,s2;
LArr                                    f;

int main()
{
    ios::sync_with_stdio(0);
//    freopen("/Users/MAC/Desktop/Error202/Error202/1.in","r",stdin);
//    freopen("/Users/MAC/Desktop/Error202/Error202/1.out","w",stdout);
    cin>>n;
    for (i=1;i<=n;i++) {
        int a;
        cin>>a; if (a==1) s1++;
    }
    f[1]=f[0]=1;
    f[2]=2;
    for (int i=3;i<=s1;i++) f[i]=(f[i-1]+(i-1)*f[i-2])%Mo;
    ll tmp=1;
    for (i=s1+1;i<=n;i++) tmp=tmp*i%Mo;
    cout<<f[s1]*tmp%Mo<<endl;
}


#include <bits/stdc++.h>
#define pb push_back
#define mk make_pair
#define fi first
#define se second
#define For(i,a,b) for(int (i)=(a);(i) < (b); ++(i))

using namespace std;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef long long ll;
typedef vector<bool> vb;

const int INF=0x3f3f3f3f;
const int mod=1e9+7, N=555;
int n, v[N];
int choose[N][N];
int dp[N][N];
ll fat[N];

void prep() {
    choose[0][0]=1;
    for(int i=1;i<N;i++) {
	choose[i][0]=1;
	for(int j=1;j<i;j++)
	    choose[i][j]=(choose[i-1][j]+choose[i-1][j-1])%mod;
	choose[i][i]=1;
    }
    fat[0]=fat[1]=1;
    for(int i=2;i<N;i++)
	fat[i]=1LL*fat[i-1]*i%mod;
}
int f(int c1, int c2) {
    if(!c1)
	return fat[c2];
    int &ret=dp[c1][c2];
    if(ret!=-1)return ret;
    ret=0;
    for(int j=0;j<=c2;j++) {
	if(c1>0)
	    ret=(ret+1LL*f(c1-1, c2-j)*choose[c2][j]%mod*fat[j]%mod)%mod;
	if(c1>1)
	    ret=(ret+1LL*f(c1-2, c2-j)*(c1-1)%mod*choose[c2][j]%mod*fat[j+1]%mod)%mod;
    }
    //cout<<c1<<","<<c2<<": "<< " "<<ret<<"@\n";
    return ret;
}

int main(void) {
	ios::sync_with_stdio(false);
	prep();
	cin>>n;
	int c1=0, c2=0;
	For(i,0,n){
	    cin>>v[i];
	    if(v[i]==1)c1++;
	    else c2++;
	}
	memset(dp,-1,sizeof dp);
	ll ans=f(c1, c2);
	cout<<ans<<endl;

	return 0;
}


#include <iostream>
#include <algorithm>

using namespace std;

const int MOD = 1000000007;

int N, n1, n2;
int P[1000002];

int main()
{
    cin >> N;
    for (int i = 1, val; i <= N; ++i)
    {
        cin >> val;
        if (val == 1) ++n1;
        else          ++n2;
    }

    P[0] = 1;
    P[1] = 1;
    for (int i = 2; i <= n1; ++i)
        P[i] = (P[i - 1] + 1LL * (i - 1) * P[i - 2]) % MOD;

    int result = P[n1];
    for (int i = n1 + 1; i <= n1 + n2; ++i)
        result = 1LL * result * i % MOD;

    cout << result << '\n';
}


#include <cstdio>
#include <vector>
#include <cstring>
#include <functional>
#include <algorithm>
#include <math.h>
#include <bitset>
#include <set>
#include <queue>
#include <assert.h>
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <complex>
#include <numeric>
#include <map>
#include <time.h>
using namespace std;
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef pair<int,int> pii;
typedef pair<int,ll> pil;
typedef pair<int,ull> piu;
typedef pair<ll,int> pli;
typedef pair<ll,ll> pll;
typedef pair<pii,ll> ppl;
typedef pair<ll,pii> plp;
typedef pair<ll,pll> plP;
typedef pair<int,pii> pip;
typedef pair<pii,int> ppi;
typedef pair<pii,pii> ppp;
typedef pair<double,int> pdi;
typedef pair<int,double> pid;
typedef pair<double,pii> pdp;
typedef pair<double,double> pdd;
typedef pair<pdd,double> pd3;
typedef vector<int> vec;
typedef vector<vec> mat;
#define rep(i,n) for (int (i) = 0; (i) < (n); (i)++)
#define repn(i,a,n) for (int (i) = (a); (i) < (n); (i)++)
#define ALL(x) (x).begin(),(x).end()
#define pb push_back
#define SORT(x) sort((x).begin(),(x).end())
#define SORTN(x,n) sort((x),(x)+(n))
#define ERASE(x) (x).erase(unique((x).begin(),(x).end()),(x).end())
#define COUNT(x,c) count((x).begin(),(x).end(),(c))
#define REMOVE(x,c) (x).erase(remove((x).begin(),(x).end(),(c)),(x).end())
#define REVERSE(x) reverse((x).begin(),(x).end())
#define FORIT(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))-(x).begin()
#define lb(x,a) lower_bound((x).begin(),(x).end(),(a))
#define LBN(x,a,n) lower_bound((x),(x)+(n),(a))-(x)
#define lbN(x,a,n) lower_bound((x),(x)+(n),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))-(x).begin()
#define ub(x,a) upper_bound((x).begin(),(x).end(),(a))
#define BS(x,a) binary_search((x).begin(),(x).end(),(a))
#define BS2(x,n,a) binary_search((x),(x)+(n),(a))
#define NB(x) (((x)&~((x)+((x)&-(x))))/((x)&-(x))>>1)|((x)+((x)&-(x)))
#define NP(x) next_permutation((x).begin(),(x).end())
#define MM(x,p) memset((x),(p),sizeof(x))
#define SQ(x) (x)*(x)
#define SC(c1,c2) strcmp(c1,c2)==0
#define mp make_pair
#define INF (1<<28)
#define INFL (1LL<<61)
#define fi first
#define se second
#define MOD 1000000007
#define EPS 1e-9
#define MIN(x,a) x=min(x,a)
#define MAX(x,a) x=max(x,a)
#define madd(x,a) x=(x+a)%MOD
#define msub(x,a) x=(x+MOD-a)%MOD
#define OUTPUT(x) rep(i,x.size())printf("%d%c",x[i],i+1==x.size()?'\n':' ');

int N,A,c1,c2;
int tt[1145141];

int main()
{
    scanf("%d",&N);
    rep(i,N)scanf("%d",&A),c1+=(A==1),c2+=(A==2);
    tt[1]=tt[0]=1;
    repn(i,2,c1+1)tt[i]=(ll(tt[i-2])*(i-1)+tt[i-1])%MOD;
    int res=tt[c1];
    repn(i,c1+1,c1+c2+1)res=ll(res)*i%MOD;
    printf("%d\n",res);
}


#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#define mod 1000000007
#define int64 long long
#define N 1000010
#define For(i,x,y) for (i=x;i<=y;i++)
using namespace std;
int i,j,k,n,m,n1,n2;
int64 h[N],v[N],an,re,w[N];
inline int64 pow(int64 x,int64 y) {
	int64 an=1;
	for (;y;y>>=1) {
		if (y&1) an=an*x%mod;
		x=x*x%mod;
	} return an;
}
inline int64 C(int n,int m) {
	return h[n]*v[m]%mod*v[n-m]%mod;
}
int main() {
	scanf("%d",&n);
	For(i,1,n) {
		scanf("%d",&k);
		if (k==1) n1++;
		if (k>1) n2++;
	}
	h[0]=v[0]=1; For(i,1,n) h[i]=h[i-1]*i%mod,v[i]=pow(h[i],mod-2);
	w[0]=1; For(i,1,n) w[i]=w[i-1]*2%mod;
	For(i,1,n) w[i]=pow(w[i],mod-2);
	For(i,0,n1/2) an+=C(n1,i)*C(n1-i,i)%mod*h[i]%mod*w[i]%mod;
	an%=mod; int k=n1?n2:0;
	For(i,0,k) re+=(n1?h[n1+i-1]*v[n1-1]:1)%mod*C(n2,i)%mod*h[n2-i]%mod;
	re%=mod;
	printf("%I64d\n",an*re%mod);
	//for(;;);
	return 0;
}


#include<cstdio>
#define MAX   1000010
typedef long long ll;
const ll mod=(ll)1e9+7;
ll f[MAX];
int n,c;
void process(void) {
    scanf("%d",&n);
    int i,t;
    for (i=1;i<=n;i=i+1) {
        scanf("%d",&t);
        if (t==1) c++;
    }
    f[0]=1LL;
    f[1]=1LL;
    for (i=2;i<=c;i=i+1)
        f[i]=(f[i-1]+f[i-2]*(i-1))%mod;
    ll res=f[c];
    for (i=c+1;i<=n;i=i+1) res=(res*i)%mod;
    printf("%I64d",res);
}
int main(void) {
    process();
    return 0;
}


#include <iostream>
using namespace std;

int main()
{
	ios_base::sync_with_stdio(false);
	int n, m(0), x;
	cin >> n;
	for (int i = 0; i < n; ++i) {
		cin >> x;
		if (x == 1) m++;
	}

	const int mod = 1e9+7;
	long long a[2] = {1,1};
	for (int i = 1; i < m; ++i)
		if (i%2) a[0] = (a[1]+i*a[0])%mod;
		else a[1] = (a[0]+i*a[1])%mod;

	long long ans = a[m%2];
	for (int i = m+1; i <= n; ++i)
		ans = (ans*i)%mod;
	cout << ans;
	return 0;
}


#include <cstdio>
#include <cstring>
#define MOD 1000000007
using namespace std;
typedef long long Lint;
Lint n;
Lint a,b;
Lint fac[1000010];
Lint fast_exp(Lint a,Lint m)
{
	if(!m) return 1;
	Lint k=fast_exp(a,m/2);
	if(m&1) return (((k*k)%MOD)*a)%MOD;
	return (k*k)%MOD;
}
Lint bol(Lint a,Lint b)
{
	return (a*fast_exp(b,MOD-2))%MOD;
}
Lint comb(Lint t)
{
	return (t*(t-1)/2)%MOD;
}
Lint birler()
{
	Lint p,r;
	Lint res=1;
	Lint carp=1;
	for(Lint x=1;x<=a/2;x++)
	{
		p=comb(a+2-x*2);
		carp*=p;
		carp%=MOD;
		res+=bol(carp,fac[x]);
		res%=MOD;
	}
	return res;
}
Lint ikiler()
{
	Lint res=fac[b];
	Lint carp=1;
	for(Lint c=1;c<=b;c++)
	{
		carp*=a+c-1;
		carp%=MOD;
		res+=(carp*bol(fac[b],fac[c]));
		res%=MOD;
	}
	return res;
}

int main()
{
	fac[0]=1;
	for(Lint i=1;i<=1000000;i++) fac[i]=(fac[i-1]*i)%MOD;
	scanf(" %I64d",&n);
	for(Lint i=1;i<=n;i++)
	{
		Lint x;
		scanf(" %I64d",&x);
		if(x==1) a++;
		if(x==2) b++;
	}
	printf("%I64d\n",(birler()*ikiler())%MOD);
	return 0;
}


/*************************************************************************
	> File Name: 316D2.cpp
	> Author: Canoe
	> Mail: canoefzh@gmail.com
	> Created Time: Sat 03 Aug 2013 09:30:12 PM CST
 ************************************************************************/

#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <ctime>
#include <cmath>
#include <cassert>
#include <sstream>
#include <fstream>

using namespace std;

const int N = 1000086;
const int mod = 1000000007;

typedef long long lint;

lint f[N];

lint gao(int one, int two)
{
	f[0] = 1;
	for(int i = 1; i < N; i++)
	{
		f[i] = f[i - 1];
		if(i >= 2)
		{
			f[i] = (f[i] + (i - 1) * f[i - 2]) % mod;
		}
	}
	lint re = f[one];
	for(int i = 0; i < two; i++)
		re = re * (one + i + 1) % mod;
	return re;
}

int main()
{
//	freopen("in.txt", "r", stdin);
	int n, dat;
	while(cin >> n)
	{
		int one = 0, two = 0;
		for(int i = 0; i < n; i++)
		{
			cin >> dat;
			if(dat == 1)
				one++;
			else two++;
		}
		lint ans = gao(one, two);
		cout << ans << endl;
	}
	return 0;
}


/*************************************************************************
	> File Name: 316D2.cpp
	> Author: Canoe
	> Mail: canoefzh@gmail.com
	> Created Time: Sat 03 Aug 2013 09:30:12 PM CST
 ************************************************************************/

#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <ctime>
#include <cmath>
#include <cassert>
#include <sstream>
#include <fstream>

using namespace std;

const int N = 1000086;
const int mod = 1000000007;

typedef long long lint;

lint f[N];

lint gao(int one, int two)
{
	f[0] = 1;
	for(int i = 1; i < N; i++)
	{
		f[i] = f[i - 1];
		if(i >= 2)
		{
			f[i] = (f[i] + (i - 1) * f[i - 2]) % mod;
		}
	}
	lint re = f[one];
	for(int i = 0; i < two; i++)
		re = re * (one + i + 1) % mod;
	return re;
}

int main()
{
	freopen("in.txt", "r", stdin);
	int n, dat;
	while(cin >> n)
	{
		int one = 0, two = 0;
		for(int i = 0; i < n; i++)
		{
			cin >> dat;
			if(dat == 1)
				one++;
			else two++;
		}
		lint ans = gao(one, two);
		cout << ans << endl;
	}
	return 0;
}


#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;

#define MOD 1000000007
long long dp[51][51]; // used long long to avoid
long long C[51][51]; // going around casting
long long fact[51]; // all over the place

long long solve(int n, int m)
{
	if (dp[n][m] != -1)	return dp[n][m];
	long long ans = 0;
	if ( n == 0 ) // no twos
	{
		// choose cycle for largest numbered 1
		for (int i = 0; i < min(2,m); i++)
			ans = (ans + ((C[m-1][i] * solve(n,m-1-i)) % MOD) ) % MOD;
		return ans;
	}
	// choose cycle for largest numbered 2
	for (int i = 0; i < n; i++) // number of extra 2
		for (int j = 0; j <= min(2,m); j++) // number of 1
		{
			ans += ( ((C[n-1][i] * ( ( C[m][j] * fact[i+j]) % MOD) ) % MOD) * solve(n-1-i,m-j) ) % MOD;
			ans %= MOD;
		}
	return dp[n][m] = ans;
}

int main(void)
{
	int N;
	scanf("%i",&N);
	int n = 0, m = 0;
	for (int i = 0; i < N; i++)
	{
		int o;
		scanf("%i",&o);
		if (o == 1) m++;
		else n++;
	}
	// compute binomial coefficients
	C[0][0] = 1;
	for (int i = 1; i <= 50; i++)
		C[0][i] = 0, C[i][0] = 1;
	for (int i = 1; i <= 50; i++)
		for (int j = 1; j <= 50; j++)
			C[i][j] = (C[i-1][j] + C[i-1][j-1]) % MOD;
	// compute factorials
	fact[0] = 1;
	for (int i = 1; i <= 50; i++)
		fact[i] = (fact[i-1] * i) % MOD;
	// initial values
	memset(dp, (-1ll), sizeof(dp));
	dp[0][0] = 1; // (0,0) -> 1
	cout << solve(n,m) << endl;
	return 0;
}


#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;

#define MOD 1000000007
long long dp[501][501]; // used long long to avoid
long long C[501][501]; // going around casting
long long fact[501]; // all over the place

long long solve(int n, int m)
{
	if (dp[n][m] != -1)	return dp[n][m];
	long long ans = 0;
	if ( n == 0 ) // no twos
	{
		// choose cycle for largest numbered 1
		for (int i = 0; i < min(2,m); i++)
			ans = (ans + ((C[m-1][i] * solve(n,m-1-i)) % MOD) ) % MOD;
		return ans;
	}
	// choose cycle for largest numbered 2
	for (int i = 0; i < n; i++) // number of extra 2
		for (int j = 0; j <= min(2,m); j++) // number of 1
		{
			ans += ( ((C[n-1][i] * ( ( C[m][j] * fact[i+j]) % MOD) ) % MOD) * solve(n-1-i,m-j) ) % MOD;
			ans %= MOD;
		}
	return dp[n][m] = ans;
}

int main(void)
{
	int N;
	scanf("%i",&N);
	int n = 0, m = 0;
	for (int i = 0; i < N; i++)
	{
		int o;
		scanf("%i",&o);
		if (o == 1) m++;
		else n++;
	}
	// compute binomial coefficients
	C[0][0] = 1;
	for (int i = 1; i <= 500; i++)
		C[0][i] = 0, C[i][0] = 1;
	for (int i = 1; i <= 500; i++)
		for (int j = 1; j <= 500; j++)
			C[i][j] = (C[i-1][j] + C[i-1][j-1]) % MOD;
	// compute factorials
	fact[0] = 1;
	for (int i = 1; i <= 500; i++)
		fact[i] = (fact[i-1] * i) % MOD;
	// initial values
	memset(dp, (-1ll), sizeof(dp));
	dp[0][0] = 1; // (0,0) -> 1
	cout << solve(n,m) << endl;
	return 0;
}


#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;

#define MOD 1000000007
long long dp[501][501]; // used long long to avoid
long long C[501][501]; // going around casting
long long fact[501]; // all over the place

int main(void)
{
	int N;
	scanf("%i",&N);
	int n = 0, m = 0;
	for (int i = 0; i < N; i++)
	{
		int o;
		scanf("%i",&o);
		if (o == 1) m++;
		else n++;
	}
	// compute binomial coefficients
	C[0][0] = 1;
	for (int i = 1; i <= 500; i++)
		C[0][i] = 0, C[i][0] = 1;
	for (int i = 1; i <= 500; i++)
		for (int j = 1; j <= 500; j++)
			C[i][j] = (C[i-1][j] + C[i-1][j-1]) % MOD;
	// compute factorials
	fact[0] = 1;
	for (int i = 1; i <= 500; i++)
		fact[i] = (fact[i-1] * i) % MOD;
	// initial values
	dp[0][0] = 1; // (0,0) -> 1
	for (int j = 1; j <= m; j++)
	{
		long long ans = 0;
		for (int i = 0; i < min(2,j); i++)
			ans = (ans + ((C[j-1][i] * dp[0][j-1-i]) % MOD) ) % MOD;
		dp[0][j] = ans;
	}
	for (int i = 1; i <= n; i++)
		for (int j = 0; j <= m; j++)
		{
			long long ans = 0;
			for (int a = 0; a < i; a++) // number of extra 2
				for (int b= 0; b <= min(2,j); b++) // number of 1
				{
					ans += ( ((C[i-1][a] * ( ( C[j][b] * fact[a+b]) % MOD) ) % MOD) * dp[i-1-a][j-b] ) % MOD;
					ans %= MOD;
				}
			dp[i][j] = ans;
		}
	cout << dp[n][m] << endl;
	return 0;
}


#include <cstdio>
#include <cstdlib>
#define P 1000000007
using namespace std;

int n,m,tmp,x;
long long f[100001];

int main()
{
    scanf("%d",&tmp);
    for (int i=1;i<=tmp;i++)
    {
        scanf("%d",&x);
        if (x==1) n++; if (x==2) m++;
    }
    f[0]=1;
    for (int i=1;i<=n;i++) f[i]=(f[i-1]+f[i-2]*(i-1))%P;
    for (int i=n+1;i<=n+m;i++) f[i]=(f[i-1]*i)%P;
    printf("%I64d\n",f[n+m]);
}


#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<set>
#include<vector>
#define REP(i,m) for(int i=0;i<m;++i)
#define REPN(i,m,in) for(int i=in;i<m;++i)
#define ALL(t) (t).begin(),(t).end()
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define dump(x)  cerr << #x << " = " << (x) << endl
#define prl cerr<<"called:"<< __LINE__<<endl
using namespace std;
static const int INF =500000000;
template<class T> void debug(T a,T b){ for(;a!=b;++a) cerr<<*a<<' ';cerr<<endl;}
typedef long long int lint;
typedef pair<int,int> pi;
int n;
int one,two;
lint base[1000005];
const lint mod=1000000007;
int main(){
	int n;
	scanf("%d",&n);
	int one=0,two=0;
	REP(i,n) {
		int t;scanf("%d",&t);
		if(t==1) ++one;
		else ++two;
	}

	base[0]=base[1]=1;
	for(int i=2;i<=one;++i){
		base[i]=base[i-1]+base[i-2]*(i-1);
		base[i]%=mod;
	}

	lint res=base[one];
	REP(i,two){
		res*=one+1+i;
		res%=mod;
	}
	cout<<res<<endl;

	return 0;
}


//
//	ID: y0rkl1u
//	PROG: codeforces 316D2. PE Lesson
//	LANG: C++
//	DATE: 05.20.2016
//	NOTE: combinatorics, permutation
//

#include <cstdio>
#include <iostream>
using namespace std;

#define reg register
#define rint reg int
#define For(i,l,r) for(rint i=(l),_c=(r);i<=_c;i++)
typedef long long ll;

const int mod=1000000007;
int n,ai,c[3],s[1000011];
inline void Main()
{
	scanf("%d",&n);
	For(i,1,n){
		scanf("%d",&ai);
		++c[ai];
	}
	rint ans=1;
	For(i,c[1]+1,n)ans=(ll)ans*i%mod;
	s[0]=1,s[1]=1,s[2]=2;
	For(i,3,c[1])s[i]=(s[i-1]+(i-1)*(ll)s[i-2])%mod;
	ans=(ll)ans*s[c[1]]%mod;
	cout<<ans<<endl;
}
int main()
{
	Main();
	return 0;
}


//
//	ID: y0rkl1u
//	PROG: codeforces 316D2. PE Lesson
//	LANG: C++
//	DATE: 05.20.2016
//	NOTE: combinatorics, permutation
//

#include <cstdio>
#include <iostream>
using namespace std;

#define reg register
#define rint reg int
#define For(i,l,r) for(rint i=(l),_c=(r);i<=_c;i++)
typedef long long ll;

const int mod=1000000007;
int n,ai,c[3],s[1000011];
inline void Main()
{
	scanf("%d",&n);
	For(i,1,n){
		scanf("%d",&ai);
		++c[ai];
	}
	rint ans=1;
	For(i,c[1]+1,n)ans=(ll)ans*i%mod;
	s[0]=1,s[1]=1,s[2]=2;
	For(i,3,c[1])s[i]=s[i-1]+((ll)i-1)*s[i-2]%mod;
	ans=(ll)ans*s[c[1]]%mod;
	cout<<ans<<endl;
}
int main()
{
	Main();
	return 0;
}


#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <list>
#include <ctime>
#include <sstream>
#include <queue>
#include <stack>
#include <bitset>
using namespace std;
typedef vector<int> VI;
typedef pair<int,int> PII;
typedef long long LL;
#define FOR(x, b, e) for(int x=b; x<=(e); ++x)
#define FORD(x, b, e) for(int x=b; x>=(e); --x)
#define REP(x, n) for(int x=0; x<(n); ++x)
#define VAR(v,n) typeof(n) v=(n)
#define ALL(c) c.begin(),c.end()
#define SIZE(x) (int)x.size()
#define FOREACH(i,c) for(VAR(i,(c).begin());i!=(c).end();++i)
#define PB push_back
#define ST first
#define ND second
#define mp(x,y) make_pair(x,y)
#define DEBUG 1
#define debug(x) {if (DEBUG)cerr <<#x <<" = " <<x <<endl; }
#define debugv(x) {if (DEBUG) {cerr <<#x <<" = "; FORE(it, (x)) cerr <<*it <<", "; cout <<endl; }}
typedef short int sint;

const LL mod = 1000000007;
const int N = 1001001;
int tab[N];
LL sil[N];
LL odwS[N];
LL I[N];
int n;

LL pot(LL a, int wyk) {
	LL res = 1;
	while (wyk) {
		if (wyk&1) res = (res * a ) % mod;
		a =(a*a) % mod;
		wyk >>= 1;
	}
	return res;
}

LL odw(LL a) {
	return pot(a, mod - 2);
}

int main(){
	scanf("%d", &n);
	sil[0] = 1;
	odwS[0] = 1;
	FOR(i, 1, n){
		sil[i] = (sil[i-1] * i ) % mod;
		odwS[i] = odw(sil[i]);
	}
	int res =0;
	int l1 = 0, l2= 0;
	REP(i, n) {
		scanf("%d", &tab[i]);
		if(tab[i] == 1) l1++;
		if (tab[i] == 2) l2++;
	}
	I[1] = I[0] = 1;
	FOR(i, 2, l1) I[i] = (I[i-1] + (i-1) * I[i-2]) % mod;
	cout <<  (((sil[n] * odwS[l1]) % mod ) * I[l1] ) % mod << endl;
}


#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <list>
#include <ctime>
#include <sstream>
#include <queue>
#include <stack>
#include <bitset>
using namespace std;
typedef vector<int> VI;
typedef pair<int,int> PII;
typedef long long LL;
#define FOR(x, b, e) for(int x=b; x<=(e); ++x)
#define FORD(x, b, e) for(int x=b; x>=(e); --x)
#define REP(x, n) for(int x=0; x<(n); ++x)
#define VAR(v,n) typeof(n) v=(n)
#define ALL(c) c.begin(),c.end()
#define SIZE(x) (int)x.size()
#define FOREACH(i,c) for(VAR(i,(c).begin());i!=(c).end();++i)
#define PB push_back
#define ST first
#define ND second
#define mp(x,y) make_pair(x,y)
#define DEBUG 1
#define debug(x) {if (DEBUG)cerr <<#x <<" = " <<x <<endl; }
#define debugv(x) {if (DEBUG) {cerr <<#x <<" = "; FORE(it, (x)) cerr <<*it <<", "; cout <<endl; }}
typedef short int sint;

const LL mod = 1000000007;
const int N = 1001001;
int tab[N];
int sil[N];
LL odwS[N];
LL I[N];
int n;

LL pot(LL a, int wyk) {
	LL res = 1;
	while (wyk) {
		if (wyk&1) res = (res * a ) % mod;
		a =(a*a) % mod;
		wyk >>= 1;
	}
	return res;
}

LL odw(LL a) {
	return pot(a, mod - 2);
}

int main(){
	scanf("%d", &n);
	sil[0] = 1;
	odwS[0] = 1;
	FOR(i, 1, n){
		sil[i] = (sil[i-1] * i ) % mod;
		odwS[i] = odw(sil[i]);
	}
	int res =0;
	int l1 = 0, l2= 0;
	REP(i, n) {
		scanf("%d", &tab[i]);
		if(tab[i] == 1) l1++;
		if (tab[i] == 2) l2++;
	}
	I[1] = I[0] = 1;
	FOR(i, 2, l1) I[i] = (I[i-1] + (i-1) * I[i-2]) % mod;
	cout <<  (((sil[n] * odwS[l1]) % mod ) * I[l1] ) % mod << endl;
}


#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <list>
#include <ctime>
#include <sstream>
#include <queue>
#include <stack>
#include <bitset>
using namespace std;
typedef vector<int> VI;
typedef pair<int,int> PII;
typedef long long LL;
#define FOR(x, b, e) for(int x=b; x<=(e); ++x)
#define FORD(x, b, e) for(int x=b; x>=(e); --x)
#define REP(x, n) for(int x=0; x<(n); ++x)
#define VAR(v,n) typeof(n) v=(n)
#define ALL(c) c.begin(),c.end()
#define SIZE(x) (int)x.size()
#define FOREACH(i,c) for(VAR(i,(c).begin());i!=(c).end();++i)
#define PB push_back
#define ST first
#define ND second
#define mp(x,y) make_pair(x,y)
#define DEBUG 1
#define debug(x) {if (DEBUG)cerr <<#x <<" = " <<x <<endl; }
#define debugv(x) {if (DEBUG) {cerr <<#x <<" = "; FORE(it, (x)) cerr <<*it <<", "; cout <<endl; }}
typedef short int sint;

const LL mod = 1000000007;
const int N = 1001001;
int tab[N];
int sil[N];
LL odwS[N];
LL I[N];
int n;

LL pot(LL a, int wyk) {
	LL res = 1;
	while (wyk) {
		if (wyk&1) res = (res * a ) % mod;
		a =(a*a) % mod;
		wyk >>= 1;
	}
	return res;
}

LL odw(LL a) {
	return pot(a, mod - 2);
}

LL silq(int kon, int ile) {
	return (sil[kon] * odwS[kon - ile]) % mod;
}

int main(){
	scanf("%d", &n);
	sil[0] = 1;
	FOR(i, 1, n){
		sil[i] = (sil[i-1] * i ) % mod;
		odwS[i] = odw(sil[i]);
	}
	int res =0;
	int l1 = 0, l2= 0;
	REP(i, n) {
		scanf("%d", &tab[i]);
		if(tab[i] == 1) l1++;
		if (tab[i] == 2) l2++;
	}
	I[1] = I[0] = 1;
	FOR(i, 2, l1) I[i] = (I[i-1] + (i-1) * I[i-2]) % mod;
	printf("%lld\n", (((sil[n] * odwS[l1]) % mod ) * I[l1] ) % mod);
}


#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <list>
#include <ctime>
#include <sstream>
#include <queue>
#include <stack>
#include <bitset>
using namespace std;
typedef vector<int> VI;
typedef pair<int,int> PII;
typedef long long LL;
#define FOR(x, b, e) for(int x=b; x<=(e); ++x)
#define FORD(x, b, e) for(int x=b; x>=(e); --x)
#define REP(x, n) for(int x=0; x<(n); ++x)
#define VAR(v,n) typeof(n) v=(n)
#define ALL(c) c.begin(),c.end()
#define SIZE(x) (int)x.size()
#define FOREACH(i,c) for(VAR(i,(c).begin());i!=(c).end();++i)
#define PB push_back
#define ST first
#define ND second
#define mp(x,y) make_pair(x,y)
#define DEBUG 1
#define debug(x) {if (DEBUG)cerr <<#x <<" = " <<x <<endl; }
#define debugv(x) {if (DEBUG) {cerr <<#x <<" = "; FORE(it, (x)) cerr <<*it <<", "; cout <<endl; }}
typedef short int sint;

const LL mod = 1000000007;
const int N = 1001001;
int tab[N];
int sil[N];
LL odwS[N];
LL I[N];
int n;

LL pot(LL a, int wyk) {
	LL res = 1;
	while (wyk) {
		if (wyk&1) res = (res * a ) % mod;
		a =(a*a) % mod;
		wyk >>= 1;
	}
	return res;
}

LL odw(LL a) {
	return pot(a, mod - 2);
}

int main(){
	scanf("%d", &n);
	sil[0] = 1;
	odwS[0] = 1;
	FOR(i, 1, n){
		sil[i] = (sil[i-1] * i ) % mod;
		odwS[i] = odw(sil[i]);
	}
	int res =0;
	int l1 = 0, l2= 0;
	REP(i, n) {
		scanf("%d", &tab[i]);
		if(tab[i] == 1) l1++;
		if (tab[i] == 2) l2++;
	}
	I[1] = I[0] = 1;
	FOR(i, 2, l1) I[i] = (I[i-1] + (i-1) * I[i-2]) % mod;
	printf("%I64d\n", (((sil[n] * odwS[l1]) % mod ) * I[l1] ) % mod);
}


#define _CRT_SECURE_NO_DEPRECATE
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <iostream>
#include <iterator>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <sstream>
#include <fstream>
#include <ctime>
#include <cstring>
#include <functional>
#include <bitset>
#pragma comment(linker, "/STACK:66777216")
using namespace std;
#define pb push_back
#define ppb pop_back
#define pi 3.1415926535897932384626433832795028841971
#define mp make_pair
#define x first
#define y second
#define pii pair<int,int>
#define pdd pair<double,double>
#define INF 1000000000
#define FOR(i,a,b) for (int _n(b), i(a); i <= _n; i++)
#define FORD(i,a,b) for(int i=(a),_b=(b);i>=_b;i--)
#define all(c) (c).begin(), (c).end()
#define SORT(c) sort(all(c))
#define rep(i,n) FOR(i,1,(n))
#define rept(i,n) FOR(i,0,(n)-1)
#define L(s) (int)((s).size())
#define C(a) memset((a),0,sizeof(a))
#define VI vector <int>
#define ll long long
#define MOD 1000000007

int a,b,c,d,n,m,k;
int main() {
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);

	scanf("%d", &n);
	int one = 0, two = 0;
	rept(i, n) {
		scanf("%d", &a);
		if (a == 1) ++one; else
		++two;
	}

	int ans = 1, p = 0;
	FOR(i, 2, one + 1) {
		int nans = (ans + (ll)(i - 2) * p) % MOD;
		p = ans; ans = nans;
	}

	rep(i, two) {
		ans = (ll)ans * (one + i) % MOD;
	}

	cout << ans << endl;
}


#define _CRT_SECURE_NO_DEPRECATE
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <iostream>
#include <iterator>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <sstream>
#include <fstream>
#include <ctime>
#include <cstring>
#include <functional>
#include <bitset>
#pragma comment(linker, "/STACK:66777216")
using namespace std;
#define pb push_back
#define ppb pop_back
#define pi 3.1415926535897932384626433832795028841971
#define mp make_pair
#define x first
#define y second
#define pii pair<int,int>
#define pdd pair<double,double>
#define INF 1000000000
#define FOR(i,a,b) for (int _n(b), i(a); i <= _n; i++)
#define FORD(i,a,b) for(int i=(a),_b=(b);i>=_b;i--)
#define all(c) (c).begin(), (c).end()
#define SORT(c) sort(all(c))
#define rep(i,n) FOR(i,1,(n))
#define rept(i,n) FOR(i,0,(n)-1)
#define L(s) (int)((s).size())
#define C(a) memset((a),0,sizeof(a))
#define VI vector <int>
#define ll long long
#define MOD 1000000007

int a,b,c,d,n,m,k;
int main() {
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);

	scanf("%d", &n);
	int one = 0, two = 0;
	rept(i, n) {
		scanf("%d", &a);
		if (a == 1) ++one; else
		++two;
	}

	int ans = 1, p = 0;
	FOR(i, 2, one + 1) {
		int nans = (ans + (ll)(i - 2) * p) % MOD;
		p = ans; ans = nans;
	}

	rep(i, two) {
		ans = (ll)ans * (one + i) % MOD;
	}

	cerr << ans << endl;
}


#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define mp make_pair
int const lim =  1e6+3;
int const MLOG = 20;
int mod = 1e9+7;
long long dp[lim+3];
int a[lim+3];
int main()
{
	//freopen("input","r",stdin);
	//freopen("output","w",stdout);
	int n;cin >> n;
	for(int i =0;i<n;i++)
	{
		int x;scanf("%d",&x);a[x]++;
	}
	long long ans = 0;
	dp[1] = dp[0] = 1;
	for(int i = 2;i<=a[1];i++)
	{
		dp[i] = (1ll*dp[i-2]*(i-1))%mod;
		dp[i]+=dp[i-1];
		dp[i]%=mod;
	}
	dp[0] = dp[a[1]];
	for(int i = 1;i<=a[2];i++)
	{
		dp[i] = (1ll*dp[i-1]*(a[1]+i-1))%mod;
		dp[i]+=dp[i-1];
	}
	cout << dp[a[2]] << endl;
}


#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define mp make_pair
int const lim =  1e6+3;
int const MLOG = 20;
int mod = 1e9+7;
long long dp[lim+3];
int a[lim+3];
int main()
{
	//freopen("input","r",stdin);
	//freopen("output","w",stdout);
	int n;cin >> n;
	for(int i =0;i<n;i++)
	{
		int x;scanf("%d",&x);a[x]++;
	}
	long long ans = 0;
	dp[1] = dp[0] = 1;
	for(int i = 2;i<=a[1];i++)
	{
		dp[i] = (1ll*dp[i-2]*(i-1))%mod;
		dp[i]+=dp[i-1];
		dp[i]%=mod;
	}
	dp[0] = dp[a[1]];
	for(int i = 1;i<=a[2];i++)
	{
		dp[i] = (1ll*dp[i-1]*(a[1]+i-1))%mod;
		dp[i]+=dp[i-1];dp[i]%=mod;
	}
	cout << dp[a[2]] << endl;
}


#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
const int MOD = (int)1e9 + 7;

int main() {
    int n; cin >> n;
    vector<int> a(n);
    for (auto &ai: a) cin >> ai;
    int one = count(begin(a), end(a), 1),
        two = count(begin(a), end(a), 2);
    vector<long long> dp(one + 1);
    dp[0] = 1;
    for (int i = 1; i <= one; i++) {
        dp[i] += dp[i - 1];
        if (i >= 2) dp[i] += dp[i - 2] * (i - 1) % MOD;
        dp[i] %= MOD;
    }
    long long ans = dp[one];
    for (int i = 1; i <= two; i++) ans = ans * (one + i) % MOD;
    cout << ans << endl;
    return 0;
}


#include<bits/stdc++.h>
#define ll long long int
#define f first
#define s second
#define pb push_back
#define PII pair<ll,ll>
ll const MOD = 1000000007;
ll const N = 1000005;
ll const LN = 20;
ll const inf = 8e18;
using namespace std;

ll n, m, a[N];

ll dp[N];

ll fact[N];
ll ifact[N];
ll bexpo (ll x, ll n, ll m)
{
	ll r = 1;
	x = x % m;
	while (n > 0)
	{
		if (n % 2) r = (r * x) % m;
		x = (x * x) % m;
		n = n / 2;
	}
	return r;
}
ll ncr (ll n, ll r)
{
	if (r > n) return 0;
	ll ans = fact[n];
	ans = (ans * ifact[r]) % MOD;
	ans = (ans * ifact[n - r]) % MOD;
	return ans;
}
void pre()
{
	fact[0] = 1;
	ifact[0] = 1;
	for (ll i = 1; i < N; i++) fact[i] = (fact[i - 1] * i) % MOD;
	ifact[N - 1] = bexpo (fact[N - 1], MOD - 2, MOD);
	for (ll i = N - 2; i > 0; i--)
		ifact[i] = (ifact[i + 1] * (i + 1)) % MOD;
}

int main()
{
	ios::sync_with_stdio (false);
	cin.tie (NULL);
	pre();
	ll n;
	cin >> n;
	ll cnt1 = 0;
	ll cnt2 = 0;
	for (ll i = 1; i <= n; i++)
	{
		ll d;
		cin >> d;
		if (d == 1) cnt1++;
		if (d == 2) cnt2++;
	}
	dp[0] = 1;
	for (ll i = 1; i <= cnt1; i++)
		dp[i] = (dp[i - 1] + (i - 1) * dp[i - 2]) % MOD;

	ll ans = dp[cnt1];
	ans *= fact[cnt1 + cnt2];
	ans %= MOD;
	ans *= ifact[cnt1];
	ans %= MOD;
	cout << ans;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define rep(i, a, b) for(int i = (a); i < (b); ++i)
#define per(i, a, b) for(int i = (b) - 1; i >= (a); --i)
#define sz(a) (int)a.size()
#define de(a) cout << #a << " = " << a << endl
#define dd(a) cout << #a << " = " << a << " "
#define all(a) a.begin(), a.end()
#define pw(a) (1ll<<(x))
#define endl "\n"
typedef long long ll;
typedef double db;
typedef pair<int, int> pii;
typedef vector<int> vi;
//----
const int mod = 1e9 + 7, N = 1e6 + 5;
int c[5];
int dp[N] = {1, 1, 2};
int add(int a, int b) {
	int res = a + b;
	if(res >= mod)res -= mod;
	return res;
}
int mul(int a, int b) {
	return 1ll * a * b % mod;
}
int main() {
	int n; cin >> n;
	rep(i, 0, n) {
		int x; cin >> x; c[x]++;
	}
	dp[1] = 1;
	rep(i, 3, c[1] + 1)dp[i] = add(dp[i - 1], mul((i - 1), dp[i - 2]));
	rep(i, n - c[2] + 1, n + 1)dp[c[1]] = mul(dp[c[1]], i);
	cout << dp[c[1]] << endl;
	return 0;
}