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
#include <bits/stdc++.h>
using namespace std;

int tab[500001];

priority_queue<int> qi;

int main(){
    std::ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    for(int i = 1; i <= n; i++) cin >> tab[i];
    sort(tab+1, tab+n+1/*, [](int a, int b){
        return a > b;
    }*/);
    //for(int i = 1; i <= n; i++) cerr << tab[i] << ' ';
    int prev = -1;
    int lennow = 0;
    for(int i = 1; i <= n; i++){
        if(tab[i]==prev) {lennow++;}
        else {prev=tab[i]; qi.push(lennow); lennow=1;}
    }
    if(lennow)qi.push(lennow);
    int costnow = n;
    int wyn=0;
    //cerr << '\n';
    while(qi.top() != 0 and costnow>0){
        int b = qi.top();
        //cerr << b << ' ';
        int remvd = b + b-1;
        costnow-=remvd;
        wyn++;
        qi.pop();
    }
    //cerr << '\n';
    cout << wyn << '\n';
}