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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
//
//  main.cpp
//  Skarbonka
//
//  Created by Cezary Chodun on 11/20/17.
//  Copyright © 2017 CCH. All rights reserved.
//

#include <algorithm>
#include <iostream>
#include <vector>
#include <bitset>
#include <cmath>
#include <set>

using namespace std;
#define int2 pair<int, int>
#define mp make_pair
#define x first
#define y second



int main(int argc, const char * argv[]) {
    
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    
    set<int2> q;
    
    int n;
    cin >> n;
    
    for(int i = 0;  i < n; i++){
        int x;
        cin >> x;
        q.insert(mp(x, i));
    }
    
    int nid = n+4;
    
    int c = 0;
    int nom = 0;
    
    while(q.size() > 0){
        int2 x = *q.begin(); q.erase(q.begin());
        
        if(x.x == nom)
            c++;
        else{
            while(c > 0){
                int l = log2(c);
               // cout << nom+l << endl;
                if(l > 0)
                    q.insert(mp(nom+l, nid++));
                c -= (1<<l);
            }
            
            c = 1;
            nom = x.x;
        }
    }
    
    cout << nom+log2(c) << "\n";
    
    return 0;
}

/*
 5
 3 4 1 3 3
*/