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
//ANMHLIJKTJIY!
#pragma GCC optimize(2)
#pragma GCC optimize("Ofast")
#pragma GCC optimize("inline","fast-math","unroll-loops","no-stack-protector")
#pragma GCC diagnostic error "-fwhole-program"
#pragma GCC diagnostic error "-fcse-skip-blocks"
#pragma GCC diagnostic error "-funsafe-loop-optimizations"
#include <bits/stdc++.h>
#define INF 1000000000
#define LINF 1000000000000000000
#define MOD 1000000007
#define mod 998244353
#define F first
#define S second
#define ll int
#define N 500010
using namespace std;
ll n,a[N],cnt[N];
int main(){
	ll i;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%d",&a[i]);
		cnt[a[i]]++;
	}
	sort(cnt,cnt+n+1);
	reverse(cnt,cnt+n+1);
	ll sum=0;
	for(i=0;i<=n;i++)
	{
		sum+=cnt[i]+cnt[i]-1;
		if(sum>=n)
		{
			printf("%d\n",i+1);
			return 0;
		}
	}
	return 0;
}