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
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <cstdlib>

int buckets[500000];

int c, i, n;

#define SKIP_WHITESPACE \
{   \
    while (1) { \
        c = fgetc(stdin);   \
        if (c != ' ' && c != '\n' && c != '\r') \
            break;  \
    }   \
}   \

#define READ_INT    \
({   \
    SKIP_WHITESPACE \
    int ret = c - '0';  \
    while (1) { \
        c = fgetc(stdin);   \
        if (c < '0' || c > '9') \
            break;  \
        ret = ret * 10 + c - '0';   \
    }   \
    ret; \
})   \

int main(int argc, char* argv[]) {
    std::ios_base::sync_with_stdio (false);

    int r, s = 0, p = 0;
    n = READ_INT;

    for (i = 0; i < n; ++i) {
        r = READ_INT;
        buckets[r - 1]++;
    }

    std::make_heap(buckets, &buckets[n]);
    while (s < n) {
        std::pop_heap(buckets, &buckets[n - p]);
        s += 2 * buckets[n - p - 1] - 1;
        p++;
    }
    std::cout << p;
    return EXIT_SUCCESS;
}