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

using namespace std;

long long int tab[300000];

int main()
{
    ios_base::sync_with_stdio(0);
    int n;
    cin >> n;
    for( int i = 1; i <= n; i ++ )
    {
        int a;
        cin >> a;
        tab[a] ++;
    }
    long long int wyn = 0;
    for( long long int i = 1; i <= 300000; i ++ )
    {
        if( tab[i] > 0 ) wyn = max(wyn, i);
        long long int c = tab[i]/2;
        tab[i+1] += c;
    }
    cout << wyn << "\n";
    return 0;
}