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

using namespace std;

#define NMAX 1000000
#define AMAX 201718

int main()
{
    static unsigned cnt[AMAX+1];
    unsigned n, amax = 0, best;

    scanf("%u", &n);
    for (unsigned i = 0; i < n; ++i) {
        unsigned a;
        scanf("%u", &a);
        ++cnt[a];
        amax = max(amax, a);
    }

    for (unsigned a = 1; a <= amax; ++a) {
        cnt[a] += cnt[a-1]/2;
    }
    best = amax + (__builtin_clz(cnt[amax])^31);

    printf("%u\n", best);

    return 0;
}