1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include<bits/stdc++.h>
#define endl '\n'
using namespace std;

int n, x, i[400010], ans;

int main()
{
	ios_base::sync_with_stdio( 0 );
	cin.tie( 0 );
	cin>>n;
	for( int a = 1; a <= n; a++ )
	{
		cin>>x;
		i[x]++;
	}	
	for( int a = 0; a <= 300000; a++ )
	{
		i[a+1] += i[a] / 2;
		if( i[a] )ans = a; 
	}
	cout<<ans<<endl;
	return 0;
}