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
#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
    int n;
    vector<int> tab;
    int p;
    int j;
    int sum;

    scanf("%d", &n);

    tab = vector<int>(n);

    for(int i = 0; i < n; ++i){
        scanf("%d", &tab[i]);
    }

    sort(tab.begin(), tab.end());

    p = tab[0];
    j = 0;
    sum = 0;
    while(j < n){
        while(p == tab[j]){
            sum++;
            j++;
        }
        p++;
        sum /= 2;
    }
    while(sum != 1){
        sum /= 2;
        p++;
    }

    printf("%d\n", p);

    return 0;
}