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
82
#include <cstdio>

void swap(int &a, int &b)
{
    a = a + b;
    b = a - b;
    a = a - b;
}

void quick_sort(int tab[], int left, int right){
     int i=left;
     int j=right;
     int x=tab[(left+right)>>1];
     do{
         while(tab[i]<x) i++;
         while(tab[j]>x) j--;
         if(i<=j){                  
             int temp=tab[i];
             tab[i]=tab[j];
             tab[j]=temp;
             i++;
             j--;
         }
     }while(i<=j);
     if(left<j) quick_sort(tab,left,j);
     if(right>i) quick_sort(tab,i,right);     
}

int main()
{
    int n;
    scanf("%d", &n);
    int* l = new int[n];
    int* cl = new int[n];
    for (int i = 0; i < n; i++) {
        scanf("%d", &l[i]);
        cl[i] = 0;
    }
    
    for (int i = 0; i < n; i++) {
        cl[l[i] - 1]++;
    }
    
    quick_sort(cl,0,n-1);
    
    int j;
    int c = 0;
    while (true) {
        j = -1;
        
        for (int i = n - 1; i >= 0; i--) {
            if (cl[i] != 0) {
                if (i-1 < 0) {
                    c++;
                    j = -1;
                    break;
                } else if (cl[i-1] <= cl[i]){
                    j = i;
                    break;
                }
            }
        }

        if (j == -1) {
            printf("%d", c);
            return 0;
        }
        
        for (int i = 0, suma = 0; i < n; i++) {
            if (suma + cl[i] >= cl[j]) {
                if (cl[j] == cl[i]) {
                    cl[i] -= (cl[j] - (suma + 1));
                }
                break;
            }
            suma += cl[i];
            cl[i] = 0;
        }
        cl[j] = 0;
        c++;
    }
}