#include #include using namespace std; using mint = atcoder::modint998244353; using ll = long long; //enumeration enu(200000);のように宣言する template struct enumeration{ int N; vector fact, inv; enumeration() : N(0), fact(1, 1), inv(1, 1) {} enumeration(int _n) : N(_n), fact(_n + 1), inv(_n + 1) { fact[0] = 1; for(int i = 1; i <= N; i++) fact[i] = fact[i - 1] * i; inv[N] = T(1) / fact[N]; for(int i = N; i >= 1; i--) inv[i - 1] = inv[i] * i; } void expand(int lim){ fact.resize(lim + 1); inv.resize(lim + 1); for(int i = N + 1; i <= lim; i++) fact[i] = i * fact[i - 1]; inv[lim] = T(1) / fact[lim]; for(int i = lim; i >= N + 2; i--) inv[i - 1] = i * inv[i]; N = lim; } T Per(int n, int k){ if(k > n) return 0; if(n > N) expand(n); return fact[n] * inv[n - k]; } T C(int n, int k){ if(n < 0 || k < 0 || k > n) return 0; if(n > N) expand(n); return fact[n] * inv[n - k] * inv[k]; } T H(int n, int k){ if(n ==0 && k == 0) return 1; if(n <= 0 || k < 0) return 0; return C(n + k - 1, k); } }; int main(){ ios::sync_with_stdio(false); cin.tie(0); enumeration enu(2005); int n; string s; cin >> n >> s; int cnt = 0; reverse(s.begin(), s.end()); while(!s.empty() && s.back() == '1') cnt++, s.pop_back(); reverse(s.begin(), s.end()); const int m = s.size(); vector dp(1); dp[0] = 1; for(int i = 1; i < m; i++){ vector ndp(i + 1); if(s[i] == '0'){ vector imos(i + 2); for(int j = 0; j < i; j++){ /*for(int k = 0; k <= i; k++){ ndp[max(k, j + 1)] += dp[j]; }*/ imos[j + 1] += (j + 2) * dp[j]; imos[j + 2] -= (j + 2) * dp[j]; imos[j + 2] += dp[j]; imos[i + 1] -= dp[j]; } for(int j = 0; j <= i; j++){ imos[j + 1] += imos[j]; ndp[j] += imos[j]; } }else{ for(int j = 0; j < i; j++){ ndp[j] += (i - j) * dp[j]; } } swap(dp, ndp); } mint ans = enu.Per(n, cnt); ans *= accumulate(dp.begin(), dp.end(), mint(0)); cout << ans.val() << '\n'; }