#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; bool isPalindrome(const string & s) { for (int i = 0; i < (int)s.size(); ++i) if (s[i] != s[s.size()-i-1]) return false; return true; } 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"); for (int i = 0; i <= n; ++i) { auto tmp = s; for (int j = i; j; --j) tmp.push_back(s[j-1]); // cout << tmp << endl; if (isPalindrome(tmp)) { cout << i << endl; return 0; } } return 0; }