#include #include #include #include #include #include #include #include #include using namespace std; void print_map(map m) { for(auto itr = m.begin(); itr != m.end(); ++itr) { std::cout << "key = " << itr->first << ", val = " << itr->second << "\n"; } } void print_vector(vector v) { for(auto itr = v.begin(); itr != v.end(); ++itr) { std::cout << *itr << ", "; } cout << endl; } vector get_vals_from_map(map m) { vector vals; for(auto itr = m.begin(); itr != m.end(); ++itr) { vals.push_back(itr->second); } return vals; } void check(vector counts) { int max = 0; int rest = 0; int n = counts.size(); for(int i = 0; i < n; ++i) { int count = counts[i]; if (i < n - 1) { rest += count; } else { max += count; } } //cout << "max: " << max << endl; //cout << "rest:" << rest << endl; if ( max == rest || max == rest - 1 || max == rest + 1) { cout << "YES" << endl; return; } else if (max + 1 > rest) { cout << "NO" << endl; } else { counts.pop_back(); int n = counts.size(); //print_vector(counts); int i = n - 1; while(max > 0) { i = i % n; if (counts[i] > 0) { --counts[i]; --max; } --i; } //print_vector(counts); counts.erase(remove(counts.begin(), counts.end(), 0), counts.end()); sort(counts.begin(), counts.end()); //print_vector(counts); //cout << "--" << endl; check(counts); } } int main(){ int n; map etos; cin >> n; for (int i = 0; i < n; i++) { string eto; cin >> eto; ++etos[eto]; } //print_map(etos); vector counts = get_vals_from_map(etos); sort(counts.begin(), counts.end()); check(counts); return 0; }