#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...) 42
#endif

using ll = long long;
using ld = long double;
using D = double;
using uint = unsigned int;
template<typename T>
using pair2 = pair<T, T>;
using pii = pair<int, int>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second

const int MOD = 998244353;

inline int mul(int a, int b)
{
	return ((ll)a * b) % MOD;
}

inline int add(int a, int b)
{
	a += b;
	if (a >= MOD) a -= MOD;
	return a;
}

inline int sub(int a, int b)
{
	a -= b;
	if (a < 0) a += MOD;
	return a;
}

const int maxn = 400005;

char s[maxn];
vector<int> divsn;
vector<pair2<int>> divs[maxn];
vector<array<int, 2>> cntset[maxn];
int isset[maxn];
int cntbad[maxn], cntfree[maxn];
int n;
int ans[maxn];
int answer;
int p2[maxn];

void adddiv(int i, int rem, int t)
{
	if (cntset[i][rem][0] > 0 && cntset[i][rem][1] > 0) cntbad[i] += t;
	else if (cntset[i][rem][0] == 0 && cntset[i][rem][1] == 0) cntfree[i] += t;
}

void sett(int pos, int v)
{
	//cout << "sett " << pos << ' ' << v << endl;
	for (int i = 0; i < (int)divsn.size(); i++)
	{
		int rem = pos % divsn[i];
		adddiv(i, rem, -1);
		if (isset[pos] != -1)
		{
			cntset[i][rem][isset[pos]]--;
		}
		cntset[i][rem][v]++;
		adddiv(i, rem, 1);
		//cout << divsn[i] << ' ' << rem << ' ' << cntfree[i] << ' ' << cntset[i][rem][isset[pos]] << endl;
	}
	isset[pos] = v;
}

void solve(int fixed)
{
	//cout << "solve " << fixed << endl;
	for (int i = 0; i < (int)divsn.size(); i++) if (n % divsn[i] != 0)
	{
		ans[i] = 0;
		if (cntbad[i] == 0) ans[i] = p2[cntfree[i] / 2];
		//cout << divsn[i] << ' ' << ans[i] << endl;
		for (auto t : divs[divsn[i]])
		{
			//if (t.se == 1) ans[i] = add(ans[i], ans[t.fi]);
			//else if (t.se == -1) ans[i] = sub(ans[i], ans[t.fi]);
			ans[i] = sub(ans[i], ans[t.fi]);
		}
		//cout << "mod " << ans[i] << endl;
		answer = add(answer, mul(divsn[i], ans[i]));
	}
}

int main()
{
	scanf("%d", &n);
	//n = 200000;
	p2[0] = 1;
	for (int i = 1; i <= 2 * n; i++) p2[i] = mul(p2[i - 1], 2);
	for (int i = 1; i <= 2 * n; i++) if ((2 * n) % i == 0 && n % i != 0)
	{
		divsn.pb(i);
		int mu = -1;
		int cur = i;
		for (int j = 2; j * j <= cur; j++) if (cur % j == 0)
		{
			if (cur % (j * j) == 0) mu = 0;
			while (cur % j == 0) cur /= j;
			mu *= -1;
		}
		if (cur > 1) mu *= -1;
		for (int j = i * 2; j <= 2 * n; j += i) divs[j].pb({(int)divsn.size() - 1, mu});
	}
	scanf("%s", s);
	//for (int i = 0; i < n; i++) s[i] = '1';
	
	for (int i = 0; i < (int)divsn.size(); i++)
	{
		cntset[i].resize(divsn[i]);
		for (int j = 0; j < divsn[i]; j++) adddiv(i, j, 1);
	}
	
	for (int i = 0; i < 2 * n; i++) isset[i] = -1;
	for (int fixed = 0; fixed < n; fixed++)
	{
		if (fixed > 0)
		{
			sett(fixed - 1, s[fixed - 1] - '0');
			sett(n + fixed - 1, 1 - (s[fixed - 1] - '0'));
		}
		if (s[fixed] == '1')
		{
			sett(fixed, 0);
			sett(n + fixed, 1);
			solve(fixed);
		}
	}
	sett(n - 1, s[n - 1] - '0');
	sett(n + n - 1, 1 - (s[n - 1] - '0'));
	solve(n);
	cout << answer << endl;
    return 0;
}


Measured memory_bytes: 42624