1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
#include <cstdio>

const int maxN = 1e6 + 10;
int t[maxN];
int n, mx;

int main() {
    scanf("%d", &n);
    for(int a, i = 0; i < n; ++i) {
        scanf("%d", &a);
        t[a]++;
        mx = mx < a ? a : mx;
    }
    int i = -1;
    long long sum = 0;
    while(i < mx || sum) {
        i++;
        sum = sum / 2 + t[i];
    }
    printf("%d\n", i-1);
}