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
//PiOtR - Piotr Obst 1 LO Chełm
#include <iostream>
#include <map>
using namespace std;
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    map<long,long> mapa;
    long n,a,b;
    cin>>n;
    for(long i=0;i<n;i++){
        cin>>a;
        mapa[a]++;
    }
    for (pair<long, long> e : mapa)
		if(e.second>1){
            b=0;
            while(e.second>1){
                if(b&&mapa[e.first+b])
                    break;
                mapa[e.first+b]=e.second-e.second/2*2;
                b++;
                e.second/=2;
                mapa[e.first+b]+=e.second;
            }
		}
    cout<<(--mapa.end())->first;
    return 0;
}