#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); } //cout << div_point << endl; reverse(vege.begin(), vege.end()); //cout << c << endl; //cout << eleje << endl << vege << endl; //cout << endl; return (vege == eleje); } int main() { int n; cin >> n >> str; c = str; while (c.find(str[n - 1]) != string::npos) { c = c.substr(c.find(str[n - 1])); if (isPalindrome()) { cout << n - c.length() << endl; break; } c = c.substr(1); } }