1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
int num[201720], res=0;
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n, x;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>x;
		num[x]++;
	}
	for(int i=0;i<201720;i++){
		if(num[i]>0) res=max(res, i);
		num[i+1]+=num[i]/2;
	}
	cout<<res<<endl;
	return 0;
}