#include #include #include using namespace std; string str; string c; bool isPalindrome() { int div_point; string eleje; string vege; if ((c.length()) % 2 == 0) { div_point = c.length() / 2; eleje = c.substr(0, div_point); vege = c.substr(div_point); } else { div_point = c.length() / 2 + 1; eleje = c.substr(0, div_point); vege = c.substr(div_point - 1); } reverse(vege.begin(), vege.end()); return (vege == eleje); } int main() { int n; cin >> n >> str; int div = n / 2; string str_to_find; string c; while (div != n) { str_to_find = str.substr(div); reverse(str_to_find.begin(), str_to_find.end()); c = str; size_t t; while (t = c.find(str_to_find), t != string::npos) { c = c.substr(t); if (isPalindrome()) { cout << n - c.length() << endl; return 0; } c = c.substr(1); } div++; } }