1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <iostream>
using namespace std;
int a[201800],x,makx,m,n;
int main()
{	
	cin >> m;
	for(int i=0;i<m;i++)
	{
	cin >> x;
	a[x]++;
	if(x>makx)
	{
		makx=x;
	}
	}
	while((a[n]!=0)||(n<makx))
	{
	a[n+1]+=a[n]/2;	
	n++;
	}
	cout << n-1;
}