#include using namespace std; const long long OO = 1e9 + 7; const int MAXN = 1e5 + 5; long long base[3], p[3][MAXN], h[3][MAXN], rev_h[3][MAXN]; int n; string s; long long getH(int ty, int i, int j) { long long tmp = (h[ty][j] - h[ty][i - 1] * p[ty][j - i + 1]); return tmp; } long long getRevH(int ty, int i, int j) { long long tmp = (rev_h[ty][i] - rev_h[ty][j + 1] * p[ty][j - i + 1]); return tmp; } bool check(int s1, int e1, int s2, int e2) { if (s1 <= 0 || e1 <= 0) return false; for(int ty = 1; ty <= 2; ++ty) { long long tmp1 = getH(ty, s2, e2); long long tmp2 = getRevH(ty, s1, e1); if (tmp1 != tmp2) return false; } return true; } void initH(const string &s) { int n = s.size(); base[1] = 233; base[2] = 719; //MOD[1] = OO; MOD[2] = OO + 6; p[1][0] = p[2][0] = 1; for(int ty = 1; ty <= 2; ++ty) { for(int i = 1; i <= n; ++i) p[ty][i] = (p[ty][i - 1] * base[ty]); for(int i = 1; i <= n; ++i) h[ty][i] = (h[ty][i - 1] * base[ty] + s[i - 1] - 'a' + 1); for(int i = n; i > 0; --i) rev_h[ty][i] = (rev_h[ty][i + 1] * base[ty] + s[i - 1] - 'a' + 1); } } int main() { // cout << "Hello world!" << endl; ios_base::sync_with_stdio(false); cin.tie(0); cin >> n; cin >> s; initH(s); int res = 0; for(int i = n; i > 0; --i) { int e2 = n; int s2 = i; int l = (n - i + 1); if (check(s2 - l + 1, s2, s2, e2)) { res = max(res, 2 * l - 1); } if (check(s2 - 1 - l + 1, s2 - 1, s2, e2)) { res = max(res, 2 * l); } } cout << n - res << '\n'; return 0; }