#include <iostream>
#include <algorithm>
#include <vector>
#include <cassert>
#include <chrono>
int main()
{
    //std::chrono::steady_clock::time_point begin = std::chrono::steady_clock::now();
    std::ios::sync_with_stdio(false);
    std::cin.tie(NULL);
    int numbersCount;
    std::cin >> numbersCount;
    std::vector<int> numbers;
    numbers.reserve(numbersCount);
    for (int i = 0; i < numbersCount; ++i)
    {
      int number;
      std::cin >> number;
      numbers.push_back(number);
    }
    //std::chrono::steady_clock::time_point begin = std::chrono::steady_clock::now();
    std::sort(numbers.begin(), numbers.end());
    std::vector<int> counts;
    int count = 1;
    for (int i = 1; i < numbers.size(); ++i)
    {
      if (numbers[i] == numbers[i-1])
        count++;
      else
      {
        counts.push_back(count);
        count = 1;
      }
    }
    counts.push_back(count);
    std::sort(counts.begin(), counts.end());
    std::reverse(counts.begin(), counts.end());
    int includedCount = 0;
    for (int i = 0; i < numbersCount; ++i)
    {
      includedCount += 2 * counts[i] - 1;
      if (includedCount >= numbersCount)
      {
        std::cout << (i+1) << "\n";
        //std::chrono::steady_clock::time_point end = std::chrono::steady_clock::now();
        //std::cout << "Time difference = " << std::chrono::duration_cast<std::chrono::milliseconds>(end - begin).count() << "[ms]" << std::endl;
        //std::cout << "AA\n";
        return 0;
      }
    }
    assert(false);
    return 0;
}
        1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54  | #include <iostream> #include <algorithm> #include <vector> #include <cassert> #include <chrono> int main() { //std::chrono::steady_clock::time_point begin = std::chrono::steady_clock::now(); std::ios::sync_with_stdio(false); std::cin.tie(NULL); int numbersCount; std::cin >> numbersCount; std::vector<int> numbers; numbers.reserve(numbersCount); for (int i = 0; i < numbersCount; ++i) { int number; std::cin >> number; numbers.push_back(number); } //std::chrono::steady_clock::time_point begin = std::chrono::steady_clock::now(); std::sort(numbers.begin(), numbers.end()); std::vector<int> counts; int count = 1; for (int i = 1; i < numbers.size(); ++i) { if (numbers[i] == numbers[i-1]) count++; else { counts.push_back(count); count = 1; } } counts.push_back(count); std::sort(counts.begin(), counts.end()); std::reverse(counts.begin(), counts.end()); int includedCount = 0; for (int i = 0; i < numbersCount; ++i) { includedCount += 2 * counts[i] - 1; if (includedCount >= numbersCount) { std::cout << (i+1) << "\n"; //std::chrono::steady_clock::time_point end = std::chrono::steady_clock::now(); //std::cout << "Time difference = " << std::chrono::duration_cast<std::chrono::milliseconds>(end - begin).count() << "[ms]" << std::endl; //std::cout << "AA\n"; return 0; } } assert(false); return 0; }  | 
            
        
                    English