1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <iostream>
using namespace std;

const int MaxA = 201718 + 30;
int tab [MaxA + 1];

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n; cin >> n;
    while ( n-- )
    {
        int p; cin >> p; ++tab[p];
    }
    for ( int i = 1; i <= MaxA; ++i )
        tab[i] += tab[i - 1] / 2;
    int res = 0;
    for ( int i = 0; i <= MaxA; ++i )
        if ( tab[i] ) res = i;
    cout << res << '\n';      
}