mod = 998244353

N = int(eval(input()))

X = eval(input())



d = []

for n in range(1,N+1):

    if N%n==0 and (N//n)%2==1:

        d.append(n)



p_d = {}



for n in d:

    p_d[n] = 0

    S = []

    for i in range(N):

        j = i//n

        if X[i%n]=='0':

            if j%2==0:

                S.append('0')

            else:

                S.append('1')

        else:

            if j%2==0:

                S.append('1')

            else:

                S.append('0')



    S = ''.join(S)

    s = X[:n][::-1]

    for i in range(n):

        if s[i]=='1':

            p_d[n] += pow(2,i,mod)

    if S<=X:

        p_d[n] += 1



ans = 0

for i in range(len(d)):

    n = d[i]

    for j in range(i):

        m = d[j]

        if n%m==0:

            p_d[n] -= p_d[m]

    ans += p_d[n]*2*n

ans %= mod

print(ans)

mod = 998244353

N = int(eval(input()))

X = eval(input())

X_ = []

for i in range(N):

    if X[i]=='0':

        X_.append('1')

    else:

        X_.append('0')

X_ = ''.join(X_)



d = []

for n in range(1,N+1):

    if N%n==0 and (N//n)%2==1:

        d.append(n)



p_d = {}



for n in d:

    p_d[n] = 0

    S = (X[:n]+X_[:n])*(N//n//2)+X[:n]

    p_d[n] += int(X[:n],2)%mod

    if S<=X:

        p_d[n] += 1



ans = 0

for i in range(len(d)):

    n = d[i]

    for j in range(i):

        m = d[j]

        if n%m==0:

            p_d[n] -= p_d[m]

    ans += p_d[n]*2*n

ans %= mod

print(ans)
mod = 998244353
N = int(eval(input()))
X = eval(input())
d = []
for n in range(1, N + 1):
    if N % n == 0 and (N // n) % 2 == 1:
        d.append(n)
p_d = {}
for n in d:
    p_d[n] = 0
    S = []
    for i in range(N):
        j = i // n
        if X[i % n] == "0":
            if j % 2 == 0:
                S.append("0")
            else:
                S.append("1")
        else:
            if j % 2 == 0:
                S.append("1")
            else:
                S.append("0")
    S = "".join(S)
    s = X[:n][::-1]
    for i in range(n):
        if s[i] == "1":
            p_d[n] += pow(2, i, mod)
    if S <= X:
        p_d[n] += 1
ans = 0
for i in range(len(d)):
    n = d[i]
    for j in range(i):
        m = d[j]
        if n % m == 0:
            p_d[n] -= p_d[m]
    ans += p_d[n] * 2 * n
ans %= mod
print(ans)

mod = 998244353
N = int(eval(input()))
X = eval(input())
X_ = []
for i in range(N):
    if X[i] == "0":
        X_.append("1")
    else:
        X_.append("0")
X_ = "".join(X_)
d = []
for n in range(1, N + 1):
    if N % n == 0 and (N // n) % 2 == 1:
        d.append(n)
p_d = {}
for n in d:
    p_d[n] = 0
    S = (X[:n] + X_[:n]) * (N // n // 2) + X[:n]
    p_d[n] += int(X[:n], 2) % mod
    if S <= X:
        p_d[n] += 1
ans = 0
for i in range(len(d)):
    n = d[i]
    for j in range(i):
        m = d[j]
        if n % m == 0:
            p_d[n] -= p_d[m]
    ans += p_d[n] * 2 * n
ans %= mod
print(ans)

+X_ = [] +for i in range(N): +    if X[i] == "0": +        X_.append("1") +    else: +        X_.append("0") +X_ = "".join(X_) -    S = [] -    for i in range(N): -        j = i // n -        if X[i % n] == "0": -            if j % 2 == 0: -                S.append("0") -            else: -                S.append("1") -        else: -            if j % 2 == 0: -                S.append("1") -            else: -                S.append("0") -    S = "".join(S) -    s = X[:n][::-1] -    for i in range(n): -        if s[i] == "1": -            p_d[n] += pow(2, i, mod) +    S = (X[:n] + X_[:n]) * (N // n // 2) + X[:n] +    p_d[n] += int(X[:n], 2) % mod