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

#define MAX_A 202000

using namespace std;
int tab[MAX_A];

int main()
{
	int n,a;
	cin >> n;
	for(int i=0;i<n;++i)
	{
		cin >> a;
		tab[a]++;
	}
	int cur=0;
	int res = 0;
	for(int i=0;i<MAX_A || cur >0;++i)
	{
		if(i<MAX_A)
			cur+=tab[i];
		if(cur)res=i;
		cur/=2;
	}
	cout << res;
}