#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 last_positions[400000]; int xd = 0; int main() { int n; cin >> n >> str; string c = str; while (c.find(str[n - 1]) != string::npos) { last_positions[xd] = c.find(str[n - 1]); c = c.substr(last_positions[xd] + 1); xd++; } for (int i = 0; i < xd; i++) { if (isPalindrome(last_positions[i], n - 1)); cout << last_positions[i] << endl; break; } }