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 <cstdio>
#include <bitset>

const int N = 201800;

int main() {
    int n, v;
    std::bitset<N> bs;
    scanf("%d", &n);
    for (int i = 0; i < n; ++i) {
        scanf("%d", &v);

        bs.flip(v);
        while (!bs.test(v) && v < N) {
            ++v;
            bs.flip(v);
        }
    }


    for (int j = N - 1; j >= 0; --j) {
        if (bs.test(j)) {
            printf("%d\n", j);
            return 0;
        }
    }

}