Problem:
Score : 800 points

Problem Statement

Given are integers N and X. For each integer k between 0 and X (inclusive), find the answer to the following question, then compute the sum of all those answers, modulo 998244353.

Let us repeat the following operation on the integer k. Operation: if the integer is currently odd, subtract 1 from it and divide it by 2; otherwise, divide it by 2 and add 2^{N-1} to it. How many operations need to be performed until k returns to its original value? (The answer is considered to be 0 if k never returns to its original value.)

Constraints

1 \leq N \leq 2\times 10^5

0 \leq X < 2^N

X is given in binary and has exactly N digits. (In case X has less than N digits, it is given with leading zeroes.)

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
X

Output

Print the sum of the answers to the questions for the integers between 0 and X (inclusive), modulo 998244353.

Sample Input 1

3
111

Sample Output 1

40

For example, for k=3, the operation changes k as follows: 1,0,4,6,7,3. Therefore the answer for k=3 is 6.

Sample Input 2

6
110101

Sample Output 2

616

Sample Input 3

30
001110011011011101010111011100

Sample Output 3

549320998

Solution in C++14 (GCC 5.4.1) (judge verdict: Runtime Error)

#include <bits/stdc++.h>
#define st first
#define nd second

using namespace std;

void debug_out() { cerr << endl; }
template<class T> ostream& prnt(ostream& out, T v) { out << v.size() << '\n'; for(auto e : v) out << e << ' '; return out;}
template<class T> ostream& operator<<(ostream& out, vector <T> v) { return prnt(out, v); }
template<class T> ostream& operator<<(ostream& out, set <T> v) { return prnt(out, v); }
template<class T1, class T2> ostream& operator<<(ostream& out, map <T1, T2> v) { return prnt(out, v); }
template<class T1, class T2> ostream& operator<<(ostream& out, pair<T1, T2> p) { return out << '(' << p.st << ' ' << p.nd << ')'; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << H; debug_out(T...);}

#define dbg(...) cerr << #__VA_ARGS__ << " ->", debug_out(__VA_ARGS__)
#define dbg_v(x, n) do{cerr<<#x"[]: ";for(long long _=0;_<n;++_)cerr<<x[_]<<" ";cerr<<'\n';}while(0)
#define dbg_ok cerr<<"OK!\n"

const long long N = 200100;
const long long MOD = 998244353;
long long n, ans, p2[N], c[N];
string x;

char op(char c, long long nr) {
	if(nr % 2 == 0) return c;
	if(c == '1') return '0';
	return '1';
}

long long cnt(long long pos) {
	long long ret = 0;
	for(long long i = 0; i < n; i++)  {
		// dbg(i);
		if(i < pos) {
			if(x[i] == '1') 
				ret += p2[pos - i - 1];
			ret %= MOD;
		} else  {
			// dbg(x[i], op(x[i - pos], i/pos));
			if(op(x[i % pos], i / pos) < x[i]) {
				ret++;
				break;
			} else if(op(x[i % pos], i / pos) > x[i]) break;
		}
		// if(i % pas == 0) c = '1' + '0' - c;

		// if(x[i] == c) continue;
		// if(x[i] < c) return false;
		// if(x[i] > c) return true;
	}
	assert(ret > 0);
	return ret;
}

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


	cin >> n >> x;
	// dbg(cnt(2));
	// return 0;
	p2[0] = 1;
	for(long long i = 1; i < N; i++)
		p2[i] = 2LL * p2[i - 1] % MOD;
	// reverse(x.begin(), x.end());

	long long p2 = 1;
	for(long long i = x.size() - 1; i >= 0; i--) {
		if(x[i] == '1')
			ans += p2;
		p2 = 2LL * p2 % MOD;
	}
	dbg(p2);
	ans = 2LL * ans * n % MOD;
	ans += 2LL * n;
	ans %= MOD;

	// dbg(ans);
	for(long long i = 1; i < n; i++) {
		if(n % i == 0 && (n / i) % 2 == 1) {
			// dbg(i);
			c[i] = cnt(i);
			// dbg(c);
			for(int j = 1; j < i; j++)
				if(i % j == 0)
					c[i] -= c[j];
			c[i] %= MOD;

			ans -= 2 * n * c[i];
			ans += 2 * i * c[i];
			ans %= MOD;
		}
	}
	cout << (ans % MOD + MOD) % MOD<< '\n';
}