#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <climits>
#include <cmath>
#include <complex>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <cstdint>
using namespace std;
typedef long long ll;
#define MP make_pair
#define PB push_back
#define inf 1000000007
#define mod 998244353
#define rep(i,n) for(int i = 0; i < (int)(n); ++i)
#define int long long
vector<vector<int> > dev;

signed main(){
    int n;
    string s;
    cin >> n >> s;
    vector<int>t(n);
    // int k =0;
    // int qq = 1;
    rep(i,n){
        t[i] = s[i]-'0';
    }
    // rep(i,n){
    //     k += qq*t[n-1-i]%mod;
    //     k %= mod;
    //     qq*=2;
    //     qq%= mod;
    // }
    // cerr << k << endl;
    int mx = 0;
    dev.resize(n+1);
    for(int i=1;i<=n;i++){
        for(int j=i;j<=n;j+=i){
            dev[j].push_back(i);
        }
    }
    vector<int> res(n+1);
    vector<int> p;
    for(auto x:dev[n]){
        if(x%2==0)continue;
        int len = n/x;
        p.push_back(len);
        vector<vector<bool> > ichi(len,vector<bool>(2));
        vector<vector<int> > dai(len,vector<int>(2,-1));
        vector<vector<int> > sho(len,vector<int>(2,-1));
        rep(cc,len){
            rep(i,2){
                bool ichiflag = 1;
                rep(j,n/len){
                    int id = len*j+cc;
                    if(j%2==0){
                        int k = i;  
                        if(t[id]!=k){
                            ichiflag = 0;
                            break;
                        }
                    }else{
                        int k = 1-i;
                        if(t[id]!=k){
                            ichiflag = 0;
                            break;
                        }
                    }
                }
                ichi[cc][i] = ichiflag;
            }
        }
        rep(cc,len){
            rep(i,2){
                rep(j,n/len){
                    int id = len*j+cc;
                    if(j%2==0){
                        int k = i;  
                        if(t[id]<k){
                            dai[cc][i] = j;
                            break;
                        }else if(t[id]>k){
                            dai[cc][i] = -1;
                            break;
                        }
                    }else{
                        int k = 1-i;
                        if(t[id]<k){
                            dai[cc][i] = j;
                            break;
                        }else if(t[id]>k){
                            dai[cc][i] = -1;
                            break;
                        }
                    }
                }
            }
        }
        rep(cc,len){
            rep(i,2){
                rep(j,n/len){
                    int id = len*j+cc;
                    if(j%2==0){
                        int k = i;  
                        if(t[id]>k){
                            sho[cc][i] = j;
                            break;
                        }else if(t[id]<k){
                            sho[cc][i] = -1;
                            break;
                        }
                    }else{
                        int k = 1-i;
                        if(t[id]>k){
                            sho[cc][i] = j;
                            break;
                        }else if(t[id]<k){
                            sho[cc][i] = -1;
                            break;
                        }
                    }
                }
            }
        }
        int block = n/len;
        vector<vector<vector<int> > > dp(len,vector<vector<int>>(block+1,vector<int>(2,0)));
        rep(i,len){
            if(i==0){
                if(ichi[i][0]){
                    dp[i][block][1] +=1;
                }else if(dai[i][0]!=-1){
                    dp[i][dai[i][0]][1] += 1;
                }else if(sho[i][0]!=-1){
                    dp[i][sho[i][0]][0] += 1;
                }
                if(ichi[i][1]){
                    dp[i][block][1] +=1;
                }else if(dai[i][1]!=-1){
                    dp[i][dai[i][1]][1] += 1;
                }else if(sho[i][1]!=-1){
                    dp[i][sho[i][1]][0] += 1;
                }
            }else{
                if(ichi[i][0]){
                    rep(j,block+1){
                        dp[i][j][1] += dp[i-1][j][1];
                        dp[i][j][1] %= mod;
                        dp[i][j][0] += dp[i-1][j][0];
                        dp[i][j][0] %= mod;
                    }
                }else if(dai[i][0]!=-1){
                    for(int j=0;j<=dai[i][0];j++){
                        dp[i][j][1] += dp[i-1][j][1];
                        dp[i][j][1] %= mod;
                        dp[i][j][0] += dp[i-1][j][0];
                        dp[i][j][0] %= mod;
                    }
                    for(int j=dai[i][0]+1;j<=block;j++){
                        dp[i][dai[i][0]][1] += (dp[i-1][j][1] + dp[i-1][j][0])%mod;
                        dp[i][dai[i][0]][1] %= mod;
                    }
                }else if(sho[i][0]!=-1){
                    for(int j=0;j<=sho[i][0];j++){
                        dp[i][j][1] += dp[i-1][j][1];
                        dp[i][j][1] %= mod;
                        dp[i][j][0] += dp[i-1][j][0];
                        dp[i][j][0] %= mod;
                    }
                    for(int j=sho[i][0]+1;j<=block;j++){
                        dp[i][sho[i][0]][0] += (dp[i-1][j][1] + dp[i-1][j][0])%mod;
                        dp[i][sho[i][0]][0] %= mod;
                    }
                }
                if(ichi[i][1]){
                    rep(j,block+1){
                        dp[i][j][1] += dp[i-1][j][1];
                        dp[i][j][1] %= mod;
                        dp[i][j][0] += dp[i-1][j][0];
                        dp[i][j][0] %= mod;
                    }
                }else if(dai[i][1]!=-1){
                    for(int j=0;j<=dai[i][1];j++){
                        dp[i][j][1] += dp[i-1][j][1];
                        dp[i][j][1] %= mod;
                        dp[i][j][0] += dp[i-1][j][0];
                        dp[i][j][0] %= mod;
                    }
                    for(int j=dai[i][1]+1;j<=block;j++){
                        dp[i][dai[i][1]][1] += (dp[i-1][j][1] + dp[i-1][j][0])%mod;
                        dp[i][dai[i][1]][1] %= mod;
                    }
                }else if(sho[i][1]!=-1){
                    for(int j=0;j<=sho[i][1];j++){
                        dp[i][j][1] += dp[i-1][j][1];
                        dp[i][j][1] %= mod;
                        dp[i][j][0] += dp[i-1][j][0];
                        dp[i][j][0] %= mod;
                    }
                    for(int j=sho[i][1]+1;j<=block;j++){
                        dp[i][sho[i][1]][0] += (dp[i-1][j][1] + dp[i-1][j][0])%mod;
                        dp[i][sho[i][1]][0] %= mod;
                    }
                }
            }
        }
        rep(i,block){
            res[len] += dp[len-1][i][0];
            res[len] %= mod;    
        }
        res[len] += dp[len-1][block][1];
        res[len] %= mod;
    }
    int ccc = 0;
    sort(p.begin(),p.end());
    for(auto x:p){
        //cerr << x << " " << res[x] << endl;
        for(auto y:dev[x]){
            if(y==x)continue;
            res[x] += (mod-res[y])%mod;
            res[x] %= mod;
        }
        //cerr << x << " " << res[x] << endl;
        ccc += res[x];
        ccc %= mod;
    }
    //cerr << ccc << endl;
    int ans = 0;
    for(auto x:p){
        ans += x*2%mod*res[x]%mod;
        ans %= mod;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 97916