#include<cstring> #include<cstdio> using namespace std; #define MOD 1000000007 typedef long long ll; ll F[16][16][16][16][16][6]; ll f(int a,int b,int c,int d,int e,int pre) { if(F[a][b][c][d][e][pre]!=-1) return F[a][b][c][d][e][pre]; if((!a)&&(!b)&&(!c)&&(!d)&&(!e)) return F[a][b][c][d][e][pre]=1; ll res=0; if(a) res=(res+((ll)(a-(pre==2))*f(a-1,b,c,d,e,1))%MOD)%MOD; if(b) res=(res+((ll)(b-(pre==3))*f(a+1,b-1,c,d,e,2))%MOD)%MOD; if(c) res=(res+((ll)(c-(pre==4))*f(a,b+1,c-1,d,e,3))%MOD)%MOD; if(d) res=(res+((ll)(d-(pre==5))*f(a,b,c+1,d-1,e,4))%MOD)%MOD; if(e) res=(res+((ll)e*f(a,b,c,d+1,e-1,5))%MOD)%MOD; return F[a][b][c][d][e][pre]=res; } int n,a[16]; int main() { int x; scanf("%d",&n); for(;n;--n) { scanf("%d",&x); ++a[x]; } memset(F,-1,sizeof(F)); printf("%d ",(int)f(a[1],a[2],a[3],a[4],a[5],-1)); }