#include <iostream>
#include <vector>
#include <cstdio>
#include <sstream>
#include <map>
#include <string>
#include <algorithm>
#include <queue>
#include <cmath>
#include <functional>
#include <set>
#include <ctime>
#include <random>
#include <chrono>
#include <cassert>
#include <tuple>
#include <utility>
using namespace std;

namespace {
  using Integer = long long; //__int128;
  template<class T, class S> istream& operator >> (istream& is, pair<T,S>& p){return is >> p.first >> p.second;}
  template<class T> istream& operator >> (istream& is, vector<T>& vec){for(T& val: vec) is >> val; return is;}
  template<class T> istream& operator ,  (istream& is, T& val){ return is >> val;}
  template<class T, class S> ostream& operator << (ostream& os, const pair<T,S>& p){return os << p.first << " " << p.second;}
  template<class T> ostream& operator << (ostream& os, const vector<T>& vec){for(size_t i=0; i<vec.size(); i++) os << vec[i] << (i==vec.size()-1?"":" "); return os;}
  template<class T> ostream& operator ,  (ostream& os, const T& val){ return os << " " << val;}

  template<class H> void print(const H& head){ cout << head; }
  template<class H, class ... T> void print(const H& head, const T& ... tail){ cout << head << " "; print(tail...); }
  template<class ... T> void println(const T& ... values){ print(values...); cout << endl; }

  template<class H> void eprint(const H& head){ cerr << head; }
  template<class H, class ... T> void eprint(const H& head, const T& ... tail){ cerr << head << " "; eprint(tail...); }
  template<class ... T> void eprintln(const T& ... values){ eprint(values...); cerr << endl; }

  class range{ Integer start_, end_, step_; public: struct range_iterator{ Integer val, step_; range_iterator(Integer v, Integer step) : val(v), step_(step) {} Integer operator * (){return val;} void operator ++ (){val += step_;} bool operator != (range_iterator& x){return step_ > 0 ? val < x.val : val > x.val;} }; range(Integer len) : start_(0), end_(len), step_(1) {} range(Integer start, Integer end) : start_(start), end_(end), step_(1) {} range(Integer start, Integer end, Integer step) : start_(start), end_(end), step_(step) {} range_iterator begin(){ return range_iterator(start_, step_); } range_iterator   end(){ return range_iterator(  end_, step_); } };

  inline string operator "" _s (const char* str, size_t size){ return move(string(str)); }
  constexpr Integer my_pow(Integer x, Integer k, Integer z=1){return k==0 ? z : k==1 ? z*x : (k&1) ? my_pow(x*x,k>>1,z*x) : my_pow(x*x,k>>1,z);}
  constexpr Integer my_pow_mod(Integer x, Integer k, Integer M, Integer z=1){return k==0 ? z%M : k==1 ? z*x%M : (k&1) ? my_pow_mod(x*x%M,k>>1,M,z*x%M) : my_pow_mod(x*x%M,k>>1,M,z);}
  constexpr unsigned long long operator "" _ten (unsigned long long value){ return my_pow(10,value); }

  inline int k_bit(Integer x, int k){return (x>>k)&1;} //0-indexed

  mt19937 mt(chrono::duration_cast<chrono::nanoseconds>(chrono::steady_clock::now().time_since_epoch()).count());

  template<class T> string join(const vector<T>& v, const string& sep){ stringstream ss; for(size_t i=0; i<v.size(); i++){ if(i>0) ss << sep; ss << v[i]; } return ss.str(); }

  inline string operator * (string s, int k){ string ret; while(k){ if(k&1) ret += s; s += s; k >>= 1; } return ret; }
}
constexpr long long mod = 998244353;

vector<int> z_algorithm(const string& s){
  int n = s.size();
  vector<int> z(n, 0);
  int l = 0;
  for(int i=1; i<n; i++){
    if( i+z[i-l] < l+z[l] ){
      z[i] = z[i-l];
    }else{
      int j = max(0, l+z[l]-i);
      while( i+j < n && s[j] == s[i+j] ) j++;
      z[i] = j;
      l = i;
    }
  }
  return z;
}

vector<long long> Eratosthenes(long long N){
  vector<bool> v(N+1, true);
  v[0] = v[1] = false;
  long long sqN = sqrt(N);
  for(int i=2; i<=sqN; i++){
    if(v[i] == false) continue;
    for(long long j=i*i; j<=N; j+=i){
      v[j] = false;
    }
  }
  vector<long long> Prime;
  for(long long i=2; i<=N; i++){
    if(v[i]==true) Prime.push_back(i);
  }
  return Prime;
}


int main(){
  long long n;
  cin >> n;
  string x;
  cin >> x;

  if(n == 1){
    if(x == "0"s){
      println(2);
    }else{
      println(4);
    }
    return 0;
  }

  auto xz = z_algorithm(x);

  map<long long, long long> memo_smaller;
  set<int> memo_exact;


  long long ans = 0;
  long long period_cnt = 0;
  for(long long k=n/3; k>=1; k--){
    if(n % k != 0) continue;
    if((n / k) % 2 != 1) continue;
    long long p = 2*k;

    vector<vector<long long>> dp(k+1, vector<long long>(8, 0));
    dp[0][0b000] = 1;
    for(int i=0; i<k; i++){
      int xc = x[i] - '0';
      int xc_ = x[i+k] - '0';
      for(int smaller=0; smaller<=1; smaller++){
        for(int bg=0; bg<=1; bg++){
          for(int bs=0; bs<=1; bs++){
            if(dp[i][(smaller<<2) | (bg<<1) | bs] == 0) continue;
            for(int b=0; b<=1; b++){
              if(!smaller && xc < b) continue;
              int smaller__ = smaller || xc > b;
              int bg__ = bg || !bs && xc_ < (b^1);
              int bs__ = bs || xc_ > (b^1);
              (dp[i+1][(smaller__<<2) | (bg__<<1) | bs__] += dp[i][(smaller<<2) | (bg<<1) | bs]) %= mod;
            }
          }
        }
      }
    }
    memo_smaller[p] = dp[k][0b100] + dp[k][0b110] + dp[k][0b101] + dp[k][0b111] + dp[k][0b001];
    period_cnt += memo_smaller[p];

    if(dp[k][0b000]){
      string y = x.substr(0, p);
      string z;
      while(z.size() <n){
        z += y;
      }
      z = z.substr(0, n);
      if(x >= z){
        memo_exact.insert(p);
        period_cnt++;
      }
    }
  }

  eprintln(period_cnt);

  for(auto p: memo_exact){
    for(int j=2*p; j<n; j+=p){
      if(xz[j-p] < p) break;
      if(memo_exact.count(j) == 0) continue;
      memo_exact.erase(j);
      period_cnt--;
    }
    bool exact = true;
    for(int j=2*p; j<n; j+=p){
      if(xz[j-p] < p){
        exact = false;
      }
      if(memo_smaller.count(j) == 0) continue;
      if(!exact){
        auto& v = memo_smaller[j];
        v = v-1+mod;
        if(v >= mod) v -= mod;
      }
    }

    ans = (ans + p-2*n + mod) % mod;
  }

  for(auto v: memo_smaller){
    int p = v.first;
    long long c = v.second;

    for(int j=2*p; j<n; j+=p){
      if(memo_smaller.count(j) == 0) continue;
      memo_smaller[j] += -c + mod;
      period_cnt -= c;
      if(memo_smaller[j] >= mod) memo_smaller[j] %= mod;
    }

    ans = (ans + (p - 2*n + mod) % mod * c) % mod;
  }



  eprintln("periodic_cnt =", period_cnt);
  eprintln("periodic_sum =", ans);

  long long tmp = 0;
  for(int i=0; i<n; i++){
    tmp <<= 1;
    tmp %= mod;
    if(x[i] == '1'){
      tmp++;
      tmp %= mod;
    }
  }
  tmp++;
  tmp %= mod;
  tmp *= 2*n;
  tmp %= mod;

  // long long tmp2 = 0;
  // for(long long i=60; i>=0; i--){
  //   tmp2 <<= 1;
  //   while(tmp2 >= mod){
  //     tmp2 -= mod;
  //   }
  //   if((period_cnt>>i) & 1){
  //     tmp2++;
  //     if(tmp2 >= mod) tmp2 -= mod;
  //   }
  // }

  // tmp = (tmp - tmp2 + mod) % mod;

  ans = (ans + tmp) % mod;
  println(ans);



  // long long ans2 = 0;
  // map<int, vector<string>> res;
  // for(int i=0; i<(1<<n); i++){
  //   string b;
  //   for(int j=0; j<n; j++){
  //     b += ((i>>j) & 1) ?  '1' : '0';
  //   }
  //   for(int j=0; j<n; j++){
  //     b += !((i>>j) & 1) ?  '1' : '0';
  //   }
  //   for(int j=0; j<n; j++){
  //     b += ((i>>j) & 1) ?  '1' : '0';
  //   }

  //   string bb = b.substr(0, n);
  //   if(bb > x) continue;
  //   for(int j=1; ; j++){
  //     if(bb == b.substr(j, n)){
  //       res[j].push_back(bb);
  //       ans2 += j;
  //       break;
  //     }
  //   }
  // }

  // eprintln("ans2 = ", ans2);
  // int pc = 0;
  // for(auto p : res){
  //   if(p.first == 2*n) continue;
  //   pc += p.second.size();
  //   eprintln(p.first);
  //   eprintln(join(p.second, "\n"));
  //   eprintln("");
  // }
  // eprintln("periodic_cnt =", pc);

  return 0;
}


Measured memory_bytes: 7940