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
34
35
36
#include <cstdio>
#include <string>
using namespace std;

std::string total (250000, '0');
int theBest = 0;
void addBinary(size_t nominal) {
    
    if(total[nominal] == '0') {
    	total[nominal] = '1';
    } else {
    	while(total[nominal] == '1') {
            total[nominal] = '0';
            nominal++;    
    	}
    	total[nominal] = '1';
    }
    
    if(theBest < nominal) {
    	theBest = nominal;
    }
}



int main() {
    size_t n, nominal;
    
    scanf("%d", &n);
    for(size_t i = 0; i < n; i++) {
    	scanf("%d", &nominal);
    	addBinary(nominal);
    }
    printf("%d", theBest);
    return 0;
}