#include #include int main() { int N; std::cin >> N; std::vector> A(N + 1, std::vector(N, 0)); std::vector B(N, 0); std::string S; std::cin >> S; const int P = 998244353; std::vector p(N); p[0] = 1; // base case for powers of 2 for (int i = 1; i < N; ++i) { p[i] = (2 * p[i - 1]) % P; // precalculate powers of 2 modulo P } for (int i = 1; i <= N; ++i) { bool s = S[N - i] > '0'; for (int j = 0; j < i; ++j) { long long val = (s && j > 0) ? (p[std::max(0, i - j - 2)] - A[i - j - 1][j]) % P : 0; if (val < 0) val += P; // ensure non-negative value B[j] = (B[j] + val + (s && j == 0 ? p[std::max(0, i - 2)] : 0)) % P; A[i][j] = B[j]; } } long long result = 0; for (int j = 0; j < N; ++j) { result = (result + p[j] * A[N][j]) % P; } std::cout << result << std::endl; return 0; }