#include #define FOR(i, n) for(int i = 0; i < (n); ++i) #define REP(i, a, b) for(int i = (a); i < (b); ++i) #define TRAV(i, a) for(auto &i : (a)) #define X first #define Y second #define MP std::make_pair #define PR std::pair #define SZ(x) ((int)(x).size()) typedef long long ll; typedef std::pair PII; typedef std::vector VI; // sh - parzystosc // 0 - parzyste // aaaa 0 [0, 1, 2, 1] 1 [1, 2, 2, 1] std::vector manacher(const std::string &w, int sh){ int n = SZ(w); VI p(n); int g = 0; p[0] = sh; REP(i, 1, n){ if(2*g-i >= 0) p[i] = std::max(std::min(p[2*g-i], p[g]+g-i), 0); else p[i] = 0; while(i-p[i]-1+sh >= 0 && i+p[i] < n && w[i+p[i]] == w[i-p[i]-1+sh]) p[g=i]++; } return p; } int main(){ std::ios_base::sync_with_stdio(false); std::cin.tie(0); int n; std::cin >> n; std::string s; std::cin >> s; auto par = manacher(s, 0); auto np = manacher(s, 1); int best = 1000000000; FOR(i, n){ if(np[i] == n-i){ best = std::min(best, i+1 - np[i]); } } FOR(i, n){ if(par[i] == n-i){ best = std::min(best, i-par[i]); } } std::cout << best; return 0; }