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

using namespace std;
#define MAX 500100

int buf[MAX], c[MAX];
int n,b;

bool cmp(int a, int b){
    if (c[a]== c[b]) return a < b;
    return c[a] < c[b];
}

int main() {
    scanf("%d", &n);
    for (int i=0;i<n;i++) {
        scanf("%d", &buf[i]);
        c[buf[i]]++;
    }
    sort(&buf[0], &buf[n], cmp);

    int r=0,last=-1;
    for(int i=0,j=n-1;i<=j;) {
        if(last != buf[j]) {
            last = buf[j];
            r++;
        } else {
            i++;
        }
        j--;
    }
    printf("%d\n", r);
}