#include using namespace std; typedef long long ll; typedef long double ld; #define rep(i, a, n) for (int i = (a); i < (n); i++) #define per(i, a, n) for (int i = (n) - 1; i >= (a); i--) #define FOR(i, n) rep(i, a, (n)) typedef unsigned long long H; static const H C = 123891739; typedef H K; struct HashInterval { vector ha, pw; HashInterval(string& str) : ha(str.size()+1), pw(ha) { pw[0] = 1; rep(i,0,str.size()) ha[i+1] = ha[i] * C + str[i], pw[i+1] = pw[i] * C; } H hashInterval(int a, int b) { return ha[b] - ha[a] * pw[b - a]; } }; int main(void) { ios_base::sync_with_stdio(false); int n; cin >> n; string s; cin >> s; string sr = s; reverse(sr.begin(), sr.end()); int res = n-1; HashInterval h1(s), h2(sr); rep(len,0,n) { //cout << "foo" << endl; if (n-2*len >= 0 && h2.hashInterval(0, len) == h1.hashInterval(n-2*len, n-len)) { res = min(res, n - 2*len); } //cout << "foo" << endl; if (len > 0 && n-2*len+1>= 0 && h2.hashInterval(0, len) == h1.hashInterval(n-2*len+1, n-len+1)) { res = min(res, n - 2*len+1); } //cout << "foo" << endl; } cout << res << endl; }