Problem:
E: 往復文字列 / Round-trip String
物語
ここは全人類が競技プログラマーになった世界。この世界ではみなさんの生きる現代では考えられないような習慣が多数存在する。その中の一つに、両親、特に母親に感謝の証を表す時は、文字列を送るという風習がある。送る文字列としてどのような文字列がふさわしいかは地域差があるが、北の大地北海道では、できるだけシンプルな文字列が贈り物としてふさわしい。また、送られた側の母親は子供に返礼として、送られた文字列がどれほど美しいかを答える必要がある。
さて、今あなたは1児の母親から相談を受けている。その母親は子供から素晴らしそうな文字列をもらったのだが、どれくらい素晴らしいのかうまく測れないでいるそうだ。北海道の風習では、母親に送る文字列
T
はある文字列
S
を往復させて作ることになっている。この時、
S
ができるだけ短い文字列ならばより素晴らしい文字列
T
である。母親は子供の頑張りに報いるため、
T
を作ることができる文字列の中で、最短の文字列を見つけてあげたいが、それはなかなか難しいとのことだ。あなたのプログラミング能力を駆使して母親の悩みを解決して欲しい。
問題
長さが
2
以上の文字列
S
から、以下のルールに従って長さ
N
の文字列
T
を生成する。ここで、
S
の文字列長を
K
とし、
T[i]
は文字列
T
の
i
番目の文字を表す。ここで、
T
の先頭文字は
0
番目の文字とする。
T[i] = S[K - 1 - | (i
$\bmod$
(2K - 2)) - K + 1 |]
T
のみが与えられたとき、
T
を生成する文字列は複数考えられる。 それらの文字列の中で最小の文字列長
K_{min}
を出力せよ。
入力形式
N
T
制約
2 \leq N = |T| \leq 1,000,000
文字列は英小文字のみからなる
出力形式
T
を生成する長さ最小の文字列
S
の長さ
K_{min}
を出力してください。
入力例1
6
tabata
出力例1
3
tabata
、
tabat
、
tab
の
3
つが考えられますが、
tab
が長さ最小なので、答えは
3
です。
入力例2
4
hcpc
出力例2
3
入力例3
60
aaaaaabbbbbbbbbbbaaaaaaaaaaabbbbbbbbbbbaaaaaaaaaaabbbbbbbbbb
出力例3
12

Submitted solutions:

code_snippet: #line 1 "main.cpp"
#include <bits/stdc++.h>
#line 1 "/home/anqooqie/.proconlib/lib/ac-library/atcoder/string.hpp"



#line 9 "/home/anqooqie/.proconlib/lib/ac-library/atcoder/string.hpp"

namespace atcoder {

namespace internal {

std::vector<int> sa_naive(const std::vector<int>& s) {
    int n = int(s.size());
    std::vector<int> sa(n);
    std::iota(sa.begin(), sa.end(), 0);
    std::sort(sa.begin(), sa.end(), [&](int l, int r) {
        if (l == r) return false;
        while (l < n && r < n) {
            if (s[l] != s[r]) return s[l] < s[r];
            l++;
            r++;
        }
        return l == n;
    });
    return sa;
}

std::vector<int> sa_doubling(const std::vector<int>& s) {
    int n = int(s.size());
    std::vector<int> sa(n), rnk = s, tmp(n);
    std::iota(sa.begin(), sa.end(), 0);
    for (int k = 1; k < n; k *= 2) {
        auto cmp = [&](int x, int y) {
            if (rnk[x] != rnk[y]) return rnk[x] < rnk[y];
            int rx = x + k < n ? rnk[x + k] : -1;
            int ry = y + k < n ? rnk[y + k] : -1;
            return rx < ry;
        };
        std::sort(sa.begin(), sa.end(), cmp);
        tmp[sa[0]] = 0;
        for (int i = 1; i < n; i++) {
            tmp[sa[i]] = tmp[sa[i - 1]] + (cmp(sa[i - 1], sa[i]) ? 1 : 0);
        }
        std::swap(tmp, rnk);
    }
    return sa;
}

// SA-IS, linear-time suffix array construction
// Reference:
// G. Nong, S. Zhang, and W. H. Chan,
// Two Efficient Algorithms for Linear Time Suffix Array Construction
template <int THRESHOLD_NAIVE = 10, int THRESHOLD_DOUBLING = 40>
std::vector<int> sa_is(const std::vector<int>& s, int upper) {
    int n = int(s.size());
    if (n == 0) return {};
    if (n == 1) return {0};
    if (n == 2) {
        if (s[0] < s[1]) {
            return {0, 1};
        } else {
            return {1, 0};
        }
    }
    if (n < THRESHOLD_NAIVE) {
        return sa_naive(s);
    }
    if (n < THRESHOLD_DOUBLING) {
        return sa_doubling(s);
    }

    std::vector<int> sa(n);
    std::vector<bool> ls(n);
    for (int i = n - 2; i >= 0; i--) {
        ls[i] = (s[i] == s[i + 1]) ? ls[i + 1] : (s[i] < s[i + 1]);
    }
    std::vector<int> sum_l(upper + 1), sum_s(upper + 1);
    for (int i = 0; i < n; i++) {
        if (!ls[i]) {
            sum_s[s[i]]++;
        } else {
            sum_l[s[i] + 1]++;
        }
    }
    for (int i = 0; i <= upper; i++) {
        sum_s[i] += sum_l[i];
        if (i < upper) sum_l[i + 1] += sum_s[i];
    }

    auto induce = [&](const std::vector<int>& lms) {
        std::fill(sa.begin(), sa.end(), -1);
        std::vector<int> buf(upper + 1);
        std::copy(sum_s.begin(), sum_s.end(), buf.begin());
        for (auto d : lms) {
            if (d == n) continue;
            sa[buf[s[d]]++] = d;
        }
        std::copy(sum_l.begin(), sum_l.end(), buf.begin());
        sa[buf[s[n - 1]]++] = n - 1;
        for (int i = 0; i < n; i++) {
            int v = sa[i];
            if (v >= 1 && !ls[v - 1]) {
                sa[buf[s[v - 1]]++] = v - 1;
            }
        }
        std::copy(sum_l.begin(), sum_l.end(), buf.begin());
        for (int i = n - 1; i >= 0; i--) {
            int v = sa[i];
            if (v >= 1 && ls[v - 1]) {
                sa[--buf[s[v - 1] + 1]] = v - 1;
            }
        }
    };

    std::vector<int> lms_map(n + 1, -1);
    int m = 0;
    for (int i = 1; i < n; i++) {
        if (!ls[i - 1] && ls[i]) {
            lms_map[i] = m++;
        }
    }
    std::vector<int> lms;
    lms.reserve(m);
    for (int i = 1; i < n; i++) {
        if (!ls[i - 1] && ls[i]) {
            lms.push_back(i);
        }
    }

    induce(lms);

    if (m) {
        std::vector<int> sorted_lms;
        sorted_lms.reserve(m);
        for (int v : sa) {
            if (lms_map[v] != -1) sorted_lms.push_back(v);
        }
        std::vector<int> rec_s(m);
        int rec_upper = 0;
        rec_s[lms_map[sorted_lms[0]]] = 0;
        for (int i = 1; i < m; i++) {
            int l = sorted_lms[i - 1], r = sorted_lms[i];
            int end_l = (lms_map[l] + 1 < m) ? lms[lms_map[l] + 1] : n;
            int end_r = (lms_map[r] + 1 < m) ? lms[lms_map[r] + 1] : n;
            bool same = true;
            if (end_l - l != end_r - r) {
                same = false;
            } else {
                while (l < end_l) {
                    if (s[l] != s[r]) {
                        break;
                    }
                    l++;
                    r++;
                }
                if (l == n || s[l] != s[r]) same = false;
            }
            if (!same) rec_upper++;
            rec_s[lms_map[sorted_lms[i]]] = rec_upper;
        }

        auto rec_sa =
            sa_is<THRESHOLD_NAIVE, THRESHOLD_DOUBLING>(rec_s, rec_upper);

        for (int i = 0; i < m; i++) {
            sorted_lms[i] = lms[rec_sa[i]];
        }
        induce(sorted_lms);
    }
    return sa;
}

}  // namespace internal

std::vector<int> suffix_array(const std::vector<int>& s, int upper) {
    assert(0 <= upper);
    for (int d : s) {
        assert(0 <= d && d <= upper);
    }
    auto sa = internal::sa_is(s, upper);
    return sa;
}

template <class T> std::vector<int> suffix_array(const std::vector<T>& s) {
    int n = int(s.size());
    std::vector<int> idx(n);
    iota(idx.begin(), idx.end(), 0);
    sort(idx.begin(), idx.end(), [&](int l, int r) { return s[l] < s[r]; });
    std::vector<int> s2(n);
    int now = 0;
    for (int i = 0; i < n; i++) {
        if (i && s[idx[i - 1]] != s[idx[i]]) now++;
        s2[idx[i]] = now;
    }
    return internal::sa_is(s2, now);
}

std::vector<int> suffix_array(const std::string& s) {
    int n = int(s.size());
    std::vector<int> s2(n);
    for (int i = 0; i < n; i++) {
        s2[i] = s[i];
    }
    return internal::sa_is(s2, 255);
}

// Reference:
// T. Kasai, G. Lee, H. Arimura, S. Arikawa, and K. Park,
// Linear-Time Longest-Common-Prefix Computation in Suffix Arrays and Its
// Applications
template <class T>
std::vector<int> lcp_array(const std::vector<T>& s,
                           const std::vector<int>& sa) {
    int n = int(s.size());
    assert(n >= 1);
    std::vector<int> rnk(n);
    for (int i = 0; i < n; i++) {
        rnk[sa[i]] = i;
    }
    std::vector<int> lcp(n - 1);
    int h = 0;
    for (int i = 0; i < n; i++) {
        if (h > 0) h--;
        if (rnk[i] == 0) continue;
        int j = sa[rnk[i] - 1];
        for (; j + h < n && i + h < n; h++) {
            if (s[j + h] != s[i + h]) break;
        }
        lcp[rnk[i] - 1] = h;
    }
    return lcp;
}

std::vector<int> lcp_array(const std::string& s, const std::vector<int>& sa) {
    int n = int(s.size());
    std::vector<int> s2(n);
    for (int i = 0; i < n; i++) {
        s2[i] = s[i];
    }
    return lcp_array(s2, sa);
}

// Reference:
// D. Gusfield,
// Algorithms on Strings, Trees, and Sequences: Computer Science and
// Computational Biology
template <class T> std::vector<int> z_algorithm(const std::vector<T>& s) {
    int n = int(s.size());
    if (n == 0) return {};
    std::vector<int> z(n);
    z[0] = 0;
    for (int i = 1, j = 0; i < n; i++) {
        int& k = z[i];
        k = (j + z[j] <= i) ? 0 : std::min(j + z[j] - i, z[i - j]);
        while (i + k < n && s[k] == s[i + k]) k++;
        if (j + z[j] < i + z[i]) j = i;
    }
    z[0] = n;
    return z;
}

std::vector<int> z_algorithm(const std::string& s) {
    int n = int(s.size());
    std::vector<int> s2(n);
    for (int i = 0; i < n; i++) {
        s2[i] = s[i];
    }
    return z_algorithm(s2);
}

}  // namespace atcoder


#line 1 "/home/anqooqie/.proconlib/tools/manacher.hpp"



#line 1 "/home/anqooqie/.proconlib/tools/mex.hpp"



#include <type_traits>
#line 10 "/home/anqooqie/.proconlib/tools/mex.hpp"

namespace tools {

  template <typename InputIterator>
  ::std::decay_t<decltype(*::std::declval<InputIterator>())> mex(InputIterator begin, InputIterator end) {
    using T = ::std::decay_t<decltype(*::std::declval<InputIterator>())>;
    const ::std::vector<T> orig(begin, end);
    const ::std::size_t n = orig.size();

    assert(::std::all_of(orig.begin(), orig.end(), [](const auto& o) { return o >= 0; }));

    ::std::vector<bool> exists(n, false);
    for (const ::std::size_t o : orig) {
      if (o < n) {
        exists[o] = true;
      }
    }
    for (::std::size_t i = 0; i < n; ++i) {
      if (!exists[i]) {
        return i;
      }
    }
    return n;
  }
}


#line 10 "/home/anqooqie/.proconlib/tools/manacher.hpp"

namespace tools {
  template <typename InputIterator, typename OutputIterator>
  void manacher(const InputIterator begin, const InputIterator end, const OutputIterator result) {
    using T = typename ::std::iterator_traits<InputIterator>::value_type;
    ::std::vector<T> S(begin, end);
    const auto N = S.size();
    {
      ::std::vector<T> new_S(2 * N + 1, ::tools::mex(S.begin(), S.end()));
      for (::std::size_t i = 0; i < N; ++i) {
        new_S[2 * i + 1] = S[i];
      }
      S = ::std::move(new_S);
    }

    ::std::vector<::std::size_t> R(S.size());
    {
      ::std::size_t i = 0;
      ::std::size_t j = 0;
      while (i < S.size()) {
        for (; i >= j && i + j < S.size() && S[i - j] == S[i + j]; ++j);
        R[i] = j;
        ::std::size_t k;
        for (k = 1; i >= k && k + R[i - k] < j; ++k) {
          R[i + k] = R[i - k];
        }
        i += k;
        j -= k;
      }
    }

    ::std::vector<::std::pair<::std::size_t, ::std::size_t>> new_R(S.size());
    for (::std::size_t i = 0; i <= N; ++i) {
      new_R[i * 2] = ::std::make_pair(i - (R[i * 2] - 1) / 2, i + (R[i * 2] - 1) / 2);
    }
    for (::std::size_t i = 0; i < N; ++i) {
      new_R[i * 2 + 1] = ::std::make_pair(i - (R[i * 2 + 1] / 2 - 1), i + R[i * 2 + 1] / 2);
    }
    ::std::move(new_R.begin(), new_R.end(), result);
  }
}


#line 4 "main.cpp"

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);

  int N;
  std::string T;
  std::cin >> N >> T;

  std::vector<std::pair<int, int>> R;
  tools::manacher(T.begin(), T.end(), std::back_inserter(R));
  const auto Z = atcoder::z_algorithm(T);

  std::cout << [&]() {
    for (int i = 1; i < N; ++i) {
      if (R[i * 2 + 1].first == 0 && [&]() {
        for (int j = 0; j < N; j += R[i * 2 + 1].second - R[i * 2 + 1].first - 1) {
          if (Z[j] < N - j) {
            return false;
          }
        }
        return true;
      }()) {
        return (R[i * 2 + 1].second - R[i * 2 + 1].first + 1) / 2;
      }
    }
    for (int i = 0; i < N; ++i) {
      if (R[i * 2 + 1].second == N) {
        return (N + R[i * 2 + 1].first + 1) / 2;
      }
    }
    std::exit(EXIT_FAILURE);
  }() << '\n';

  return 0;
}
accuracy: 1
time_ms: 30
memory_kb: 71940
final_rank: 14

code_snippet: #pragma region Macros
#include <bits/stdc++.h>

using namespace std;

using lint = long long;

using ull = unsigned long long;
using ld = long double;
using int128 = __int128_t;
#define all(x) (x).begin(), (x).end()
#define EPS 1e-8
#define uniqv(v) v.erase(unique(all(v)), v.end())
#define OVERLOAD_REP(_1, _2, _3, name, ...) name
#define REP1(i, n) for (auto i = std::decay_t<decltype(n)>{}; (i) != (n); ++(i))
#define REP2(i, l, r) for (auto i = (l); (i) != (r); ++(i))
#define rep(...) OVERLOAD_REP(__VA_ARGS__, REP2, REP1)(__VA_ARGS__)
#define log(x) cout << x << endl
#define logfixed(x) cout << fixed << setprecision(10) << x << endl;
#define logy(bool)         \
  if (bool) {              \
    cout << "Yes" << endl; \
  } else {                 \
    cout << "No" << endl;  \
  }

ostream &operator<<(ostream &dest, __int128_t value) {
  ostream::sentry s(dest);
  if (s) {
    __uint128_t tmp = value < 0 ? -value : value;
    char buffer[128];
    char *d = end(buffer);
    do {
      --d;
      *d = "0123456789"[tmp % 10];
      tmp /= 10;
    } while (tmp != 0);
    if (value < 0) {
      --d;
      *d = '-';
    }
    int len = end(buffer) - d;
    if (dest.rdbuf()->sputn(d, len) != len) {
      dest.setstate(ios_base::badbit);
    }
  }
  return dest;
}

template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  for (int i = 0; i < (int)v.size(); i++) {
    os << v[i] << (i + 1 != (int)v.size() ? " " : "");
  }
  return os;
}

template <typename T>
ostream &operator<<(ostream &os, const set<T> &set_var) {
  for (auto itr = set_var.begin(); itr != set_var.end(); itr++) {
    os << *itr;
    ++itr;
    if (itr != set_var.end()) os << " ";
    itr--;
  }
  return os;
}

template <typename T, typename U>
ostream &operator<<(ostream &os, const map<T, U> &map_var) {
  for (auto itr = map_var.begin(); itr != map_var.end(); itr++) {
    os << itr->first << " -> " << itr->second << "\n";
  }
  return os;
}

template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &pair_var) {
  os << "(" << pair_var.first << ", " << pair_var.second << ")";
  return os;
}

void out() { cout << '\n'; }
template <class T, class... Ts>
void out(const T &a, const Ts &...b) {
  cout << a;
  (cout << ... << (cout << ' ', b));
  cout << '\n';
}

template <typename T>
istream &operator>>(istream &is, vector<T> &v) {
  for (T &in : v) is >> in;
  return is;
}

inline void in(void) { return; }
template <typename First, typename... Rest>
void in(First &first, Rest &...rest) {
  cin >> first;
  in(rest...);
  return;
}

template <typename T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

vector<lint> dx8 = {1, 1, 0, -1, -1, -1, 0, 1};
vector<lint> dy8 = {0, 1, 1, 1, 0, -1, -1, -1};
vector<lint> dx4 = {1, 0, -1, 0};
vector<lint> dy4 = {0, 1, 0, -1};

#pragma endregion

/**
 * @brief Rolling-Hash(ローリングハッシュ)
 * @see https://qiita.com/keymoon/items/11fac5627672a6d6a9f6
 * @docs docs/rolling-hash.md
 */
struct RollingHash {
  static const uint64_t mod = (1ull << 61ull) - 1;
  using uint128_t = __uint128_t;
  vector<uint64_t> power;
  const uint64_t base;

  static inline uint64_t add(uint64_t a, uint64_t b) {
    if ((a += b) >= mod) a -= mod;
    return a;
  }

  static inline uint64_t mul(uint64_t a, uint64_t b) {
    uint128_t c = (uint128_t)a * b;
    return add(c >> 61, c & mod);
  }

  static inline uint64_t generate_base() {
    mt19937_64 mt(chrono::steady_clock::now().time_since_epoch().count());
    uniform_int_distribution<uint64_t> rand(1, RollingHash::mod - 1);
    return rand(mt);
  }

  inline void expand(size_t sz) {
    if (power.size() < sz + 1) {
      int pre_sz = (int)power.size();
      power.resize(sz + 1);
      for (int i = pre_sz - 1; i < sz; i++) {
        power[i + 1] = mul(power[i], base);
      }
    }
  }

  explicit RollingHash(uint64_t base = generate_base())
      : base(base), power{1} {}

  vector<uint64_t> build(const string &s) const {
    int sz = s.size();
    vector<uint64_t> hashed(sz + 1);

    for (int i = 0; i < sz; i++) {
      hashed[i + 1] = add(mul(hashed[i], base), s[i]);
    }
    return hashed;
  }

  template <typename T>
  vector<uint64_t> build(const vector<T> &s) const {
    int sz = s.size();
    vector<uint64_t> hashed(sz + 1);
    for (int i = 0; i < sz; i++) {
      hashed[i + 1] = add(mul(hashed[i], base), s[i]);
    }
    return hashed;
  }

  uint64_t query(const vector<uint64_t> &s, int l, int r) {
    expand(r - l);
    return add(s[r], mod - mul(s[l], power[r - l]));
  }

  uint64_t combine(uint64_t h1, uint64_t h2, size_t h2len) {
    expand(h2len);
    return add(mul(h1, power[h2len]), h2);
  }

  int lcp(const vector<uint64_t> &a, int l1, int r1,
          const vector<uint64_t> &b, int l2, int r2) {
    int len = min(r1 - l1, r2 - l2);
    int low = 0, high = len + 1;
    while (high - low > 1) {
      int mid = (low + high) / 2;
      if (query(a, l1, l1 + mid) == query(b, l2, l2 + mid))
        low = mid;
      else
        high = mid;
    }
    return low;
  }
};

int main() {
  lint n;
  in(n);
  string t, rt;

  in(t);
  rt = t;
  reverse(all(rt));
  RollingHash roll;
  auto T = roll.build(t);
  auto ansT = roll.query(T, 0, n);
  auto RT = roll.build(rt);
  roll.expand(1000010);
  lint ans = INT_MAX;
  vector<uint64_t> pw(21);
  for (lint i = n; i >= 2; i--) {
    auto z = roll.query(T, 0, i);
    auto y = roll.query(T, 1, i);
    auto x = roll.query(RT, n - i + 1, n);
    auto shash = z;

    if (n == i) {
      if (ansT == z) {
        chmin(ans, lint(i));
      }
    } else if (n > i) {
      if (n - i >= (i - 1) * 2) {
        lint mul = lint(n - i) / lint((i - 1) * 2);
        lint siz = (i - 1) * 2;

        pw[0] = roll.combine(x, y, i - 1);
        rep(j, 1, 21) {
          pw[j] = roll.combine(pw[j - 1], pw[j - 1], siz);
          siz *= 2;
        }

        rep(j, 21) {
          if ((1 << j) & mul) {
            shash = roll.combine(shash, pw[j], lint(1 << (j + 1)) * lint(i - 1));
          }
        }

        lint nokori = n - i - (mul * (i - 1) * 2);
        if (nokori <= i - 1) {
          auto xp = roll.query(RT, n - i + 1, n - i + 1 + nokori);
          shash = roll.combine(shash, xp, nokori);
        } else {
          shash = roll.combine(shash, x, i - 1);
          nokori -= (i - 1);
          auto yp = roll.query(T, 1, 1 + nokori);
          shash = roll.combine(shash, yp, nokori);
        }
      } else {
        lint nokori = n - i;
        if (nokori <= i - 1) {
          auto xp = roll.query(RT, n - i + 1, n - i + 1 + nokori);
          shash = roll.combine(shash, xp, nokori);
        } else {
          shash = roll.combine(shash, x, i - 1);
          nokori -= (i - 1);
          auto yp = roll.query(T, 1, 1 + nokori);
          shash = roll.combine(shash, yp, nokori);
        }
      }
      if (shash == ansT) {
        chmin(ans, lint(i));
      }
    }
  }
  out(ans);
}
accuracy: 0.15384615384615385
time_ms: 80
memory_kb: 236604
final_rank: 20

code_snippet: #pragma region Macros
#include <bits/stdc++.h>

using namespace std;

using lint = long long;

using ull = unsigned long long;
using ld = long double;
using int128 = __int128_t;
#define all(x) (x).begin(), (x).end()
#define EPS 1e-8
#define uniqv(v) v.erase(unique(all(v)), v.end())
#define OVERLOAD_REP(_1, _2, _3, name, ...) name
#define REP1(i, n) for (auto i = std::decay_t<decltype(n)>{}; (i) != (n); ++(i))
#define REP2(i, l, r) for (auto i = (l); (i) != (r); ++(i))
#define rep(...) OVERLOAD_REP(__VA_ARGS__, REP2, REP1)(__VA_ARGS__)
#define log(x) cout << x << endl
#define logfixed(x) cout << fixed << setprecision(10) << x << endl;
#define logy(bool)         \
  if (bool) {              \
    cout << "Yes" << endl; \
  } else {                 \
    cout << "No" << endl;  \
  }

ostream &operator<<(ostream &dest, __int128_t value) {
  ostream::sentry s(dest);
  if (s) {
    __uint128_t tmp = value < 0 ? -value : value;
    char buffer[128];
    char *d = end(buffer);
    do {
      --d;
      *d = "0123456789"[tmp % 10];
      tmp /= 10;
    } while (tmp != 0);
    if (value < 0) {
      --d;
      *d = '-';
    }
    int len = end(buffer) - d;
    if (dest.rdbuf()->sputn(d, len) != len) {
      dest.setstate(ios_base::badbit);
    }
  }
  return dest;
}

template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  for (int i = 0; i < (int)v.size(); i++) {
    os << v[i] << (i + 1 != (int)v.size() ? " " : "");
  }
  return os;
}

template <typename T>
ostream &operator<<(ostream &os, const set<T> &set_var) {
  for (auto itr = set_var.begin(); itr != set_var.end(); itr++) {
    os << *itr;
    ++itr;
    if (itr != set_var.end()) os << " ";
    itr--;
  }
  return os;
}

template <typename T, typename U>
ostream &operator<<(ostream &os, const map<T, U> &map_var) {
  for (auto itr = map_var.begin(); itr != map_var.end(); itr++) {
    os << itr->first << " -> " << itr->second << "\n";
  }
  return os;
}

template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &pair_var) {
  os << "(" << pair_var.first << ", " << pair_var.second << ")";
  return os;
}

void out() { cout << '\n'; }
template <class T, class... Ts>
void out(const T &a, const Ts &...b) {
  cout << a;
  (cout << ... << (cout << ' ', b));
  cout << '\n';
}

template <typename T>
istream &operator>>(istream &is, vector<T> &v) {
  for (T &in : v) is >> in;
  return is;
}

inline void in(void) { return; }
template <typename First, typename... Rest>
void in(First &first, Rest &...rest) {
  cin >> first;
  in(rest...);
  return;
}

template <typename T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

vector<lint> dx8 = {1, 1, 0, -1, -1, -1, 0, 1};
vector<lint> dy8 = {0, 1, 1, 1, 0, -1, -1, -1};
vector<lint> dx4 = {1, 0, -1, 0};
vector<lint> dy4 = {0, 1, 0, -1};

#pragma endregion

/**
 * @brief Rolling-Hash(ローリングハッシュ)
 * @see https://qiita.com/keymoon/items/11fac5627672a6d6a9f6
 * @docs docs/rolling-hash.md
 */
struct RollingHash {
  static const uint64_t mod = (1ull << 61ull) - 1;
  using uint128_t = __uint128_t;
  vector<uint64_t> power;
  const uint64_t base;

  static inline uint64_t add(uint64_t a, uint64_t b) {
    if ((a += b) >= mod) a -= mod;
    return a;
  }

  static inline uint64_t mul(uint64_t a, uint64_t b) {
    uint128_t c = (uint128_t)a * b;
    return add(c >> 61, c & mod);
  }

  static inline uint64_t generate_base() {
    mt19937_64 mt(chrono::steady_clock::now().time_since_epoch().count());
    uniform_int_distribution<uint64_t> rand(1, RollingHash::mod - 1);
    return rand(mt);
  }

  inline void expand(size_t sz) {
    if (power.size() < sz + 1) {
      int pre_sz = (int)power.size();
      power.resize(sz + 1);
      for (int i = pre_sz - 1; i < sz; i++) {
        power[i + 1] = mul(power[i], base);
      }
    }
  }

  explicit RollingHash(uint64_t base = generate_base())
      : base(base), power{1} {}

  vector<uint64_t> build(const string &s) const {
    int sz = s.size();
    vector<uint64_t> hashed(sz + 1);
    for (int i = 0; i < sz; i++) {
      hashed[i + 1] = add(mul(hashed[i], base), s[i]);
    }
    return hashed;
  }

  template <typename T>
  vector<uint64_t> build(const vector<T> &s) const {
    int sz = s.size();
    vector<uint64_t> hashed(sz + 1);
    for (int i = 0; i < sz; i++) {
      hashed[i + 1] = add(mul(hashed[i], base), s[i]);
    }
    return hashed;
  }

  uint64_t query(const vector<uint64_t> &s, int l, int r) {
    expand(r - l);
    return add(s[r], mod - mul(s[l], power[r - l]));
  }

  uint64_t combine(uint64_t h1, uint64_t h2, size_t h2len) {
    expand(h2len);
    return add(mul(h1, power[h2len]), h2);
  }

  int lcp(const vector<uint64_t> &a, int l1, int r1,
          const vector<uint64_t> &b, int l2, int r2) {
    int len = min(r1 - l1, r2 - l2);
    int low = 0, high = len + 1;
    while (high - low > 1) {
      int mid = (low + high) / 2;
      if (query(a, l1, l1 + mid) == query(b, l2, l2 + mid))
        low = mid;
      else
        high = mid;
    }
    return low;
  }
};

int main() {
  lint n;
  in(n);
  string t, rt;

  in(t);
  rt = t;
  reverse(all(rt));
  RollingHash roll;
  auto T = roll.build(t);
  auto ansT = roll.query(T, 0, n);
  auto RT = roll.build(rt);
  lint ans = INT_MAX;
  vector<uint64_t> pw(21);
  for (lint i = n; i >= 2; i--) {
    auto z = roll.query(T, 0, i);
    auto y = roll.query(T, 1, i);
    auto x = roll.query(RT, n - i + 1, n);
    auto shash = z;

    if (n == i) {
      if (ansT == z) {
        chmin(ans, lint(i));
      }
    } else if (n > i) {
      if (n - i >= (i - 1) * 2) {
        lint mul = lint(n - i) / lint((i - 1) * 2);
        lint siz = (i - 1) * 2;

        pw[0] = roll.combine(x, y, i - 1);
        rep(j, 1, 21) {
          pw[j] = roll.combine(pw[j - 1], pw[j - 1], siz);
          siz *= 2;
        }

        rep(j, 21) {
          if ((1 << j) & mul) {
            shash = roll.combine(shash, pw[j], lint(1 << (j + 1)) * lint(i - 1));
          }
        }

        lint nokori = n - i - (mul * (i - 1) * 2);
        if (nokori <= i - 1) {
          auto xp = roll.query(RT, n - i + 1, n - i + 1 + nokori);
          shash = roll.combine(shash, xp, nokori);
        } else {
          shash = roll.combine(shash, x, i - 1);
          nokori -= (i - 1);
          auto yp = roll.query(T, 1, 1 + nokori);
          shash = roll.combine(shash, yp, nokori);
        }
      } else {
        lint nokori = n - i;
        if (nokori <= i - 1) {
          auto xp = roll.query(RT, n - i + 1, n - i + 1 + nokori);
          shash = roll.combine(shash, xp, nokori);
        } else {
          shash = roll.combine(shash, x, i - 1);
          nokori -= (i - 1);
          auto yp = roll.query(T, 1, 1 + nokori);
          shash = roll.combine(shash, yp, nokori);
        }
      }
      if (shash == ansT) {
        chmin(ans, lint(i));
      }
    }
  }
  out(ans);
}
accuracy: 0.15384615384615385
time_ms: 70
memory_kb: 236588
final_rank: 19

code_snippet: #pragma region Macros
#include <bits/stdc++.h>

using namespace std;

using lint = long long;

using ull = unsigned long long;
using ld = long double;
using int128 = __int128_t;
#define all(x) (x).begin(), (x).end()
#define EPS 1e-8
#define uniqv(v) v.erase(unique(all(v)), v.end())
#define OVERLOAD_REP(_1, _2, _3, name, ...) name
#define REP1(i, n) for (auto i = std::decay_t<decltype(n)>{}; (i) != (n); ++(i))
#define REP2(i, l, r) for (auto i = (l); (i) != (r); ++(i))
#define rep(...) OVERLOAD_REP(__VA_ARGS__, REP2, REP1)(__VA_ARGS__)
#define log(x) cout << x << endl
#define logfixed(x) cout << fixed << setprecision(10) << x << endl;
#define logy(bool)         \
  if (bool) {              \
    cout << "Yes" << endl; \
  } else {                 \
    cout << "No" << endl;  \
  }

ostream &operator<<(ostream &dest, __int128_t value) {
  ostream::sentry s(dest);
  if (s) {
    __uint128_t tmp = value < 0 ? -value : value;
    char buffer[128];
    char *d = end(buffer);
    do {
      --d;
      *d = "0123456789"[tmp % 10];
      tmp /= 10;
    } while (tmp != 0);
    if (value < 0) {
      --d;
      *d = '-';
    }
    int len = end(buffer) - d;
    if (dest.rdbuf()->sputn(d, len) != len) {
      dest.setstate(ios_base::badbit);
    }
  }
  return dest;
}

template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  for (int i = 0; i < (int)v.size(); i++) {
    os << v[i] << (i + 1 != (int)v.size() ? " " : "");
  }
  return os;
}

template <typename T>
ostream &operator<<(ostream &os, const set<T> &set_var) {
  for (auto itr = set_var.begin(); itr != set_var.end(); itr++) {
    os << *itr;
    ++itr;
    if (itr != set_var.end()) os << " ";
    itr--;
  }
  return os;
}

template <typename T, typename U>
ostream &operator<<(ostream &os, const map<T, U> &map_var) {
  for (auto itr = map_var.begin(); itr != map_var.end(); itr++) {
    os << itr->first << " -> " << itr->second << "\n";
  }
  return os;
}

template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &pair_var) {
  os << "(" << pair_var.first << ", " << pair_var.second << ")";
  return os;
}

void out() { cout << '\n'; }
template <class T, class... Ts>
void out(const T &a, const Ts &...b) {
  cout << a;
  (cout << ... << (cout << ' ', b));
  cout << '\n';
}

template <typename T>
istream &operator>>(istream &is, vector<T> &v) {
  for (T &in : v) is >> in;
  return is;
}

inline void in(void) { return; }
template <typename First, typename... Rest>
void in(First &first, Rest &...rest) {
  cin >> first;
  in(rest...);
  return;
}

template <typename T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

vector<lint> dx8 = {1, 1, 0, -1, -1, -1, 0, 1};
vector<lint> dy8 = {0, 1, 1, 1, 0, -1, -1, -1};
vector<lint> dx4 = {1, 0, -1, 0};
vector<lint> dy4 = {0, 1, 0, -1};

#pragma endregion

/**
 * @brief Rolling-Hash(ローリングハッシュ)
 * @see https://qiita.com/keymoon/items/11fac5627672a6d6a9f6
 * @docs docs/rolling-hash.md
 */
struct RollingHash {
  static const uint64_t mod = (1ull << 61ull) - 1;
  using uint128_t = __uint128_t;
  vector<uint64_t> power;
  const uint64_t base;

  static inline uint64_t add(uint64_t a, uint64_t b) {
    if ((a += b) >= mod) a -= mod;
    return a;
  }

  static inline uint64_t mul(uint64_t a, uint64_t b) {
    uint128_t c = (uint128_t)a * b;
    return add(c >> 61, c & mod);
  }

  static inline uint64_t generate_base() {
    mt19937_64 mt(chrono::steady_clock::now().time_since_epoch().count());
    uniform_int_distribution<uint64_t> rand(1, RollingHash::mod - 1);
    return rand(mt);
  }

  inline void expand(size_t sz) {
    if (power.size() < sz + 1) {
      int pre_sz = (int)power.size();
      power.resize(sz + 1);
      for (int i = pre_sz - 1; i < sz; i++) {
        power[i + 1] = mul(power[i], base);
      }
    }
  }

  explicit RollingHash(uint64_t base = generate_base())
      : base(base), power{1} {}

  vector<uint64_t> build(const string &s) const {
    int sz = s.size();
    vector<uint64_t> hashed(sz + 1);
    for (int i = 0; i < sz; i++) {
      hashed[i + 1] = add(mul(hashed[i], base), s[i]);
    }
    return hashed;
  }

  template <typename T>
  vector<uint64_t> build(const vector<T> &s) const {
    int sz = s.size();
    vector<uint64_t> hashed(sz + 1);
    for (int i = 0; i < sz; i++) {
      hashed[i + 1] = add(mul(hashed[i], base), s[i]);
    }
    return hashed;
  }

  uint64_t query(const vector<uint64_t> &s, int l, int r) {
    expand(r - l);
    return add(s[r], mod - mul(s[l], power[r - l]));
  }

  uint64_t combine(uint64_t h1, uint64_t h2, size_t h2len) {
    expand(h2len);
    return add(mul(h1, power[h2len]), h2);
  }

  int lcp(const vector<uint64_t> &a, int l1, int r1,
          const vector<uint64_t> &b, int l2, int r2) {
    int len = min(r1 - l1, r2 - l2);
    int low = 0, high = len + 1;
    while (high - low > 1) {
      int mid = (low + high) / 2;
      if (query(a, l1, l1 + mid) == query(b, l2, l2 + mid))
        low = mid;
      else
        high = mid;
    }
    return low;
  }
  // RollingHash roll;
  // auto rh1=roll.build(s);
  // auto rh2=roll.build(t);
  // if(roll.query(rh1,l,r)==roll.query(rh2,l,r)){

  // }
};

int main() {
  //   RollingHash roll;
  //   string s = "abc";
  //   string t = "def";
  //   string st = "abcdef";
  //   auto rh1 = roll.build(s);
  //   auto rh2 = roll.build(t);
  //   auto rh3 = roll.build(st);
  //   auto h1 = roll.query(rh1, 0, 3);
  //   auto h2 = roll.query(rh2, 0, 3);
  //   out(roll.query(rh3, 0, 6) == roll.combine(h1, h2, 3));

  int n;
  in(n);
  string t, rt;

  in(t);
  rt = t;
  reverse(all(rt));
  RollingHash roll;
  auto T = roll.build(t);
  auto ansT = roll.query(T, 0, n);
  auto RT = roll.build(rt);
  int ans = INT_MAX;
  rep(i, 2, n + 1) {
    auto z = roll.query(T, 0, i);
    auto y = roll.query(T, 1, i);
    auto x = roll.query(RT, n - i + 1, n);
    auto shash = z;

    if (n == i) {
      if (ansT == z) {
        chmin(ans, i);
      }
    } else if (n > i) {
      if (n - i >= (i - 1) * 2) {
        int mul = (n - i) / ((i - 1) * 2);
        lint siz = (i - 1) * 2;
        vector<uint64_t> pw(20);
        pw[0] = roll.combine(x, y, i - 1);
        rep(j, 1, 20) {
          pw[j] = roll.combine(pw[j - 1], pw[j - 1], siz);
          siz *= 2;
        }

        rep(j, 20) {
          if ((1 << j) & mul) {
            shash = roll.combine(shash, pw[j], (1 << (j + 1)) * (i - 1));
          }
        }

        int nokori = n - i - (mul * (i - 1) * 2);
        if (nokori <= i - 1) {
          auto xp = roll.query(RT, n - i + 1, n - i + 1 + nokori);
          shash = roll.combine(shash, xp, nokori);
        } else {
          shash = roll.combine(shash, x, i - 1);
          nokori -= (i - 1);
          auto yp = roll.query(T, 1, 1 + nokori);
          shash = roll.combine(shash, yp, nokori);
        }
      } else {
        int nokori = n - i;
        if (nokori <= i - 1) {
          auto xp = roll.query(RT, n - i + 1, n - i + 1 + nokori);
          shash = roll.combine(shash, xp, nokori);
        } else {
          shash = roll.combine(shash, x, i - 1);
          nokori -= (i - 1);
          auto yp = roll.query(T, 1, 1 + nokori);
          shash = roll.combine(shash, yp, nokori);
        }
      }
      if (shash == ansT) {
        chmin(ans, i);
      }
    }
  }
  out(ans);
}
accuracy: 0.15384615384615385
time_ms: 40
memory_kb: 139620
final_rank: 18

code_snippet: #line 1 "main.cpp"
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
using ll = long long;
#define all(x) x.begin(),x.end()
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }

#line 1 "/home/student/s1290119/ICPC/domestic-template-main/library/ushi/string/rolling-hash.hpp"
/**
 * @brief Rolling-Hash(ローリングハッシュ)
 * @see https://qiita.com/keymoon/items/11fac5627672a6d6a9f6
 *
 */
struct RollingHash {
  static const uint64_t mod = (1ull << 61ull) - 1;
  using uint128_t = __uint128_t;
  vector<uint64_t> power;
  const uint64_t base;

  static inline uint64_t add(uint64_t a, uint64_t b) {
    if ((a += b) >= mod) a -= mod;
    return a;
  }

  static inline uint64_t mul(uint64_t a, uint64_t b) {
    uint128_t c = (uint128_t)a * b;
    return add(c >> 61, c & mod);
  }

  static inline uint64_t generate_base() {
    mt19937_64 mt(chrono::steady_clock::now().time_since_epoch().count());
    uniform_int_distribution<uint64_t> rand(1, RollingHash::mod - 1);
    return rand(mt);
  }

  inline void expand(size_t sz) {
    if (power.size() < sz + 1) {
      int pre_sz = (int)power.size();
      power.resize(sz + 1);
      for (int i = pre_sz - 1; i < sz; i++) {
        power[i + 1] = mul(power[i], base);
      }
    }
  }

  explicit RollingHash(uint64_t base = generate_base())
      : base(base), power{1} {}

  vector<uint64_t> build(const string &s) const {
    int sz = s.size();
    vector<uint64_t> hashed(sz + 1);
    for (int i = 0; i < sz; i++) {
      hashed[i + 1] = add(mul(hashed[i], base), s[i]);
    }
    return hashed;
  }

  template <typename T>
  vector<uint64_t> build(const vector<T> &s) const {
    int sz = s.size();
    vector<uint64_t> hashed(sz + 1);
    for (int i = 0; i < sz; i++) {
      hashed[i + 1] = add(mul(hashed[i], base), s[i]);
    }
    return hashed;
  }

  uint64_t query(const vector<uint64_t> &s, int l, int r) {
    expand(r - l);
    return add(s[r], mod - mul(s[l], power[r - l]));
  }

  uint64_t combine(uint64_t h1, uint64_t h2, size_t h2len) {
    expand(h2len);
    return add(mul(h1, power[h2len]), h2);
  }

  int lcp(const vector<uint64_t> &a, int l1, int r1, const vector<uint64_t> &b,
          int l2, int r2) {
    int len = min(r1 - l1, r2 - l2);
    int low = 0, high = len + 1;
    while (high - low > 1) {
      int mid = (low + high) / 2;
      if (query(a, l1, l1 + mid) == query(b, l2, l2 + mid))
        low = mid;
      else
        high = mid;
    }
    return low;
  }
};
#line 10 "main.cpp"

int main() {
    int n;
    cin >> n;

    string t;
    cin >> t;
    
    string rt = t;
    reverse(all(rt));

    RollingHash rh;
    auto hs1 = rh.build(t);
    auto hs2 = rh.build(rt);

    for (int i = 2; i <= n; ++i) {
        bool parity = false;
        for (int j = 0; j < n; j += i - 1) {
            int len = min(i, n - j);
            if (parity) {
                if (rh.query(hs2, n - i, n - i + len) != rh.query(hs1, j, j + len)) goto ng;
            } else {
                if (rh.query(hs1, 0, len) != rh.query(hs1, j, j + len)) goto ng;
            }
            parity = parity xor 1;
        }
        cout << i << '\n';
        exit(0);
        ng:;
    }
}
accuracy: 1
time_ms: 100
memory_kb: 36228
final_rank: 11

code_snippet: #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
#define rrep(i,start,end) for (long long i = start;i >= (long long)(end);i--)
#define repn(i,end) for(long long i = 0; i <= (long long)(end); i++)
#define reps(i,start,end) for(long long i = start; i < (long long)(end); i++)
#define repsn(i,start,end) for(long long i = start; i <= (long long)(end); i++)
#define each(p,a) for(auto &p:a)
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<long long> vll;
typedef vector<pair<long long ,long long>> vpll;
typedef vector<vector<long long>> vvll;
typedef set<ll> sll;
typedef map<long long , long long> mpll;
typedef pair<long long ,long long> pll;
typedef tuple<long long , long long , long long> tpl3;
#define LL(...) ll __VA_ARGS__; input(__VA_ARGS__)
#define LD(...) ld __VA_ARGS__; input(__VA_ARGS__)
#define Str(...) string __VA_ARGS__; input(__VA_ARGS__)
#define Ch(...) char __VA_ARGS__; input(__VA_ARGS__)
#define all(a)  (a).begin(),(a).end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define sz(x) (int)x.size()
// << std::fixed << std::setprecision(10)
const ll INF = 1LL << 60;
const ld EPS = 1e-9;
 
inline ll lfloor(ll x,ll m){return (x - ((x % m+ m)%m))/m;}
inline ll positive_mod(ll a,ll m){return (a % m + m)%m;}
inline ll popcnt(ull a){ return __builtin_popcountll(a);}
template<class T> bool chmin(T& a, T b){if(a > b){a = b;return true;}return false;}
template<class T> bool chmax(T& a, T b){if(a < b){a = b;return true;}return false;}
template<typename T> std::istream &operator>>(std::istream&is,std::vector<T>&v){for(T &in:v){is>>in;}return is;}
template<typename T> std::ostream &operator<<(std::ostream&os,const std::vector<T>&v){for(auto it=std::begin(v);it!=std::end(v);){os<<*it<<((++it)!=std::end(v)?" ":"");}return os;}
template<typename T1, typename T2>std::ostream &operator<< (std::ostream &os, std::pair<T1,T2> p){os << "{" << p.first << "," << p.second << "}";return os;}
template<class... T>void input(T&... a){(cin >> ... >> a);}
void print(){cout << endl;}
template<class T, class... Ts>void print(const T& a, const Ts&... b){cout << a;((cout << ' ' << b), ...);cout << endl;}
template<class T> void pspace(const T& a){ cout << a << ' ';}
void perr(){cerr << endl;}
template<class T, class... Ts>void perr(const T& a, const Ts&... b){cerr << a;((cerr << ' ' << b), ...);cerr << endl;}
void yes(bool i = true){ return print(i?"yes":"no"); }
void Yes(bool i = true){ return print(i?"Yes":"No"); }
void YES(bool i = true){ return print(i?"YES":"NO"); }
template <class T> vector<T> &operator++(vector<T> &v) {for(auto &e : v) e++;return v;}
template <class T> vector<T> operator++(vector<T> &v, signed) {auto res = v;for(auto &e : v) e++;return res;}
template <class T> vector<T> &operator--(vector<T> &v) {for(auto &e : v) e--;return v;}
template <class T> vector<T> operator--(vector<T> &v, signed) {auto res = v;for(auto &e : v) e--;return res;}
//grid探索用
vector<ll> _ta = {0,0,1,-1,1,1,-1,-1};
vector<ll> _yo = {1,-1,0,0,1,-1,1,-1};
bool isin(ll now_i,ll now_j,ll h,ll w){return (0<=now_i && now_i < h && 0 <= now_j && now_j < w);}
  
ll lpow(ll x,ll n){ll ans = 1;while(n >0){if(n & 1)ans *= x;x *= x;n >>= 1;}return ans;}
ll Modlpow(ll x,ll n,ll m){ll ans = 1;ll a = x%m;while(n >0){if(n & 1){ans *= a;ans%= m;}a *= a;a %= m;n >>= 1;}return ans;} 
const ll MOD9 = 998244353LL;
const ll MOD10 = 1000000007LL;

//参考 https://drken1215.hatenablog.com/entry/2019/03/12/135500
//https://qiita.com/keymoon/items/11fac5627672a6d6a9f6
//verify https://atcoder.jp/contests/tessoku-book/submissions/52829138
struct RollingHash{

  const ull MASK30 = (1UL << 30) - 1;
  const ull MASK31 = (1UL << 31) - 1;
  const ull MOD = (1UL << 61) - 1;
  const ull MASK61 = MOD;
  const ull POSITIVIZER = MOD * 4;
  const ull base = 9973;


  string s;
  vector<ull> hash;

  RollingHash(){}

  RollingHash(const string &_s){
    init(_s);
  }

  //mod 2^61-1を計算する関数
  ull CalcMod(ull x)
  {
      ull xu = x >> 61;
      ull xd = x & MASK61;
      ull res = xu + xd;
      if (res >= MOD) res -= MOD;
      return res;
  }
  //a*b mod 2^61-1を返す関数(最後にModを取る)
  ull Mul(ull a, ull b)
  {
      ull au = a >> 31;
      ull ad = a & MASK31;
      ull bu = b >> 31;
      ull bd = b & MASK31;
      ull mid = ad * bu + au * bd;
      ull midu = mid >> 30;
      ull midd = mid & MASK30;
      return CalcMod(au * bu * 2 + midu + (midd << 31) + ad * bd);
  }
  
  //2^61 -1 で割る時のpow計算
  
  ull SuperMODpow(ll x,ll n){
    // MOD = (1UL << 61) - 1;,Mul,CalcMod必要
    ull ans = 1;
    ull a = x;
    while(n> 0){
      if(n & 1){
        ans = Mul(ans,a);
      }
      a = Mul(a,a);
      n>>=1;
    }
    return ans;
  }

  void init(const string &_s){
    s = _s;
    ll n = s.size();
    hash.assign(n+1,0);
    rep(i,n){
      hash[i + 1] = CalcMod((Mul(hash[i],base) + s[i]));
    }
  }

  //[l,r)のハッシュを返す
  inline ull get(ll l,ll r){
    return CalcMod(hash[r]+ POSITIVIZER - Mul(hash[l],SuperMODpow(base,r-l)));
  }
};
 
int main(){
  ios::sync_with_stdio(false);cin.tie(nullptr);
  LL(n);

  Str(t);
  string rt = t;
  reverse(all(rt));
  RollingHash ha(t),rha(rt);

  repsn(len,2,n){
    bool able = true;
    ll idx = 1;
    bool asc = true;
    while(idx < n){
      if(idx + len -1 <= n-1){
        if(asc){
          if(ha.get(1,len) != ha.get(idx,idx+len-1)){
            able = false;
          }
        }else{
          ll r = n-1- idx;
          ll l = n-1 -(idx+len-1-1);
          //
          if(ha.get(0,len-1) != rha.get(l,r+1)){
            able = false;
          }
        }
        idx+= len-1;
      }else{
        ll le = n-1- idx + 1;
        if(asc){
          if(ha.get(1,le+1) != ha.get(idx,idx + le)){
            able = false;
          }
        }else{
          ll r = n-1- idx;
          ll l = 0;
          //
          if(ha.get(len -1- le,len-1) != rha.get(l,r+1)){
            able = false;
          }
        }
        break;
      }
      asc  = !asc;
    }
    if(able){
      cout << len << endl;
      return 0;
    }
  }
}
accuracy: 1
time_ms: 1490
memory_kb: 22800
final_rank: 16

code_snippet: #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
#define rrep(i,start,end) for (long long i = start;i >= (long long)(end);i--)
#define repn(i,end) for(long long i = 0; i <= (long long)(end); i++)
#define reps(i,start,end) for(long long i = start; i < (long long)(end); i++)
#define repsn(i,start,end) for(long long i = start; i <= (long long)(end); i++)
#define each(p,a) for(auto &p:a)
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<long long> vll;
typedef vector<pair<long long ,long long>> vpll;
typedef vector<vector<long long>> vvll;
typedef set<ll> sll;
typedef map<long long , long long> mpll;
typedef pair<long long ,long long> pll;
typedef tuple<long long , long long , long long> tpl3;
#define LL(...) ll __VA_ARGS__; input(__VA_ARGS__)
#define LD(...) ld __VA_ARGS__; input(__VA_ARGS__)
#define Str(...) string __VA_ARGS__; input(__VA_ARGS__)
#define Ch(...) char __VA_ARGS__; input(__VA_ARGS__)
#define all(a)  (a).begin(),(a).end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define sz(x) (int)x.size()
// << std::fixed << std::setprecision(10)
const ll INF = 1LL << 60;
const ld EPS = 1e-9;
 
inline ll lfloor(ll x,ll m){return (x - ((x % m+ m)%m))/m;}
inline ll positive_mod(ll a,ll m){return (a % m + m)%m;}
inline ll popcnt(ull a){ return __builtin_popcountll(a);}
template<class T> bool chmin(T& a, T b){if(a > b){a = b;return true;}return false;}
template<class T> bool chmax(T& a, T b){if(a < b){a = b;return true;}return false;}
template<typename T> std::istream &operator>>(std::istream&is,std::vector<T>&v){for(T &in:v){is>>in;}return is;}
template<typename T> std::ostream &operator<<(std::ostream&os,const std::vector<T>&v){for(auto it=std::begin(v);it!=std::end(v);){os<<*it<<((++it)!=std::end(v)?" ":"");}return os;}
template<typename T1, typename T2>std::ostream &operator<< (std::ostream &os, std::pair<T1,T2> p){os << "{" << p.first << "," << p.second << "}";return os;}
template<class... T>void input(T&... a){(cin >> ... >> a);}
void print(){cout << endl;}
template<class T, class... Ts>void print(const T& a, const Ts&... b){cout << a;((cout << ' ' << b), ...);cout << endl;}
template<class T> void pspace(const T& a){ cout << a << ' ';}
void perr(){cerr << endl;}
template<class T, class... Ts>void perr(const T& a, const Ts&... b){cerr << a;((cerr << ' ' << b), ...);cerr << endl;}
void yes(bool i = true){ return print(i?"yes":"no"); }
void Yes(bool i = true){ return print(i?"Yes":"No"); }
void YES(bool i = true){ return print(i?"YES":"NO"); }
template <class T> vector<T> &operator++(vector<T> &v) {for(auto &e : v) e++;return v;}
template <class T> vector<T> operator++(vector<T> &v, signed) {auto res = v;for(auto &e : v) e++;return res;}
template <class T> vector<T> &operator--(vector<T> &v) {for(auto &e : v) e--;return v;}
template <class T> vector<T> operator--(vector<T> &v, signed) {auto res = v;for(auto &e : v) e--;return res;}
//grid探索用
vector<ll> _ta = {0,0,1,-1,1,1,-1,-1};
vector<ll> _yo = {1,-1,0,0,1,-1,1,-1};
bool isin(ll now_i,ll now_j,ll h,ll w){return (0<=now_i && now_i < h && 0 <= now_j && now_j < w);}
  
ll lpow(ll x,ll n){ll ans = 1;while(n >0){if(n & 1)ans *= x;x *= x;n >>= 1;}return ans;}
ll Modlpow(ll x,ll n,ll m){ll ans = 1;ll a = x%m;while(n >0){if(n & 1){ans *= a;ans%= m;}a *= a;a %= m;n >>= 1;}return ans;} 
const ll MOD9 = 998244353LL;
const ll MOD10 = 1000000007LL;

//参考 https://drken1215.hatenablog.com/entry/2019/03/12/135500
//https://qiita.com/keymoon/items/11fac5627672a6d6a9f6
//verify https://atcoder.jp/contests/tessoku-book/submissions/52829138
struct RollingHash{

  const ull MASK30 = (1UL << 30) - 1;
  const ull MASK31 = (1UL << 31) - 1;
  const ull MOD = (1UL << 61) - 1;
  const ull MASK61 = MOD;
  const ull POSITIVIZER = MOD * 4;
  const ull base = 9973;


  string s;
  vector<ull> hash;

  RollingHash(){}

  RollingHash(const string &_s){
    init(_s);
  }

  //mod 2^61-1を計算する関数
  ull CalcMod(ull x)
  {
      ull xu = x >> 61;
      ull xd = x & MASK61;
      ull res = xu + xd;
      if (res >= MOD) res -= MOD;
      return res;
  }
  //a*b mod 2^61-1を返す関数(最後にModを取る)
  ull Mul(ull a, ull b)
  {
      ull au = a >> 31;
      ull ad = a & MASK31;
      ull bu = b >> 31;
      ull bd = b & MASK31;
      ull mid = ad * bu + au * bd;
      ull midu = mid >> 30;
      ull midd = mid & MASK30;
      return CalcMod(au * bu * 2 + midu + (midd << 31) + ad * bd);
  }
  
  //2^61 -1 で割る時のpow計算
  
  ull SuperMODpow(ll x,ll n){
    // MOD = (1UL << 61) - 1;,Mul,CalcMod必要
    ull ans = 1;
    ull a = x;
    while(n> 0){
      if(n & 1){
        ans = Mul(ans,a);
      }
      a = Mul(a,a);
      n>>=1;
    }
    return ans;
  }

  void init(const string &_s){
    s = _s;
    ll n = s.size();
    hash.assign(n+1,0);
    rep(i,n){
      hash[i + 1] = CalcMod((Mul(hash[i],base) + s[i]));
    }
  }

  //[l,r)のハッシュを返す
  inline ull get(ll l,ll r){
    return CalcMod(hash[r]+ POSITIVIZER - Mul(hash[l],SuperMODpow(base,r-l)));
  }
};
 
int main(){
  ios::sync_with_stdio(false);cin.tie(nullptr);
  LL(n);

  Str(t);
  if(*min_element(all(t)) == *max_element(all(t))){
    cout << 1 << endl;
    return 0;
  }
  string rt = t;
  reverse(all(rt));
  RollingHash ha(t),rha(rt);

  repsn(len,2,n){
    bool able = true;
    ll idx = 1;
    bool asc = true;
    while(idx < n){
      if(idx + len -1 <= n-1){
        if(asc){
          if(ha.get(1,len) != ha.get(idx,idx+len-1)){
            able = false;
          }
        }else{
          ll r = n-1- idx;
          ll l = n-1 -(idx+len-1-1);
          //
          if(ha.get(0,len-1) != rha.get(l,r+1)){
            able = false;
          }
        }
        idx+= len-1;
      }else{
        ll le = n-1- idx + 1;
        if(asc){
          if(ha.get(1,le+1) != ha.get(idx,idx + le)){
            able = false;
          }
        }else{
          ll r = n-1- idx;
          ll l = 0;
          //
          if(ha.get(len -1- le,len-1) != rha.get(l,r+1)){
            able = false;
          }
        }
        break;
      }
      asc  = !asc;
    }
    if(able){
      cout << len << endl;
      return 0;
    }
  }
}
accuracy: 0.9615384615384616
time_ms: 1490
memory_kb: 22732
final_rank: 17

code_snippet: #line 1 "a.cpp"
#define PROBLEM "https://onlinejudge.u-aizu.ac.jp/problems/2934"
#include <iostream>
#include <string>

#line 2 "/home/kuhaku/home/github/algo/lib/template/template.hpp"
#pragma GCC target("sse4.2,avx2,bmi2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
template <class T, class U>
constexpr bool chmax(T &a, const U &b) {
    return a < (T)b ? a = (T)b, true : false;
}
template <class T, class U>
constexpr bool chmin(T &a, const U &b) {
    return (T)b < a ? a = (T)b, true : false;
}
constexpr std::int64_t INF = 1000000000000000003;
constexpr int Inf = 1000000003;
constexpr double EPS = 1e-7;
constexpr double PI = M_PI;
#line 2 "/home/kuhaku/home/github/algo/lib/string/manacher.hpp"

/**
 * @brief Manacher
 * @details R[i] := S[i-R[i]:i] == S[i:i+R[i]]
 *
 * @tparam Container
 */
template <typename Container>
struct Manacher {
    Manacher(const Container &_s) : _size(_s.size()), s(_s), r(_s.size()) {
        int i = 0, j = 0;
        while (i < this->_size) {
            while (i - j >= 0 && i + j < this->_size && this->s[i - j] == this->s[i + j]) ++j;
            this->r[i] = j;
            int k = 1;
            while (i - k >= 0 && i + k < this->_size && k + this->r[i - k] < j)
                this->r[i + k] = this->r[i - k], ++k;
            i += k, j -= k;
        }
    }

    const auto &operator[](int i) const { return this->r[i]; }
    auto &operator[](int i) { return this->r[i]; }
    const auto begin() const { return this->r.begin(); }
    auto begin() { return this->r.begin(); }
    const auto end() const { return this->r.end(); }
    auto end() { return this->r.end(); }

    const std::vector<int> &get() { return this->r; }

  private:
    int _size;
    const Container &s;
    std::vector<int> r;
};
#line 6 "a.cpp"

int solve(const std::string &s) {
    int n = s.size();
    if (n == 1)
        return 1;
    Manacher manacher(s);
    for (int m = 1; m < n; ++m) {
        bool flag = true;
        int k = m;
        while (k < n) {
            flag &= manacher[k] >= std::min(m + 1, n - k);
            k += m;
        }
        if (flag)
            return m + 1;
    }
    return n;
}

int main(void) {
    int n;
    std::cin >> n;
    std::string s;
    std::cin >> s;
    std::cout << solve(s) << std::endl;

    return 0;
}
accuracy: 1
time_ms: 40
memory_kb: 8224
final_rank: 6

code_snippet: //
// Manacher のアルゴリズム
//   res[i] := S[i] を中心とする S 上の奇数長の最長回文の半径 (中心を含む)
//   偶数長の回文を求めたいときは S = "abc" に対して "a$b$c" といった処理をするテクがある
//
// verified:
//   RUPC 2019 day3-E 往復文字列
//     https://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2934
//
//   ウクーニャたんお誕生日コンテスト D - ukuku
//     https://atcoder.jp/contests/ukuku09/tasks/ukuku09_d
//


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


// Manacher
struct Manacher {
    string S;
    vector<int> radius_odd, radius_even;

    // construct
    Manacher(const string &S_) : S(S_) { init(S); }
    void init(const string &S_) {
        S = S_;
        string S2 = "";
        for (int i = 0; i < (int)S.size(); ++i) {
            S2 += S[i];
            if (i+1 < (int)S.size()) S2 += "$";
        }
        construct(S2);
    }
    vector<int> construct(const string &S2) {
        vector<int> len(S2.size());
        int i = 0, j = 0;
        while (i < (int)S2.size()) {
            while (i-j >= 0 && i+j < (int)S2.size() && S2[i-j] == S2[i+j]) ++j;
            len[i] = j;
            int k = 1;
            while (i-k >= 0 && i+k < (int)S2.size() && k+len[i-k] < j) {
                len[i+k] = len[i-k];
                ++k;
            }
            i += k, j -= k;
        }
        radius_odd.assign(S.size(), 0), radius_even.assign(S.size()+1, 0);
        for (int i = 0; i < (int)S.size(); ++i) {
            radius_odd[i] = (len[i*2] - 1) / 2;
            if (i > 0) radius_even[i] = len[i*2-1] / 2;
        }
        return len;
    }

    // radius, center is i (0 <= i < N)
    int get_odd(int i) { return radius_odd[i]; }

    // radius, center is between i-1 and i (0 <= i <= N)
    int get_even(int i) { return radius_even[i]; }

    // judge if [left, right) is palindrome
    bool ispalin(int left, int right) {
        int mid = (left + right) / 2;
        if ((right - left) & 1) return ( get_odd(mid) == (right - left + 1)/2);
        else return (get_even(mid) == (right - left)/2);
    }
};



/*/////////////////////////////*/
// Examples
/*/////////////////////////////*/

void RUPC_2019_day3_E() {
    int N;
    string S;
    cin >> N >> S;

    Manacher m(S);
    int res = N;
    for (int len = 2; len < N; ++len) {
        bool ok = true;
        for (int i = len - 1; i < N; i += len - 1) {
            if (m.get_odd(i) != min(i, N-i-1)) ok = false;
        }
        if (ok) {
            res = len;
            break;
        }
    }
    cout << res << endl;
}

void UKUKU_D() {
    int N, Q;
    string S;
    cin >> N >> Q >> S;
    Manacher mana(S);
    while (Q--) {
        int l, r;
        cin >> l >> r;
        --l;
    }
}


int main() {
    RUPC_2019_day3_E();
    //UKUKU_D();
}
accuracy: 1
time_ms: 30
memory_kb: 24412
final_rank: 10

code_snippet: #include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
using std::cout;
using std::cin;
using std::endl;
using ll=long long;
using ld=long double;
ll ILL=9167167167167167167;
const int INF=100000000;
const ll mod=998244353;
#define rep(i,a) for (int i=0;i<a;i++)
#define all(p) p.begin(),p.end()
template<class T> using _pq = priority_queue<T, vector<T>, greater<T>>;
template<class T> ll LB(vector<T> &v,T a){return lower_bound(v.begin(),v.end(),a)-v.begin();}
template<class T> ll UB(vector<T> &v,T a){return upper_bound(v.begin(),v.end(),a)-v.begin();}
template<class T> bool chmin(T &a,const T &b){if(a>b){a=b;return 1;}else return 0;}
template<class T> bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}else return 0;}
template<class T> void So(vector<T> &v) {sort(v.begin(),v.end());}
template<class T> void Sore(vector<T> &v) {sort(v.begin(),v.end(),[](T x,T y){return x>y;});}
void yneos(bool a){if(a) cout<<"Yes\n"; else cout<<"No\n";}
template<class T> void vec_out(vector<T> &p){for(int i=0;i<(int)(p.size());i++){if(i) cout<<" ";cout<<p[i];}cout<<"\n";}


namespace po167{
//LCP vec[0,n) and vec[i,n)
//for all i 
//O(vec.size())
template<class T>
std::vector<int> Z_algo(std::vector<T> &vec){
	int n=vec.size();
	int ind=1,j=0,k;
	std::vector<int> ans(n,0);
	ans[0]=n;
	while(ind<n){
		while(ind+j<n&&vec[j]==vec[ind+j]) j++;
		ans[ind]=j;
		if(j==0){
			ind++;
			continue;
		}
		k=1;
		while(k+ind<n&&ans[k]+k<j){
			ans[k+ind]=ans[k];
			k++;
		}
		j-=k;
		ind+=k;
	}
	return ans;
}
std::vector<int> Z_algo(std::string &vec){
	int n=vec.size();
	int ind=1,j=0,k;
	std::vector<int> ans(n,0);
	ans[0]=n;
	while(ind<n){
		while(ind+j<n&&vec[j]==vec[ind+j]) j++;
		ans[ind]=j;
		if(j==0){
			ind++;
			continue;
		}
		k=1;
		while(k+ind<n&&ans[k]+k<j){
			ans[k+ind]=ans[k];
			k++;
		}
		j-=k;
		ind+=k;
	}
	return ans;
}

template<class T>
std::vector<int> Manacher(std::vector<T> &p){
	int _n=p.size();
	std::vector<int> R(_n);
	int i=0,j=0;
	while(i<_n){
		while(i-j>=0&&i+j<_n&&p[i-j]==p[i+j]) j++;
		R[i]=j;
		int k=1;
		while(i-k>=0&&k+R[i-k]<j) R[i+k]=R[i-k],k++;
		i+=k,j-=k;
	}
	return R;
}

std::vector<int> Manacher(string S){
	vector<char> p((int)S.size());
	for(int i=0;i<(int)(S.size());i++) p[i]=S[i];
	return Manacher(p);
}

}
using po167::Z_algo;
using po167::Manacher;

void solve();
// oddloop
int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	
	int t=1;
	//cin>>t;
	rep(i,t) solve();
}

void solve(){
	int N;
	string S;
	cin>>N>>S;
	auto R=Manacher(S);
	auto Z=Z_algo(S);
	for(int i=1;i<N;i++){
		int a=i-R[i]+1,b=(i+R[i]);
		if(b==N){
			cout<<i+1<<"\n";
			return;
		}
		if(a<2){
			if(Z[i*2]+i*2==N){
				cout<<i+1<<"\n";
				return;
			}
		}
	}
}
accuracy: 1
time_ms: 10
memory_kb: 12136
final_rank: 5

code_snippet: #line 1 "a.cpp"
#define PROBLEM "https://judge.yosupo.jp/problem/enumerate_palindromes"
#line 2 "/home/kuhaku/home/github/algo/lib/template/template.hpp"
#pragma GCC target("sse4.2,avx2,bmi2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
template <class T, class U>
bool chmax(T &a, const U &b) {
    return a < (T)b ? a = (T)b, true : false;
}
template <class T, class U>
bool chmin(T &a, const U &b) {
    return (T)b < a ? a = (T)b, true : false;
}
constexpr int64_t INF = 1000000000000000003;
constexpr int Inf = 1000000003;
constexpr int MOD = 1000000007;
constexpr int MOD_N = 998244353;
constexpr double EPS = 1e-7;
constexpr double PI = M_PI;
#line 2 "/home/kuhaku/home/github/algo/lib/string/manacher.hpp"

/**
 * @brief Manacher
 * @details R[i] := S[i-R[i]:i] == S[i:i+R[i]]
 *
 * @tparam Container
 */
template <typename Container>
struct Manacher {
    Manacher(const Container &_s) : _size(_s.size()), s(_s), r(_s.size()) {
        int i = 0, j = 0;
        while (i < this->_size) {
            while (i - j >= 0 && i + j < this->_size && this->s[i - j] == this->s[i + j]) ++j;
            this->r[i] = j;
            int k = 1;
            while (i - k >= 0 && i + k < this->_size && k + this->r[i - k] < j)
                this->r[i + k] = this->r[i - k], ++k;
            i += k, j -= k;
        }
    }

    const auto &operator[](int i) const { return this->r[i]; }
    auto &operator[](int i) { return this->r[i]; }
    const auto begin() const { return this->r.begin(); }
    auto begin() { return this->r.begin(); }
    const auto end() const { return this->r.end(); }
    auto end() { return this->r.end(); }

    const std::vector<int> &get() { return this->r; }

  private:
    int _size;
    const Container &s;
    std::vector<int> r;
};
#line 3 "/home/kuhaku/home/github/algo/lib/template/macro.hpp"
#define FOR(i, m, n) for (int i = (m); i < int(n); ++i)
#define FORR(i, m, n) for (int i = (m)-1; i >= int(n); --i)
#define FORL(i, m, n) for (int64_t i = (m); i < int64_t(n); ++i)
#define rep(i, n) FOR (i, 0, n)
#define repn(i, n) FOR (i, 1, n + 1)
#define repr(i, n) FORR (i, n, 0)
#define repnr(i, n) FORR (i, n + 1, 1)
#define all(s) (s).begin(), (s).end()
#line 3 "/home/kuhaku/home/github/algo/lib/template/sonic.hpp"
struct Sonic {
    Sonic() {
        std::ios::sync_with_stdio(false);
        std::cin.tie(nullptr);
    }

    constexpr void operator()() const {}
} sonic;
#line 5 "/home/kuhaku/home/github/algo/lib/template/atcoder.hpp"
using ll = int64_t;
using ld = long double;
template <class T, class U>
std::istream &operator>>(std::istream &is, std::pair<T, U> &p) {
    return is >> p.first >> p.second;
}
template <class T>
std::istream &operator>>(std::istream &is, std::vector<T> &v) {
    for (T &i : v) is >> i;
    return is;
}
template <class T, class U>
std::ostream &operator<<(std::ostream &os, const std::pair<T, U> &p) {
    return os << '(' << p.first << ',' << p.second << ')';
}
template <class T>
std::ostream &operator<<(std::ostream &os, const std::vector<T> &v) {
    for (auto it = v.begin(); it != v.end(); ++it) {
        os << (it == v.begin() ? "" : " ") << *it;
    }
    return os;
}
template <class Head, class... Tail>
void co(Head &&head, Tail &&...tail) {
    if constexpr (sizeof...(tail) == 0) std::cout << head << '\n';
    else std::cout << head << ' ', co(std::forward<Tail>(tail)...);
}
template <class Head, class... Tail>
void ce(Head &&head, Tail &&...tail) {
    if constexpr (sizeof...(tail) == 0) std::cerr << head << '\n';
    else std::cerr << head << ' ', ce(std::forward<Tail>(tail)...);
}
template <typename T, typename... Args>
auto make_vector(T x, int arg, Args... args) {
    if constexpr (sizeof...(args) == 0) return std::vector<T>(arg, x);
    else return std::vector(arg, make_vector<T>(x, args...));
}
void setp(int n) {
    std::cout << std::fixed << std::setprecision(n);
}
void Yes(bool is_correct = true) {
    std::cout << (is_correct ? "Yes" : "No") << '\n';
}
void No(bool is_not_correct = true) {
    Yes(!is_not_correct);
}
void YES(bool is_correct = true) {
    std::cout << (is_correct ? "YES" : "NO") << '\n';
}
void NO(bool is_not_correct = true) {
    YES(!is_not_correct);
}
void Takahashi(bool is_correct = true) {
    std::cout << (is_correct ? "Takahashi" : "Aoki") << '\n';
}
void Aoki(bool is_not_correct = true) {
    Takahashi(!is_not_correct);
}
#line 4 "a.cpp"

int main(void) {
    int n;
    cin >> n;
    string s;
    cin >> s;

    if (n == 1) {
        co(1);
        return 0;
    }

    Manacher ma(s);

    FOR(m, 1, n) {
        bool flag = true;
        int k = m;
        while (k < n) {
            flag &= ma[k] >= min(m + 1, n - k);
            k += m;
        }
        if (flag) {
            co(m + 1);
            break;
        }
    }

    return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 7948
final_rank: 2

code_snippet: #include<bits/stdc++.h>

using namespace std;

#define int long long

constexpr long long INF = 1e18;
constexpr long long MOD = 1000000007; 

struct fast_io {
  fast_io(){
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(14);
  };
} fio;

int Manacher(string& S, vector<int>& R){
  R.assign(S.size(),0);
  
  for(int i = 0, j = 0; i < (int)S.size();){
    
    while(i-j >= 0 && i+j < (int)S.size() && S[i-j] == S[i+j]) ++j;
    
    R[i] = j;
    
    int k = 1;
    
    while(i-k >= 0 && i+k < (int)S.size() && k+R[i-k] < j) R[i+k] = R[i-k], ++k;
    
    i += k, j -= k;
  }
  
  return *max_element(R.begin(), R.end());
}


signed main(){
  
  int N;
  string T, t;
  vector<int>R;
  
  cin>>N;
  
  cin>>T;
  
  Manacher(T, R);
  
  for(int i = 1; i < N; i++){
    bool flag = true;
    
    for(int j = 0; j < N && flag; j += i){
      if(R[j] < min(N-j, j+1))  flag = false;
    }
    
    if(flag) {
      cout<<i+1<<endl;
      return 0;
    }
  }
  
  return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 12060
final_rank: 4

code_snippet: #include<bits/stdc++.h>

using namespace std;

#define int long long

constexpr long long INF = 1e18;
constexpr long long MOD = 1000000007; 

struct fast_io {
  fast_io(){
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(14);
  };
} fio;

int Manacher(string& S, vector<int>& R){
  R.assign(S.size(),0);
  
  for(int i = 0, j = 0; i < (int)S.size();){
    
    while(i-j >= 0 && i+j < (int)S.size() && S[i-j] == S[i+j]) ++j;
    
    R[i] = j;
    
    int k = 1;
    
    while(i-k >= 0 && i+k < (int)S.size() && k+R[i-k] < j) R[i+k] = R[i-k], ++k;
    
    i += k, j -= k;
  }
  
  return *max_element(R.begin(), R.end());
}


signed main(){
  
  int N;
  string T, t;
  vector<int>R;
  
  cin>>N;
  
  cin>>T;
  
  Manacher(T, R);
  
  for(int i = 1; i < N; i++){
    bool flag = true;
    
    for(int j = i; j < N; j += i*2){
      if(R[j] < min(i+1, N-j) || T[i] != T[j]) {
        flag = false;
        break;
      }
    }
    
    for(int j = 0; j < N; j += i*2){
      if(R[j] < min({i+1, j+1, N-j}) || T[0] != T[j]) {
        flag = false;
        break;
      }
    }
    
    if(flag) {
      cout<<i+1<<endl;
      return 0;
    }
  }
  
  return 0;
}
accuracy: 1
time_ms: 30
memory_kb: 12116
final_rank: 8

code_snippet: #include<bits/stdc++.h>
using ll = long long;
#define var auto
const char newl = '\n';

using namespace std;

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

template<typename T, T MOD, T B>
struct RollingHash {
  using ll = long long;
  vector<T> hash, po;
  RollingHash(vector<T> vs) { init(vs); }
  RollingHash(string& s) {
    vector<T> vs;
    for (char c : s) vs.emplace_back(c);
    init(vs);
  }
  void init(vector<T> vs) {
    int n = vs.size();
    hash.assign(n + 1, 0);
    po.assign(n + 1, 1);
    for (int i = 0; i < n; i++) {
      hash[i + 1] = ((ll)hash[i] * B + vs[i]) % MOD;
      po[i + 1] = (ll)po[i] * B % MOD;
    }
  }
  //S[l, r)
  T find(int l, int r) {
    T res = (ll)hash[r] + MOD - (ll)hash[l] * po[r - l] % MOD;
    return res >= MOD ? res - MOD : res;
  }
};

using rollinghash = RollingHash<uint64_t, 998244353, 20211027>;


int main() {
  int n;
  cin >> n;
  string t;
  cin >> t;
  var revt = t;
  reverse(revt.begin(), revt.end());

  rollinghash t_rh(t);
  rollinghash revt_rh(revt);
  var get_hash = [&](int l, int r) {
    assert(l <= r);
    // return t.substr(l, r - l);
    return t_rh.find(l, r);
  };
  var get_revhash = [&](int l, int r) {
    assert(l <= r);
    // return revt.substr(n - r, r - l);
    return revt_rh.find(n - r, n - l);
  };

  // 循環節の長さは i * 2 - 2
  vector<bool> is_valid(n + 1, false);
  is_valid[n] = true;
  int res = n;
  for (int len = n - 1; len >= 1; len--) {
    var recLen = min(len * 2 - 2, n);
    var tailLen = recLen - len;
    
    var headhash = get_hash(len - (tailLen + 1), len);
    var tailhash = get_revhash(recLen - (tailLen + 1), recLen);

    if (headhash != tailhash) continue;
    
    var afterLen = min(recLen, n - recLen);
    var rechash = get_hash(0, afterLen);
    var afterhash = get_hash(recLen, recLen + afterLen);

    if (rechash != afterhash) continue;
    is_valid[len] = is_valid[min(len * 2 - 1, n)];
    if (is_valid[len]) res = len;
  }
  cout << res << endl;
}
accuracy: 1
time_ms: 30
memory_kb: 52492
final_rank: 12

code_snippet: #include<bits/stdc++.h>
#define rep(i,a,...) for(int i = (a)*(strlen(#__VA_ARGS__)!=0);i<(int)(strlen(#__VA_ARGS__)?__VA_ARGS__:(a));++i)
#define per(i,a,...) for(int i = (strlen(#__VA_ARGS__)?__VA_ARGS__:(a))-1;i>=(int)(strlen(#__VA_ARGS__)?(a):0);--i)
#define foreach(i, n) for(auto &i:(n))
#define all(x) (x).begin(), (x).end()
#define bit(x) (1ll << (x))
#define lambda(RES_TYPE, ...) (function<RES_TYPE(__VA_ARGS__)>)[&](__VA_ARGS__) -> RES_TYPE
#define method(FUNC_NAME, RES_TYPE, ...) function<RES_TYPE(__VA_ARGS__)> FUNC_NAME = lambda(RES_TYPE, __VA_ARGS__)
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
//const ll MOD = (ll)1e9+7;
const ll MOD = 998244353;
const int INF = (ll)1e9+7;
const ll INFLL = (ll)1e18;
template<class t>
using vvector = vector<vector<t>>;
template<class t>
using vvvector = vector<vector<vector<t>>>;
template<class t>
using priority_queuer = priority_queue<t, vector<t>, greater<t>>;
template<class t, class u> bool chmax(t &a, u b){if(a<b){a=b;return true;}return false;}
template<class t, class u> bool chmin(t &a, u b){if(a>b){a=b;return true;}return false;}
#ifdef DEBUG
#define debug(x) cout<<"LINE "<<__LINE__<<": "<<#x<<" = "<<x<<endl;
#else
#define debug(x) (void)0
#endif

namespace templates{
    ll modpow(ll x, ll b,ll mod=MOD){
        ll res = 1;
        while(b){
            if(b&1)res = res * x % mod;
            x = x * x % mod;
            b>>=1;
        }
        return res;
    }

    ll modinv(ll x){
        return modpow(x, MOD-2);
    }

    bool was_output = false;

    void print();
    template <class t> void print(const vector<t> &);
    template <class t, class u> void print(const pair<t, u> &);
    template <class t> void print(const t&);
    template <class Head, class... Tail> void print(const Head&, const Tail&...);

    template <class t> void println(const vector<vector<t>>&);
    template <class t> void println(const vector<t>&);
    template <class t> void println(const t&);
    template <class Head, class... Tail> void println(const Head&, const Tail&...);
    void println();
    void newline();

    void print(){
        return;
    }

    template <class t>
    void print(const vector<t>&x){
        for(const t&i:x)print(i);
    }
    template <class t, class u>
    void print(const pair<t,u>&p){
        print(p.first);
        print(p.second);
    }
    template <class t>
    void print(const t&x){
        if(was_output)cout<<" ";
        cout<<x;
        was_output = true;
    }
    template <class Head, class... Tail>
    void print(const Head&head,const Tail&...tail){
        print(head);
        print(tail...);
    }

    template<class t>
    void println(const vector<vector<t>>&x){
        for(vector<t> i:x)println(i);
    }
    template<class t>
    void println(const vector<t>&x){
        for(const t&i:x)print(i);
        println();
    }
    template <class t>
    void println(const t&x){
        print(x);
        println();
    }
    void println(){
        if(was_output){
            cout << endl;
            was_output = false;
        }
    }
    template <class Head, class... Tail>
    void println(const Head&head,const Tail&...tail){
        print(head);
        println(tail...);
    }

    void newline(){
        was_output = true;
        println();
    }

    template<class t>
    istream& operator>>(istream&is, vector<t>&x){
        for(auto &i:x)is >> i;
        return is;
    }

    template<class t, class u>
    istream& operator>>(istream&is, pair<t, u>&x){
        is >> x.first >> x.second;
        return is;
    }

    template<class t>
    ostream& operator<<(ostream&os, vector<t> &v){
        os << "{";
        for(t &i:v){
            os << i << ", ";
        }
        os << "}";
        return os;
    }

    template<class t = long long>
    t in(){
        t res; cin >> res; return res;
    }

    template<class t>
    vector<t> sorted(vector<t> line,function<bool(t,t)> comp=[](t a,t b){return a<b;}){
        sort(line.begin(),line.end(),comp);
        return line;
    }

    template<class t>
    vector<t> reversed(vector<t> line){
        reverse(line.begin(),line.end());
        return line;
    }
    string reversed(string str){
        reverse(str.begin(),str.end());
        return str;
    }

    long long gcd(long long a,long long b){
        while(b){
            a %= b;
            swap(a,b);
        }
        return a;
    }

    long long lcm(long long a,long long b){
        return a / gcd(a,b) * b;
    }

    class output_initializer{
    public:
        output_initializer(){
            ios::sync_with_stdio(false);
            cin.tie(nullptr);
            cout << setprecision(20);
        }
    };output_initializer OUTPUT_INITIALIZER_INSTANCE = output_initializer();
}

using namespace templates;

template <int B, long long mod>
class rolling_hash{
public:
    class modint{
    public:
        long long x;
        modint(long long a){x=a%mod;if(x<0)x+=mod;}
        modint(){x=0;}

        modint pow(long long a){
            modint res(1), b(x);
            while(a){
                if(a&1)res*=b;
                b*=b;
                a>>=1;
            }
            return res;
        }

        modint inv(){return pow(mod-2);}

        modint& operator+=(modint a){x=(x+a.x)%mod;return *this;}
        modint& operator-=(modint a){x=x-a.x;if(x<0)x+=mod;return *this;}
        modint& operator*=(modint a){x=x*a.x%mod;return *this;}
        modint& operator/=(modint a){x=x*a.inv().x%mod;return *this;}

        modint operator+(modint a){return modint(x)+=a;}
        modint operator-(modint a){return modint(x)-=a;}
        modint operator*(modint a){return modint(x)*=a;}
        modint operator/(modint a){return modint(x)/=a;}

        modint operator-(){return modint(x);}

        bool operator==(const modint a){return x == a.x;}
        bool operator<(const modint a){return x < a.x;}
        bool operator>(const modint a){return x > a.x;}
    };
    vector<modint> line;
    vector<modint> revs;
    vector<modint> muls;
    vector<modint> invs;
    modint inv;
    int n;
    rolling_hash(string str){
        inv = modint(1) / B;
        n = str.size();
        line.assign(n+1,0);
        revs.assign(n+1,0);
        muls.assign(n+1,1);
        invs.assign(n+1,1);
        for(int i=0;i<n;++i){
            muls[i+1] = muls[i] * B;
            invs[i+1] = invs[i] * inv;
            line[i+1] = line[i] + muls[i+1] * str[i];
            revs[i+1] = revs[i] + muls[i+1] * str[n-i-1];
        }
    }
    //
    long long get(int l,int r){
        return ((line[r] - line[l]) * invs[l+1]).x;
    }

    long long revget(int len,int x){
        modint res = 0;
        if(len < x){
            res = line[len];
            int a = n - (2*len-2-x) - 1;
            int b = n - len + 1;
            res += muls[len+1] * (revs[a]-revs[b]) * invs[b+1];
        }else{
            res = line[x];
        }
        return (res * invs[1]).x;
    }
};

int func(){
    int n = in();
    string str = in<string>();
    rolling_hash<11,998244353> r1(str);
    rolling_hash<13,1000000007> r2(str);
    rolling_hash<17,1000000009> r3(str);

    method(check,bool,int len){
        int olen = len;
        len = len * 2 - 2;
        int i;
        for(i=0;i+len<=n;i+=len){
            if(r1.revget(olen,len)!=r1.get(i,i+len))return false;
            if(r2.revget(olen,len)!=r2.get(i,i+len))return false;
            if(r3.revget(olen,len)!=r3.get(i,i+len))return false;
        }
        if(i<n){
            int c = n - i;
            if(r1.revget(olen,c)!=r1.get(i,n))return false;
            if(r2.revget(olen,c)!=r2.get(i,n))return false;
            if(r3.revget(olen,c)!=r3.get(i,n))return false;
        }
        return true;
    };
    for(int i=2;i<n;++i){
        if(check(i))return i;
    }
    return n;
}


int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    println(func());
    return 0;
}
accuracy: 1
time_ms: 640
memory_kb: 98880
final_rank: 15

code_snippet: #include<bits/stdc++.h>
using ll = long long;
#define var auto
const char newl = '\n';

using namespace std;

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

template<typename T, T MOD, T B>
struct RollingHash {
  using ll = long long;
  vector<T> hash, po;
  RollingHash(vector<T> vs) { init(vs); }
  RollingHash(string& s) {
    vector<T> vs;
    for (char c : s) vs.emplace_back(c);
    init(vs);
  }
  void init(vector<T> vs) {
    int n = vs.size();
    hash.assign(n + 1, 0);
    po.assign(n + 1, 1);
    for (int i = 0; i < n; i++) {
      hash[i + 1] = ((ll)hash[i] * B + vs[i]) % MOD;
      po[i + 1] = (ll)po[i] * B % MOD;
    }
  }
  //S[l, r)
  T find(int l, int r) {
    T res = (ll)hash[r] + MOD - (ll)hash[l] * po[r - l] % MOD;
    return res >= MOD ? res - MOD : res;
  }
};

using rollinghash = RollingHash<uint64_t, 998244353, 20211027>;


int main() {
  int n;
  cin >> n;
  string t;
  cin >> t;
  var revt = t;
  reverse(revt.begin(), revt.end());

  rollinghash t_rh(t);
  rollinghash revt_rh(revt);
  var get_hash = [&](int l, int r) {
    assert(l <= r);
    // return t.substr(l, r - l);
    return t_rh.find(l, r);
  };
  var get_revhash = [&](int l, int r) {
    assert(l <= r);
    // return revt.substr(n - r, r - l);
    return revt_rh.find(n - r, n - l);
  };

  // 循環節の長さは i * 2 - 2
  vector<bool> is_valid(n + 1, false);
  is_valid[n] = true;
  int res = n;
  for (int len = n - 1; len >= 1; len--) {
    var recLen = min(len * 2 - 2, n);
    var tailLen = recLen - len;
    
    var headhash = get_hash(len - (tailLen + 1), len);
    var tailhash = get_revhash(recLen - (tailLen + 1), recLen);

    if (headhash != tailhash) continue;
    
    var afterLen = min(recLen, n - recLen);
    var rechash = get_hash(0, afterLen);
    var afterhash = get_hash(recLen, recLen + afterLen);

    if (rechash != afterhash) continue;
    is_valid[len] = is_valid[min(len * 2 - 1, n)];
    if (is_valid[len]) res = len;
  }
  cout << res << endl;
}
accuracy: 1
time_ms: 30
memory_kb: 52636
final_rank: 13

code_snippet: #include <cmath>
#include <vector>
#include <iostream>
#include <iomanip>
#include <fstream>
#include <algorithm>
#include <set>
#include <queue>
#include <string>
#include <map>
#include <stack>
#include <climits>
#include <array>
#include <unordered_set>
#include <unordered_map>
#include <memory>
#include <functional>
#include <cfloat>
#include <numeric>
#include <random>
#include <sstream>
#include <bitset>
#include <complex>
#include <chrono>
#include <cassert>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>


std::vector<int> calc_palindrome(const std::string &str) {
	std::vector<int> result(str.size(), 0);
	int left{ 0 }, right{ 0 };
	for (auto i = 0; i < str.size(); ++i) {
		result[i] = i < right ? std::min(result[left - (i - left)], right - i) : 0;
		if (i + result[i] < right) {
			continue;
		}
		left = i;
		auto& len = result[i];
		while (i - len >= 0 && i + len < str.size() && str[i - len] == str[i + len]) {
			++len;
		}
		right = i + len;
	}
	return result;
}
std::vector<int> z_algorithm(const std::string& str) {
	std::vector<int> result(str.size(), 0);
	int left{ 1 }, right{ 1 };
	for (auto i = 1; i < str.size(); ++i) {
		result[i] = std::max(0, std::min(right - i, result[i - left]));
		if (i + result[i] < right) {
			continue;
		}
		left = i;
		auto& len = result[i];
		while (i + len < str.size() && str[len] == str[i + len]) {
			++len;
		}
		right = i + len;
	}
	result[0] = str.size();
	return result;
}
int solve(const std::string str) {
	const int n = str.size();
	const auto palindrome = calc_palindrome(str);
	const auto suffix = z_algorithm(str);
	int result{ n };
	const auto repeat = [&suffix, n](const int i) {
		return suffix[i] + i == n;
	};
	const auto reverse = [&palindrome](const int from, const int to) {
		if ((to ^ from) & 1) {
			return false;
		}
		else {
			const auto mid = (to + from) >> 1;
			return to < palindrome[mid] + mid;
		}
	};
	for (auto i = 2; i < suffix.size(); ++i) {
		if (repeat(i) && reverse(0, i)) {
			result = std::min(result, (i + 2) >> 1);
			return result;
		}
		if (reverse(i - (n - 1 - i), n - 1)) {
			result = std::min(result, i + 1);
		}
	}
	return result;
}
int main() {
	int n; std::cin >> n;
	std::string str; std::cin >> str;
	const int result = solve(str);
	std::cout << result << std::endl;
}
accuracy: 1
time_ms: 10
memory_kb: 12888
final_rank: 7

code_snippet: #include <bits/stdc++.h>

#define For(i, a, b) for (int(i) = (int)(a); (i) < (int)(b); ++(i))
#define rFor(i, a, b) for (int(i) = (int)(a)-1; (i) >= (int)(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second

using namespace std;

typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<lint, lint> pll;

template <class T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T>
bool chmin(T &a, const T &b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

template <class T>
T div_floor(T a, T b) {
    if (b < 0) a *= -1, b *= -1;
    return a >= 0 ? a / b : (a + 1) / b - 1;
}
template <class T>
T div_ceil(T a, T b) {
    if (b < 0) a *= -1, b *= -1;
    return a > 0 ? (a - 1) / b + 1 : a / b;
}

template <typename T>
struct coord_comp {
    vector<T> v;
    bool sorted = false;

    coord_comp() {}

    int size() { return v.size(); }

    void add(T x) { v.push_back(x); }

    void build() {
        sort(v.begin(), v.end());
        v.erase(unique(v.begin(), v.end()), v.end());
        sorted = true;
    }

    int get_idx(T x) {
        assert(sorted);
        return lower_bound(v.begin(), v.end(), x) - v.begin();
    }
};

constexpr lint mod = 1000000007;
constexpr lint INF = mod * mod;
constexpr int MAX = 200010;

vector<int> manacher(string &s) {
    int n = s.size();
    vector<int> ret(n);
    int i = 0, j = 0;
    while (i < n) {
        while (i - j >= 0 && i + j < n && s[i - j] == s[i + j]) ++j;
        ret[i] = j;
        int k = 1;
        while (i - k >= 0 && k + ret[i - k] < j) ret[i + k] = ret[i - k], ++k;
        i += k;
        j -= k;
    }
    return ret;
}

int main() {
    int n;
    string t;
    cin >> n >> t;

    auto v = manacher(t);
    int ans = n;
    For(len, 2, n) {
        bool flag = true;
        for (int i = len - 1; i < n; i += len - 1) {
            if (v[i] != min(i + 1, n - i)) {
                flag = false;
                break;
            }
        }
        if (flag) chmin(ans, len);
    }
    printf("%d\n", ans);
}
accuracy: 1
time_ms: 10
memory_kb: 8232
final_rank: 1

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
using ld = long double;
using P = pair<ll, ll>;
using Pld = pair<ld, ld>;
using Vec = vector<ll>;
using VecP = vector<P>;
using VecB = vector<bool>;
using VecC = vector<char>;
using VecD = vector<ld>;
using VecS = vector<string>;
template <class T>
using Vec2 = vector<vector<T>>;
#define REP(i, m, n) for(ll i = (m); i < (n); ++i)
#define REPN(i, m, n) for(ll i = (m); i <= (n); ++i)
#define REPR(i, m, n) for(ll i = (m)-1; i >= (n); --i)
#define REPNR(i, m, n) for(ll i = (m); i >= (n); --i)
#define rep(i, n) REP(i, 0, n)
#define repn(i, n) REPN(i, 1, n)
#define repr(i, n) REPR(i, n, 0)
#define repnr(i, n) REPNR(i, n, 1)
#define all(s) (s).begin(), (s).end()
template <class T1, class T2>
bool chmax(T1 &a, const T2 b) { if (a < b) { a = b; return true; } return false; }
template <class T1, class T2>
bool chmin(T1 &a, const T2 b) { if (a > b) { a = b; return true; } return false; }
template <class T>
istream &operator>>(istream &is, vector<T> &v) { for (T &i : v) is >> i; return is; }
template <class T>
ostream &operator<<(ostream &os, const vector<T> &v) { for (const T &i : v) os << i << ' '; return os; }
void _co() { cout << '\n'; }
template <class Head, class... Tail>
void _co(Head&& head, Tail&&... tail) { cout << ' ' << head; _co(forward<Tail>(tail)...); }
template <class Head, class... Tail>
void co(Head&& head, Tail&&... tail) { cout << head; _co(forward<Tail>(tail)...); }
void ce() { cerr << '\n'; }
template <class Head, class... Tail>
void ce(Head&& head, Tail&&... tail) { cerr << head << ' '; ce(forward<Tail>(tail)...); }
void sonic() { ios::sync_with_stdio(false); cin.tie(nullptr); }
void setp(const int n) { cout << fixed << setprecision(n); }
constexpr int64_t LINF = 1000000000000000001;
constexpr int64_t MOD = 1000000007;
constexpr int64_t MOD_N = 998244353;
constexpr long double EPS = 1e-11;
const double PI = acos(-1);

template <typename Type>
struct Manacher {
    Type s;
    vector<int64_t> data;

    Manacher(const Type &_s) : s(_s), data(_s.size()) {
        int64_t i = 0, j = 0;
        while (i < s.size()) {
            while (i - j >= 0 && i + j < s.size() && s[i - j] == s[i + j]) ++j;
            data[i] = j;
            int64_t k = 1;
            while (i - k >= 0 && i + k < s.size() && k + data[i - k] < j)
                data[i + k] = data[i - k], ++k;
            i += k, j -= k;
        }
    }

    const int64_t& operator[](int64_t i) const {
        return data[i];
    }
};

int main(void) {
    ll n;
    cin >> n;
    string s;
    cin >> s;

    if (n == 1) {
        co(1);
        return 0;
    }

    Manacher<string> ma(s);

    REPN(m, 2, n) {
        bool flg = true;
        ll k = m - 1;
        while (k < n) {
            flg &= ma[k] >= min(m, n - k);
            k += m - 1;
        }
        if (flg) {
            co(m);
            break;
        }
    }

    return 0;
}
accuracy: 1
time_ms: 30
memory_kb: 13116
final_rank: 9

code_snippet: #include <bits/stdc++.h>
//#include <atcoder/all>
//using namespace atcoder;
const double pi = 3.141592653589793238462643383279;
using namespace std;
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<long long, long long> PLL;
typedef pair<int, PII> TIII;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;

//container util
//------------------------------------------
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SQ(a) ((a) * (a))
#define EACH(i, c) for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort((c).begin(), (c).end())

//repetition
//------------------------------------------
#define FOR(i, s, n) for (int i = s; i < (int)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define MOD 1000000007

#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define trav(a, x) for (auto &a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
const double EPS = 1e-3, PI = acos(-1);
//ここから編集

vector<int> Manacher(const string &S) {
    int N = (int)S.size();
    vector<int> res(N);
    int i = 0, j = 0;
    while (i < N) {
        while (i-j >= 0 && i+j < N && S[i-j] == S[i+j]) ++j;
        res[i] = j;
        int k = 1;
        while (i-k >= 0 && i+k < N && k+res[i-k] < j) res[i+k] = res[i-k], ++k;
        i += k, j -= k;
    }
    return res;
}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(6);

  int N; cin >> N;
  string s; cin >> s;

  auto v = Manacher(s);

  for(int len=2; len<=N; len++){
    bool ok = true;
    for(int i=len-1; i<N; i+=len-1){
      if(v[i] != min(i+1, N-i)) ok = false;
    }
    if(ok){
      cout << len << endl;
      return 0;
    }
  }
  return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 7952
final_rank: 3