#include #include const int P = 998244353; int main() { int N; std::cin >> N; std::vector> A(N+1, std::vector(N)); std::vector B(N), p(N); std::string S; std::cin >> S; // Precompute powers of 2 modulo P p[0] = 1; for (int i = 1; i < N; i++) { p[i] = (p[i-1] * 2) % P; } for (int i = 1; i <= N; i++) { bool s = S[N-i] > '0'; for (int j = 0; j < i; j++) { B[j] = (B[j] + (s && j > 0 ? (p[std::max(0, i-j-2)] - A[i-j-1][j] + P) % P : 0)) % P; A[i][j] = (A[i-1][j] + (s ? (j == 0 ? p[std::max(0, i-2)] : B[j]) : 0)) % P; } } 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; }