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
#include <iostream>
using namespace std;
#define REP(x,n) for(int x=0;x<(n);++x)

const int MAX_M = 201720;
int cnt[MAX_M];

int main()
{
    ios_base::sync_with_stdio(0);
	int n,a;
	cin>>n;
	REP(x,n)
	{
		cin>>a;
		++cnt[a];
	}
	int wyn=0, sum=0;
	REP(x,MAX_M)
	{
		if(sum)
			wyn=x;
		sum=(sum>>1)+cnt[x];
	}
	while(sum)
	{
		sum>>=1;
		++wyn;
	}
	cout<<wyn-1;
	return 0;
}