#include using namespace std; int main() { const int CHAR_COUNT = 20; int inputLength = 0; string line; cin >> inputLength; std::getline(cin, line); int maxSequenceLength = 0; // sudy bool isEven[CHAR_COUNT]; std::getline(cin, line); int charCount[CHAR_COUNT] = {0}; for (char c : line) { charCount[c - 'a']++; } int roundCount[CHAR_COUNT]; for (int i = 0; i < inputLength; ++i) { if (inputLength - i < maxSequenceLength) { break; } for (int j = 0; j < CHAR_COUNT; ++j) { isEven[j] = true; roundCount[j] = charCount[j]; } bool ok = true; int oddCount = 0; char c; int len = 0; for (int k = i; k < inputLength; ++k) { c = line[k]; roundCount[c - 'a']--; len++; isEven[c - 'a'] = !isEven[c - 'a']; if (isEven[c - 'a']) { oddCount--; } else { oddCount++; } ok = oddCount <= 1; if (ok) { maxSequenceLength = max(maxSequenceLength, len); } else { int counter = 0; for (int n = 0; n < CHAR_COUNT; ++n) { if (!isEven[n] && roundCount == 0) { counter++; } } if (counter >= 2) { break; } } } } cout << maxSequenceLength << endl; return 0; }