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
#include <iostream>

const int SIZE = 1 << 18;
int values[SIZE];

int main() {
    std::ios_base::sync_with_stdio(false);

    int n;
    int r;
    std::cin >> n;
    while (n--) {
        std::cin >> r;
        ++values[r];
    }

    r = 0;
    for (int i = 1; i < SIZE; ++i) {
        values[i] += values[i - 1] / 2;
        r = (values[i] == 0 ? r : i);
    }

    std::cout << r << std::endl;

    return 0;
}