#include #define EQ(a,b) (fabs(a - b) <= fabs(a + b)*EPS) using namespace std; bool Check(const map & stor) { int lichy = 0; for(auto i : stor) { if(i.second%2 == 1) { if(lichy >= 1) return false; else { lichy++; } } } return true; } struct Val { map m_Stor; int start; int end; Val(const map & src, int s, int e) { m_Stor = src; start = s; end = e; }; }; int Solve(const string & input) { map stor; for(auto i : input) { stor[i - 'a']++; } queue q; q.push({stor, 0, int( input.size()) - 1}); while(! q.empty()) { auto & cur = q.front(); if( cur.start < cur.end && cur.end >= 0 && cur.start < (int)input.size()) { if(Check(cur.m_Stor)) return cur.end - cur.start + 1; cur.m_Stor[input[cur.start] - 'a']--; q.push({cur.m_Stor, cur.start + 1, cur.end}); cur.m_Stor[input[cur.start] - 'a']++; cur.m_Stor[input[cur.end] - 'a']--; q.push({cur.m_Stor, cur.start, cur.end-1}); } q.pop(); } return 1; } int main() { ios::sync_with_stdio(false); int len; string input; cin >> len >> input; //cout << len << " " << input << endl; cout << Solve(input) << endl; return 0; }