#pragma comment(linker, "/STACK:512000000")
//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#include <bits/stdc++.h>
#ifdef AIM
#include <sys/resource.h>
#endif
using namespace std;

#define all(a) a.begin(), a.end()
typedef long long li;
typedef long double ld;
void solve(__attribute__((unused)) bool);
void precalc();
clock_t start;
#define FILENAME ""

int main() {
#ifdef AIM
  string s = FILENAME;
//    assert(!s.empty());
  freopen("/home/alexandero/ClionProjects/cryptozoology/input.txt", "r", stdin);
  //freopen("/home/alexandero/ClionProjects/cryptozoology/output.txt", "w", stdout);
#else
//    freopen(FILENAME ".in", "r", stdin);
//    freopen(FILENAME ".out", "w", stdout);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
#endif
    start = clock();
    int t = 1;
#ifndef AIM
  cout.sync_with_stdio(0);
  cin.tie(0);
#endif

#ifdef AIM
  const rlim_t kStackSize = 256 * 1024 * 1024;
  struct rlimit rl;
  int result;

  result = getrlimit(RLIMIT_STACK, &rl);
  if (result == 0)
  {
    if (rl.rlim_cur < kStackSize)
    {
      rl.rlim_cur = kStackSize;
      result = setrlimit(RLIMIT_STACK, &rl);
      if (result != 0)
      {
        fprintf(stderr, "setrlimit returned result = %d\n", result);
      }
    }
  }
#endif

  precalc();
  cout.precision(10);
  cout << fixed;
  //cin >> t;
  int testNum = 1;
  while (t--) {
      //cout << "Case #" << testNum++ << ": ";
      solve(true);
  }
  cout.flush();
#ifdef AIM1
    while (true) {
      solve(false);
  }
#endif

#ifdef AIM
  cout.flush();
  auto end = clock();

  usleep(10000);
  print_stats(end - start);
  usleep(10000);
#endif

    return 0;
}

template<typename T>
T binpow(T q, T w, T mod) {
    if (!w)
        return 1 % mod;
    if (w & 1)
        return q * 1LL * binpow(q, w - 1, mod) % mod;
    return binpow(q * 1LL * q % mod, w / 2, mod);
}

template<typename T>
T gcd(T q, T w) {
    while (w) {
        q %= w;
        swap(q, w);
    }
    return q;
}
template<typename T>
T lcm(T q, T w) {
    return q / gcd(q, w) * w;
}

template <typename T>
void make_unique(vector<T>& a) {
    sort(all(a));
    a.erase(unique(all(a)), a.end());
}

template<typename T>
void relax_min(T& cur, T val) {
    cur = min(cur, val);
}

template<typename T>
void relax_max(T& cur, T val) {
    cur = max(cur, val);
}

void precalc() {
}

#define int li
const int mod = 998244353;

const int C = 200500;
int lp[C];
int mob[C];

void solve(__attribute__((unused)) bool read) {
  for (int i = 2; i < C; ++i) {
    if (lp[i] == 0) {
      lp[i] = i;
      for (int j = i * i; j < C; j += i) {
        lp[j] = i;
      }
    }
  }
  mob[1] = 1;
  for (int i = 2; i < C; ++i) {
    int p = lp[i];
    if (p == i) {
      mob[i] = -1;
      continue;
    }
    if (i / p % p == 0) {
      mob[i] = 0;
      continue;
    }
    mob[i] = -mob[i / p];
  }

  int n;
  cin >> n;
  int no_twos = n;
  int mult = 1;
  while (no_twos % 2 == 0) {
    no_twos /= 2;
    mult *= 2;
  }
  string s;
  cin >> s;
  vector<int> a(n);
  for (int i = 0; i < n; ++i) {
    a[i] = s[i] - '0';
  }
  vector<int> powers(n + 1, 1);
  for (int i = 1; i < powers.size(); ++i) {
    powers[i] = powers[i - 1] * 2 % mod;
  }
  vector<pair<int, int>> vec;
  //cout << no_twos << " " << mult << endl;
  for (int d = 1; d <= no_twos; ++d) {
    if (no_twos % d) {
      continue;
    }
    int period = d * mult;
    int prefixes = 0;
    for (int i = 0; i < period; ++i) {
      if (a[i] == 1) {
        prefixes += powers[period - i - 1];
        prefixes %= mod;
      }
    }
    bool f = true;
    for (int i = 0; i < n; ++i) {
      int need = a[i % period];
      if (i / period % 2) {
        need ^= 1;
      }
      if (a[i] > need) {
        break;
      }
      if (a[i] < need) {
        f = false;
        break;
      }
    }
    if (f) {
      ++prefixes;
    }
    vec.push_back({period, prefixes});
    //cout << d << " " << prefixes << endl;
  }
  int res = 0;
  for (int i = 0; i < vec.size(); ++i) {
    for (int j = 0; j < i; ++j) {
      if (vec[i].first % vec[j].first) {
        continue;
      }
      vec[i].second -= vec[j].second;
    }

    //cout << vec[i].first << " " << vec[i].second << endl;

    res += vec[i].second * 2 * vec[i].first;
    res %= mod;
  }
  if (res < 0) {
    res += mod;
  }
  cout << res << "\n";


  /*int n = 9;
  map<int, vector<int>> mapa;
  for (int mask = 0; mask < (1 << n); ++mask) {
    int cur_mask = mask;
    int cnt = 0;
    do {
      cur_mask = ((cur_mask & 1) ^ 1) * (1 << (n - 1)) + (cur_mask >> 1);
      ++cnt;
    } while (cur_mask != mask);
    mapa[cnt].push_back(mask);
  }
  for (auto item : mapa) {
    cout << "res: " << item.first;
    cout << " cnt: " << item.second.size() << " vals:";
    int c = 0;
    for (int mask : item.second) {
      ++c;
      if (c > 20) {
        break;
      }
      cout << " ";
      for (int i = n - 1; i >= 0; --i) {
        cout << (bool)(mask & (1 << i));
      }
    }
    cout << "\n";
  }*/
}

Measured memory_bytes: 6804