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

using namespace std;

const int N = 201750;

int main() {
	int n, x;
	int t[N];
	fill(t, t+N, 0);
	cin >> n;
	for(int i = 0; i < n; i++) {
		cin >> x;
		t[x]++;
	}
	
	for(int i = 0; i < N; i++) {
		t[i+1] += (t[i]>>1);
		t[i]%=2;
		if(t[i] == 1)
			x = i;
	}

	cout << x << endl;

	return 0;
}