#include using namespace std; typedef long long ll; typedef pair p_ll; template void debug(T itr1, T itr2) { auto now = itr1; while(now=0; i--) const ll LLINF = pow(2,61)-1; const int INF = pow(2,30)-1; // ---------------------------------------------------------------------- // ---------------------------------------------------------------------- const ll MOD = 998244353; struct MLL { ll x, mod; MLL(ll y=0, ll m=MOD) { x = y; mod = m; } MLL &operator+= (const MLL &p) { x = (x+p.x)%mod; return *this; } MLL &operator-= (const MLL &p) { x = (x-p.x+mod)%mod; return *this; } MLL &operator*= (const MLL &p) { x = (x*p.x)%mod; return *this; } MLL &operator/= (const MLL &p) { x = (x*p.inv().x)%mod; return *this; } MLL operator+ (const MLL &p) const { return MLL(*this)+=p; } MLL operator- (const MLL &p) const { return MLL(*this)-=p; } MLL operator* (const MLL &p) const { return MLL(*this)*=p; } MLL operator/ (const MLL &p) const { return MLL(*this)/=p; } bool operator== (const MLL &p) const { return x==p.x; } bool operator!= (const MLL &p) const { return x!=p.x; } bool operator< (const MLL &p) const { return x< p.x; } bool operator<= (const MLL &p) const { return x<=p.x; } bool operator> (const MLL &p) const { return x> p.x; } bool operator>= (const MLL &p) const { return x>=p.x; } MLL pow(MLL n) const { MLL result(1), p(x); ll tn = n.x; while(tn){ if (tn&1) result*=p; p*=p; tn>>=1; } return result; } MLL inv() const { return pow(MOD-2); } }; MLL operator+ (ll x, MLL p) { return (MLL)x+p; } MLL operator- (ll x, MLL p) { return (MLL)x-p; } MLL operator* (ll x, MLL p) { return (MLL)x*p; } MLL operator/ (ll x, MLL p) { return (MLL)x/p; } vector fac; void c_fac(ll x=pow(10,7)+10) { fac.resize(x); rep(i,x) fac[i] = i ? fac[i-1]*i : 1; } MLL nck(MLL n, MLL k) { return n<0||n> (istream &ist, MLL &p) { return ist >> p.x; } // ---------------------------------------------------------------------- // ---------------------------------------------------------------------- int main() { ll N; cin >> N; string S; cin >> S; ll c0 = 0, c1 = 0; rep(i,N) { if (S[i]=='0') c0++; else c1++; } c_fac(); assert(1<=N && N<=5000); rep(i,N) assert(S[i]=='0'||S[i]=='1'); vector> dp(N+1, vector(N+1)); dp[0][0] = 1; rep(i,N) rep(j,N+1) { if (i+2<=N&&j+1<=N) dp[i+2][j+1] += dp[i][j] * (i+1); if (j+1<=N) dp[i+1][j+1] += dp[i][j] * (i-j); dp[i+1][j] += dp[i][j] * j; } // rep(i,N+1) debug(all(dp[i])); MLL result = 0; rep(eq01,N+1) { MLL select_eq = nck(c0+c1,eq01) * fac[eq01]; rep(eq0,eq01+1) { ll eq1 = eq01 - eq0; if (eq0>c0||eq1>c1) continue; MLL select_01 = nck(c0,eq0) * fac[c0-eq0] * nck(c1,eq1) * fac[c1-eq1]; result += select_eq * select_01 * dp[N-eq01][c0-eq0]; // cout << eq0 << " " << eq1 << "->" << select_eq * select_01 * dp[N-eq01][c0-eq0] << endl; } } cout << result << endl; return 0; }