#include #include #include using namespace std; #include #include using mint1 = atcoder::modint998244353; using mint2 = atcoder::modint998244353; template Mint A107984(Mint n, Mint k) { return (k + 1) * (n + 2) * (2 * n - k + 3) * (n - k + 1) / 6; } // 右に r ステップ進むより左に l ステップ進む方が先の確率 * (そのようなときにそれを達成するまでの時間の条件付き期待値) template Mint solve(int l, int r) { int N = l + r; return A107984(N - 2, l - 1) * 2 / Mint(N * N); } template Mint sol(const string &S) { const int N = S.size(); vector zeropos; for (int i = 0; i < N; i++) { if (S[i] == '1') continue; zeropos.push_back(i); } mint1 ret = 0; for (int t = 0; t < 2; ++t) { ret += solve(N - zeropos[0], zeropos[0]); for (auto &x : zeropos) x = N - x; reverse(zeropos.begin(), zeropos.end()); } for (int i = 1; i < int(zeropos.size()); ++i) { int a = zeropos[i - 1], b = zeropos[i]; for (int t = 0; t < 2; ++t) { auto e1 = solve(a, N - b); auto e2 = solve(N - (b - a), b - a); ret += e1 * (b - a) / N + e2 * (N - b) / (N - b + a); swap(a, b); a = N - a; b = N - b; } } return ret; } int main() { cin.tie(nullptr), ios::sync_with_stdio(false); int N; string S; cin >> N >> S; auto v1 = sol(S).val(); auto v2 = sol(S).val(); cout << atcoder::crt({v1, v2}, {mint1::mod(), mint2::mod()}).first << '\n'; }