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
#include <stdio.h>

#define MAX_A 202000
int vals[MAX_A];

int inc(int i) {
    if (vals[i]) {
        vals[i] = 0;
        inc(i+1);
    } else {
        vals[i] = 1;
    }
}

int main() {
    int n;
    scanf("%d", &n);

    for (int i = 0; i < n; i++) {
        int a;
        scanf("%d", &a);

        inc(a);
    }

    int best = 0;
    for (int i = 0; i < MAX_A; i++) {
        if (vals[i]) {
            best = i;
        }
    }

    printf("%d\n", best);
}