#include using namespace std; #define int long long #define INF (int)1e18 #define f first #define s second mt19937_64 RNG(chrono::steady_clock::now().time_since_epoch().count()); int n; string s; const int mod = 998244353; const int N = 4005; int p[N]; int dp[N][2]; int unsetpref[N]; int calc(int x){ dp[0][0] = 1; dp[0][1] = 0; int pref = 0; unsetpref[0] = 1; for (int i = 1; i <= n; i++){ dp[i][0] = p[i - 1]; //consider previously set bit dp[i][1] = pref; if (i > x && s[i - x] == '1'){ dp[i][1] += unsetpref[i - x - 1]; dp[i][1] %= mod; } pref += dp[i][1]; pref %= mod; unsetpref[i] = unsetpref[i - 1] + dp[i][0] - dp[i][1]; unsetpref[i] %= mod; if (unsetpref[i] < 0) unsetpref[i] += mod; } return dp[n][1]; } void Solve() { cin >> n >> s; s = "0" + s; p[0] = 1; for (int i = 1; i < N; i++) p[i] = p[i-1] * 2 % mod; int ans = 0; for (int bi = 0; bi < n; bi++){ int ways = calc(bi); ans += ways * p[bi] % mod; ans %= mod; } cout << ans << "\n"; } int32_t main() { auto begin = std::chrono::high_resolution_clock::now(); ios_base::sync_with_stdio(0); cin.tie(0); int t = 1; // cin >> t; for(int i = 1; i <= t; i++) { //cout << "Case #" << i << ": "; Solve(); } auto end = std::chrono::high_resolution_clock::now(); auto elapsed = std::chrono::duration_cast(end - begin); // cerr << "Time measured: " << elapsed.count() * 1e-9 << " seconds.\n"; return 0; }