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
33
#include <iostream>
#include <algorithm>

using namespace std;

int main(){
	int n = 0;
	int *tab = new int[1000001];
	int r = 0;
	
	cin >> n;
	
	for(int i = 0; i < 1000001; i++){
		tab[i] = 0;
	}
	
	for(int i = 0; i < n; i++){
		int a;
		cin >> a;
		tab[a]++;
	}
	
	for(int i = 0; i < 1000001; i++){
		int a = tab[i] / 2;
		if(tab[i] > 0) r = i;
		tab[i] -= a*2;
		tab[i+1] += a;
	}
	
	
	cout << r;
	return 0;
}