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

using namespace std;

const int SIZE = 500000;

int main(int argc, char const *argv[])
{
    int n;
    int c[SIZE] = {};
    int a;

    cin >> n;
    for (int i=0; i<n; i++) { 
        cin >> a;
        c[a-1]++;
    }

    sort(c, c + SIZE);

    int f = 0;
    int l = SIZE - 1;
    int result = 0;
    while (f < l && c[l] > 0) {
        int sub = min(c[f], c[l] - 1);
        c[f] -= sub;
        c[l] -= sub;
        if (c[f] == 0) {
            f++;
        }
        if (c[l] == 1 ) {
            l--;
            result++;
        }
    }

    if (c[l] > 0) {
        result++;
    }
    
    cout << result << endl;
    return 0;
}