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
#include <iostream>
#include <vector>

using namespace std;

int main(){
    // Input variables
    int n;
    vector<int> a;
    // Output variables
    vector<bool> o(201738, 0);
    int out = 0;
    // Temp variables
    int i,j;
    int temp;
    // IN:
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>temp;
        a.push_back(temp);
    }
    // ALG:
    for(i=0;i<n;i++){
        for (j = a[i]; o[j]==1; j++)o[j] = 0;
        o[j] = 1;
        if (j > out) out = j;
    }
    // OUT:
    cout<<out<<endl;
    return 0;
}