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
83
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;

int tab[500001];

pair<int, int> v[500001];

int main()
{
  int n;
  scanf("%d", &n);
  
  memset(tab,0,sizeof(tab));
  for (int i = 0; i < n; i++)
  {
    int a;
    scanf("%d", &a);
    tab[a]++;
  }
  
  int c = 0;
  for (int i = 1; i <= n; i++)
  {
    if (tab[i])
    {
      v[c].first = tab[i];
      v[c].second = i;
      c++;
    }
  }
  
  sort(v, v + c, [](pair<int, int> a, pair<int, int> b) {return a.first > b.first;});
  
 
//  printf("ddd %d", c);
  for (int i = 0; i < c; i++)
  {
  //  printf("%d %d\n", v[i].first, v[i].second);
  }
  
  int k = 0;
  for (int i = 0; i < c; i++)
  {
    for (int j = 0; j < v[i].first; j++)
    {
//      tab[k] = v[i].second;
//      k++;
    }
  }
  int l = 0;
  
  int r = n - 1;
  
  
  int ret = 0;
  for (int i = 0; i < c; i++)
  {
    if (v[i].first >= 2)
    {
      l += v[i].first;
      r -= (v[i].first - 1);
      ret++;
      if (r < l)
      {
        break;
      }
    }
    else
    {
      ret += r - l + 1;
      break;
    }
  }
  
  printf("%d\n", ret);
  
  
  
  
  return 0;
}