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
#include <iostream>
using namespace std;
const int SIZE = 201718 * 3 + 10;
// const int SIZE = 10;
int n, tab[SIZE], tmp;
int main(){
	cin >> n;
	for(int i = 0; i < n; i++){
		cin >> tmp;
		tab[tmp]++;
	}

	tmp = 0;
	int result = 0;
	for(int i = 0; i < SIZE; i++){
		tab[i+1] += max(0, tab[i]) / 2;
		tab[i] = tab[i] % 2;
		if(tab[i] > 0){
			result = i;
		}
	}

	cout << result << endl;
	return 0;
}