1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
#include <iostream>

using namespace std;

#define MAX 1000000
int v[MAX],n,a,w = 0;

int main() {

    cin >> n;
    while(n--) {
	cin >> a;
	while(v[a]) v[a++] = 0;
	v[a] = 1;
	if(a>w) w = a;
    }
    cout << w << "\n";
    return 0;
}