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<bits/stdc++.h>

using namespace std;

template<typename T> T load() { T x; cin >> x; return x; }
template<typename T> vector<T> loadN(int n) { vector<T> vt(n); for(auto& it : vt) it = load<T>(); return vt; }
template<typename T> ostream& operator<<(ostream& os, const vector<T>& vt) { for(auto& it : vt) os << it << ' '; return os; }

const int MaxCoin = 203000;
int coins[MaxCoin + 30];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    auto coinNum = load<int>();
    while(coinNum-->0)
        coins[load<int>()]++;
    
    auto answer = -42;
    for(int i = 0 ; i < MaxCoin ; ++i){
        coins[i + 1] += coins[i] / 2;
        if(coins[i] > 0)
            answer = i;
    }
    cout << answer << '\n';
    
}