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
30
31
32
33
#include <iostream>
#include <map>
using namespace std;
int main()
{
    ios_base::sync_with_stdio(0);
    map <long long, long long> mapa;
    long long a;
    cin >>a;
    long long b;
    for(long long i = 0; i<a; i++)
    {
        cin >> b;
        mapa[b]++;
    }
    long long c = 0;
    auto pocz = mapa.begin();
    long long d = pocz->first;
    auto kon = mapa.end();
    kon--;
    long long f = kon->first;
    //cout << d << " " << f << endl;
    for(; d<=f || c>0; )
    {

        c = (mapa[d]+c)/2;
        d++;
        //mapa[it->first] %= 2;
    }
    cout << d-1 << endl;

    return 0;
}