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

using namespace std;

int main() {
    const int tab_size = 201738;
    short tab [tab_size];
    int n, i, tmp, max = 0;
    for (i=0; i<tab_size; i++)
        tab[i] = 0;

    cin >> n;
    for (i=0; i<n; i++) {
        cin >> tmp;
        tab[tmp]++;
        while (tab[tmp] == 2) {
            tab[tmp] = 0;
            tab[tmp+1] += 1;
            tmp++;
        }
        if (tmp > max)
            max = tmp;
    }

    cout << max << endl;
}