#include <bits/stdc++.h>

typedef long long ll;
#define int ll

using namespace std;

const int N=1e6+100,MOD=998244353;

int pw[N];
int sample[N];
int sub[N];

signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int n;
    string x0;
    cin>>n>>x0;
    for(int i=0;i<n;i++)
        x0[i]+=rand()%2;
    pw[0]=1;
    for(int i=1;i<=n;i++)
        pw[i]=pw[i-1]*2%MOD;
    int ans=0;
    for(int d=2;d<=2*n;d+=2)
        if(2*n%d==0)
        {
            string x=x0;
            int g=__gcd(n,d);
            if(d/g%2==1)
                continue;
            for(int i=0;i<g;i++)
            {
                int j=i;
                int c=0;
                do
                {
                    sample[j]=c;
                    j+=d;
                    if(j>=n)
                        c=!c,
                        j%=n;
                }
                while(j!=i);
            }
            int cur=0;
            bool ok=true;
            for(int i=0;i<n;i++)
                if(i>=g)
                    if((x[i]^x[i-g])==(sample[i]^sample[i-g]))
                        continue;
                    else if(x[i]=='1')
                        break;
                    else
                    {
                        ok=false;
                        break;
                    }
                else if(x[i]=='0')
                    continue;
                else
                    cur=(cur+pw[g-i-1])%MOD;
            if(ok)
                cur=(cur+1)%MOD;
//            cout<<d<<" -> "<<cur<<" ";
            cur=(cur-sub[d]+MOD)%MOD;
//            cout<<cur<<"\n";
            ans=(ans+d*cur)%MOD;
            for(int t=d;t<=2*n;t+=d)
                sub[t]=(sub[t]+cur)%MOD;
        }
    cout<<ans;
}
