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 <bits/stdc++.h>
using namespace std;

const int A = 1000 * 1000;

int cnt[A];

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

    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        cnt[a]++;
    }

    int res = 0;
    for (int i = 0; i < A; i++) {
        if (cnt[i]) {
            res = i;
            cnt[i + 1] += cnt[i] / 2;
        }
    }

    cout << res << "\n";
}