#include <bits/stdc++.h>
    #define ll long long
    #define db long double
    #define x first
    #define y second
    #define mp make_pair
    #define pb push_back
    #define all(a) a.begin(), a.end()
     
    using namespace std;
     
    const int mod = 998244353;
     
    int sum(int x, int y){
    	if (x+y < 0) return x+y+mod;
    	if (x+y>=mod) return x+y-mod;
    	return x+y;
    }
     
    int mult(int x, int y){
    	return ((ll) x * (ll) y) % (ll) mod;
    }
     
    vector<vector<int> > data;
     
    vector<int> conc;
    vector<bool> used;
     
    void dfs(int vertex, int par){
    	conc[vertex] = par;
    	for (int i=0; i < data[vertex].size(); ++i){
    		int to = data[vertex][i];
    		if (conc[to] != -1) continue;
    		dfs(to, 1-par);
    	}
    }
     
    void dfs2(int vertex){
    	used[vertex] = true;
    	for (int i=0; i < data[vertex].size(); ++i){
    		int to = data[vertex][i];
    		if (used[to]) continue;
    		dfs2(to);
    	}
    }
     
    int pw2[300000];
     
    main(){
    #ifdef LOCAL
    	freopen("B_input.txt", "r", stdin);
    	//freopen("A_output.txt", "w", stdout);
    #endif
    	ios_base::sync_with_stdio(0);
    	cin.tie(0);
     
    	pw2[0] = 1;
    	for (int i=1; i < 300000; ++i) pw2[i] = mult(2, pw2[i-1]);
     
    	int n;
    	cin >> n;
     
    	string x;
    	cin >> x;
    	int total = 0;
    	int pw = 1;
    	for (int i=x.size()-1; i >= 0; i--){
    		if (x[i] == '1') total = sum(total, pw);
    		pw = mult(pw, 2);
    	}


     
     
    	int l = -1;
    	for (int i=1; i <= n; ++i){
    		if ((i / __gcd(i, n)) % 2 == 0){
    			l = i;
    			break;
    		}
    	}
     
    	if (l==-1){
    		total = sum(total, 1);
    		cout << mult(total, mult(2, n));
    		exit(0);
    	}
     
    	int q = l;
     
    	int res=0, spec=0;
     
    	vector<int> num = {0};

     
    	for (l=q; l <= n; l += q){
    		if ((2*n)%l!=0){
    			num.push_back(0);
    			continue;
    		}
    		int tut=0;
    		data.assign(l, {});
    		used.assign(l, false);
    		int G = __gcd(n, l);
    		//cout << G << endl;
    		for (int i=0; i < l; ++i){
    			int T = (i-G+l)%l;
    			data[i].push_back(T);
    			data[T].push_back(i);
    		}
     
     
    		int cmp = 0;
    		for (int i=0;i<l; ++i){
    			if (used[i]) continue;
    			dfs2(i);
    			cmp++;
    		}
     
    		conc.assign(l, -1);
     
    		bool if_out = false;
     
    		for (int i=0; i < n; ++i){
    			//cout << i << " " << cmp << endl;
    			if (conc[i%l] == -1){
    				if (x[i] == '0'){
    					cmp--;
    					dfs(i%l, 0);
    				}
    				else{
    					tut = sum(tut, pw2[cmp-1]);
    					cmp--;
    					dfs(i%l, 1);
    				}
    			}
    			else if (conc[i%l] == 0){
    				if (x[i] == '1'){
    					tut = sum(tut, pw2[cmp]);
    					if_out = true;
    					break;
    				}
    				else continue;
    			}
    			else{
    				if (x[i] == '0'){
    					if_out=true;
    					break;
    				}
    				else continue;
    			}
    		}
    		if (!if_out) tut = sum(tut, 1);
    		for (int j=1; j < num.size(); ++j){
    			if ((l/q)%j == 0){
    				tut = sum(tut, -num[j]);
    			}
    		}
    		num.push_back(tut);
    		//tut = sum(tut, -spec);
    		spec = sum(spec, tut);
    		res = sum(res, mult(tut, l));
     
    		//cout << l << " " << tut << endl;
    	}
     
    	total = sum(total, 1);
     
     
    	res = sum(mult(2*n, sum(total, -spec)), res);
     
    	cout << res;
    }

Measured memory_bytes: 10124