#include <bits/stdc++.h>

#define FOR(i,b,e) for (int i = (b); i <= (e); i++)
#define FORD(i,b,e) for (int i = (b); i >= (e); i--)
#define SIZE(c) ((int) (c).size())

#define pb push_back
#define st first
#define nd second

using namespace std;


typedef long long ll;
typedef pair <int,int> pii;

typedef vector <int> VI;
typedef vector <ll> VL;
typedef vector <bool> VB;
typedef vector <pii> VP;

typedef vector <VI> VVI;
typedef vector <VL> VVL;
typedef vector <VB> VVB;
typedef vector <VP> VVP;

const int MOD = 998244353;


int main() {
    ios_base::sync_with_stdio(false);

    int n;
    cin >> n;

    string xStr;
    cin >> xStr;

    VI x(n);
    FOR(i,0,n-1) {
        x[i] = xStr[i] == '1';
    }

    reverse(x.begin(), x.end());

    VI pows(n + 1);

    pows[0] = 1;
    FOR(i,1,n) {
        pows[i] = (pows[i-1] * 2) % MOD;
    }

    VI divs;

    for (int i = 1; i < n; i++) if (n % i == 0 && (n / i) % 2) {
        divs.pb(i);
    }

    int d = SIZE(divs);

    VL ansForDiv(d, 0);

    FOR(i,0,d-1) {
        int dv = divs[i];

        int freeBits = dv;
        VI info(dv, -1);

        int broken = 0;

        FOR(pref,0,n) {
            int pos = n - 1 - pref;

            int posInInfo = pos % dv;
            bool negatedInInfo = (pos / dv) % 2;

            bool didSet = false;
            bool didBreak = false;

            if (pref == n || x[pos]) {
                if (pref < n) {
                    int value = negatedInInfo xor (1 - x[pos]);

                    if (info[posInInfo] == -1) {
                        info[posInInfo] = value;
                        freeBits--;

                        didSet = true;
                    } else if (info[posInInfo] == 1 - value) {
                        broken++;

                        didBreak = true;
                    }
                }

                if (!broken) {
                    ansForDiv[i] += pows[freeBits];

                    if (ansForDiv[i] >= MOD) {
                        ansForDiv[i] -= MOD;
                    }
                }
            }

            if (pref < n) {
                if (didSet) {
                    info[posInInfo] = -1;
                    freeBits++;
                }

                if (didBreak) {
                    broken--;
                }

                int value = negatedInInfo xor x[pos];

                if (info[posInInfo] == -1) {
                    info[posInInfo] = value;
                    freeBits--;
                } else if (info[posInInfo] == 1 - value) {
                    broken++;
                }
            }
        }
    }

    VI sieve(n + 1, -1);

    FOR(i,2,n) if (sieve[i] == -1) {
        sieve[i] = i;

        for (int j = 2 * i; j <= n; j += i) if (sieve[j] == -1) {
            sieve[j] = i;
        }
    }

    VI mu(n + 1, 1);

    FOR(i,2,n) {
        int j = i / sieve[i];

        if (j % sieve[i] == 0) {
            mu[i] = 0;
        } else {
            mu[i] = -mu[j];
        }
    }

    VI ansForDivAfter(d, 0);

    FOR(i,0,d-1) FOR(j,0,i) if (divs[i] % divs[j] == 0) {
        ansForDivAfter[i] += mu[divs[i] / divs[j]] * ansForDiv[j];

        ansForDivAfter[i] %= MOD;
        if (ansForDivAfter[i] < 0) {
            ansForDivAfter[i] += MOD;
        }
    }

    long long ans = 0;

    int total = 1;
    FOR(i,0,n-1) if (x[i]) {
        total = (total + pows[i]) % MOD;
    }

    FOR(i,0,d-1) {
        int here = ansForDivAfter[i];

        ans = (ans + (long long) here * 2 * divs[i]) % MOD;

        total -= here;
        if (total < 0) {
            total += MOD;
        }
    }

    ans = (ans + (long long) total * 2 * n) % MOD;
    cout << ans;

    return 0;
}

Measured memory_bytes: 3860