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
#include <bits/stdc++.h>
using namespace std;
const int MAXX = 250 * 1000;

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

    int n; cin >> n;
    vector<int> f(MAXX + 1, 0);

    for(int i = 0; i < n; ++i) {
        int x; cin >> x;
        f[x] += 1;
    }
    
    int ans = 0;

    for(int i = 0; i < MAXX; ++i) {
        f[i + 1] += (f[i] / 2);
        f[i] %= 2;
        if(f[i] > 0) {
            ans = i;
        }
    }

    cout << ans << "\n";
}