1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <bits/stdc++.h>
using namespace std;
const int SIZ = 700001;
int ile [SIZ];

int main()
{
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    int val;
    for(int i=0;i<n;i++){
        cin >> val;
        ile[val]++;
    }
    int last = 0;
    for(int i=0;i<SIZ-1;i++){
        ile[i+1] += ile[i] / 2;
        if(ile[i] > 0)
            last = i;
    }
    cout<<last<<endl;
    return 0;
}