#include using namespace std; int main() { int N; cin >> N; string s; cin >> s; // we should calculate hash of last N chars // also we should calculate hash of last N chars backwards uint h0 = 0; uint h1 = 0; uint h0q = 1; const uint Q = 33; vector T0(N); vector T1(N); for (int i = N-1; i >= 0; i--) { h1 *= Q; h1 += s[i]; T1[i] = h1; h0 += s[i] * h0q; h0q *= Q; T0[i] = h0; //cout << T0[i] << " " << T1[i] << endl; } for (int i = 0; i < N; i++) { // hash matching if (T0[i] == T1[i]) { // real match bool good = true; for (int k = i; good && k < N; k++) { int l = i+N-1-k; if (s[k] != s[l]) { good = false; } } if (good) { cout << i << endl; return 0; } } } }