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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>

using namespace std;

const int max_size = 500005;
const int max_n = 500000;

int n;
int t[max_size];

vector<int> v;

void print_t()
{
        for(int i = 1; i <= n; ++i) {
                printf("t[%d]=%d\n", i, t[i]);
        }
}

void print_vector()
{
    for (auto e : v) {
        printf(" %d", e);
    }
    printf("\n");
}

int calc_res()
{
        int res=1;
        int a = 0;
        int b = 0;

        while(b < max_n && v[b] != 0) {
                ++b;
        }
        --b;

        --v[a];
        while (a != b) {
                if (v[a] >= v[b]) {
                        v[a] -= v[b];
                        --b;
                        continue;
                }
                v[b] -= v[a];
                ++a;
                --v[a];
                ++res;
        }
        return res;
}

int main()
{
        int a;

        scanf("%d\n", &n);

	for(int i = 0; i < n; ++i) {
		scanf("%d", &a);
                t[a]++;
	}

//        print_t();

        for(int i = 1; i <= n; ++i) {
                if (t[i] != 0) {
                        v.push_back(t[i]);
                }
        }
        sort(v.begin(), v.end(), greater<int>());
  //      print_vector();

        printf("%d\n", calc_res());

        return 0;
}