#include <bits/stdc++.h>
using namespace std;

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
  for(auto &e:u) fill_v<T>(e,v...);
}

template<::std::uint_fast64_t mod>
class ModInt{
private:
    using value_type = ::std::uint_fast64_t;
    value_type n;
public:
    ModInt() : n(0) {}
    ModInt(value_type n_) : n(n_ % mod) {}
    ModInt(const ModInt& m) : n(m.n) {}

    template<typename T>
    explicit operator T() const { return static_cast<T>(n); }
    value_type get() const { return n; }

    friend ::std::ostream& operator<<(::std::ostream &os, const ModInt<mod> &a) {
        return os << a.n;
    }

    friend ::std::istream& operator>>(::std::istream &is, ModInt<mod> &a) {
        value_type x;
        is >> x;
        a = ModInt<mod>(x);
        return is;
    }

    bool operator==(const ModInt& m) const { return n == m.n; }
    bool operator!=(const ModInt& m) const { return n != m.n; }
    ModInt& operator*=(const ModInt& m){ n = n * m.n % mod; return *this; }

    ModInt pow(value_type b) const{
        ModInt ans = 1, m = ModInt(*this);
        while(b){
            if(b & 1) ans *= m;
            m *= m;
            b >>= 1;
        }
        return ans;
    }

    ModInt inv() const { return (*this).pow(mod-2); }
    ModInt& operator+=(const ModInt& m){ n += m.n; n = (n < mod ? n : n - mod); return *this; }
    ModInt& operator-=(const ModInt& m){ n += mod - m.n; n = (n < mod ? n : n - mod); return *this; }
    ModInt& operator/=(const ModInt& m){ *this *= m.inv(); return *this; }
    ModInt operator+(const ModInt& m) const { return ModInt(*this) += m; }
    ModInt operator-(const ModInt& m) const { return ModInt(*this) -= m; }
    ModInt operator*(const ModInt& m) const { return ModInt(*this) *= m; }
    ModInt operator/(const ModInt& m) const { return ModInt(*this) /= m; }
    ModInt& operator++(){ n += 1; return *this; }
    ModInt& operator--(){ n -= 1; return *this; }
    ModInt operator++(int){
        ModInt old(n);
        n += 1;
        return old;
    }
    ModInt operator--(int){
        ModInt old(n);
        n -= 1;
        return old;
    }
    ModInt operator-() const { return ModInt(mod-n); }
};

::std::vector<::std::int64_t> divisors(::std::int64_t x) {
    ::std::vector<::std::int64_t> res;
    for (::std::int64_t i = 1; i*i <= x; ++i) {
        if (x % i == 0) {
            res.push_back(i);
            if (i * i != x) res.push_back(x / i);
        }
    }
    ::std::sort(res.begin(), res.end());
    return res;
}

constexpr int64 mod = 998244353;
using Mint = ModInt<mod>;

int64 len; // len per block
vector<map<PII, Mint>> dp;
vector<map<PII, int64>> visited;
string X;
int64 N;

//Mint dfs(int64 dig = 0, int min_loose = N, int max_over = N+1) {
//    if (dig == len) return min_loose < max_over;
//    if (visited[dig].count(PII(min_loose, max_over))) return dp[dig][PII(min_loose, max_over)];
//    visited[dig][PII(min_loose, max_over)] = 1;
//    auto &ret = dp[dig][PII(min_loose, max_over)];
//    ret = 0;
//
//    int64 lim = min_loose > dig ? X[dig]-'0'+1 : 2;
//    REP(x, lim) {
//        bool out = 0;
//        int64 y = x;
//        int64 new_min_loose = min_loose;
//        int64 new_max_over = max_over;
//        for (int64 j = dig; j < min_loose; j += len) {
//            if (X[j]-'0' < y) {
//                chmin(new_max_over, j);
//            }
//            if (X[j]-'0' > y) {
//                chmin(new_min_loose, j);
//            }
//            y = 1-y;
//        }
////        if (out) continue;
//        ret += dfs(dig+1, new_min_loose, new_max_over);
//    }
//    cout << dig << " " << min_loose << " " << ret << endl;
//    return ret;
//}

bool ok(int64 min_loose = N+1, int64 min_over = N+1) {
    REP(i, len) {
        int64 y = X[i]-'0';
        for (int64 j = i; j < N; j+=len) {
            if (X[j]-'0' > y) {
                chmin(min_loose, j);
            }
            if (X[j]-'0' < y) {
                chmin(min_over, j);
            }
            y = 1-y;
        }
    }
    return min_loose <= min_over;
}

int main(void) {
    cin.tie(0);
    ios::sync_with_stdio(false);

    cin >> N >> X;
    auto divs = divisors(N);

    sort(all(divs), greater<int64>());
    Mint res = 0, cnt = 0;
    map<int64, Mint> mp;
    REP(i, divs.size()) {
        if (divs[i]%2 == 0 && divs[i] != 1) continue;
        len = N / divs[i];
//        dp = vector<map<PII, Mint>>(len+1);
//        visited = vector<map<PII, int64>>(len+1);
//        Mint ret = dfs();
        Mint ret = 0;
        REP(j, len) {
            ret *= 2;
            if (X[j]-'0' == 1) {
                ret++;
            }
        }
        ret++;
        if (!ok()) {
            ret--;
        }

        mp[len] = ret;
    }
    for (auto &x : mp) {
        for (auto &y : mp) {
            if (x.fs == y.fs) continue;
            if (y.fs % x.fs == 0) {
                y.sc -= x.sc;
            }
        }
    }

    for (auto &x : mp) {
        res += x.sc * x.fs * 2;
    }
    cout << res << endl;
}


Measured memory_bytes: 720