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
37
38
39
40
41
42
43
44
45
46
//Autor: Karol Baryła
#include <bits/stdc++.h>
using namespace std;

#ifndef getchar_unlocked
#define getchar_unlocked getchar
#endif
#define MOD 1000000007

inline int read(){
    int x = 0;
    char c;
    bool m = false;
    while(true){
        c = getchar_unlocked();
        if(c == '-') m = true;
        if(c >= '0' && c <= '9') break;
    }
    while(true){
        x = x * 10 + c - '0';
        c = getchar_unlocked();
        if(c < '0' || c > '9') return m ? -x : x;
    }
}

int main(){
    int n = read();
    int* tab = new int[202719];
    int r = 0;
    for(int i = 0; i < n; i++){
        r = read();
        while(tab[r]){
            tab[r] = 0;
            r++;
        }
        tab[r] = 1;
    }
    for(int i = 202718; i >= 0; i--){
        if(tab[i]){
            printf("%d\n", i);
            return 0;
        }
    }
    printf("0\n");
    return 0;
}