#include #define ff first #define ss second using namespace std; using ii = pair; const ii N_range = { 1, 4*1e5 }; const int K = 100; const int MAX_CASE_CNT = 1000; const int MOD = 1e9+7; vector z_function(string s) { int n = (int) s.length(); vector z(n); for (int i = 1, l = 0, r = 0; i < n; ++i) { if (i <= r) z[i] = min (r - i + 1, z[i - l]); while (i + z[i] < n && s[z[i]] == s[i + z[i]]) ++z[i]; if (i + z[i] - 1 > r) l = i, r = i + z[i] - 1; } return z; } int main() { ios::sync_with_stdio(0); int n; string s; assert(cin >> n && "Could not read N"); assert(N_range.ff <= n && n <= N_range.ss && "Invalid value of N"); assert(cin.get() == '\n' && "Something else than new line follows N"); assert(cin >> s && "Could not read S"); assert(n == (int)s.size() && "N does not correspond to length of S"); assert(s.find_first_not_of("abcdefghijklmnopqrstuvwxyz") == string::npos && "S contains faulty characters"); auto rs = s; reverse(rs.begin(), rs.end()); rs += s; auto z = z_function(rs); int res = rs.size(); for (int i = n; i < (int)rs.size(); ++i) { if (i + z[i] == 2 * n) res = min(res, n - z[i]); } cout << res << endl; return 0; }