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
#include <iostream>
using namespace std;

#define MAX_INDEX 202000

int tab[MAX_INDEX];

void act(){
	for(int i=0; i<MAX_INDEX-1; i++){
		tab[i+1] += tab[i]/2;
		tab[i]%=2;
	}
}

int main(){
	for(int i=0; i<MAX_INDEX; i++){
		tab[i]=0;
	}
	int n;
	cin >> n;
	while(n--){
		int x;
		cin >> x;
		tab[x]++;
	}
	act();
	int i=MAX_INDEX-1;
	while(i>=0 && tab[i] == 0) i--;
	cout << i << "\n";
}