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
#include <iostream>
#include <algorithm>
using namespace std;

const int N = 250000;

int ile[N + 7];
int n;

int main() {
    ios_base::sync_with_stdio(0);
    cin >> n;
    for(int i = 1; i <= n; ++i) {
        int x;
        cin >> x;
        ile[x]++;
    }
    
    int wyn = 0;
    
    for(int i = 0; i <= N; ++i) {
        int dod = ile[i] / 2;
        ile[i] %= 2;   
        ile[i + 1] += dod;
        if(ile[i] > 0) wyn = i;
    }
    cout << wyn << endl;
    return 0;
}