#include #include using namespace std; string str; bool isPalindrome(int a, int b) { if (a == b) return true; if (a + 1 == b) { if (str[a] == str[b]) return true; } if (str[a] != str[b]) return false; return isPalindrome(a + 1, b - 1); } int main() { int n; cin >> n >> str; string c = str; while (c.find(str[n - 1]) != string::npos) { c = c.substr(c.find(str[n - 1]) + 1); if (isPalindrome(n - 1 - c.length(), n - 1)) { cout << n - 1 - c.length() << endl; break; } } }