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


int main()
{
    std::ios_base::sync_with_stdio(0);

    int n = 0;
    std::set<int> s;

    std::cin >> n;

    for (int i = 0; i < n; i++)
    {
        int m = 0;
        std::cin >> m;

        while (s.find(m) != s.end()) {
            s.erase(m);
            m++;
        }

        s.insert(m);
    }

    printf("%d\n", *(s.rbegin()));
    return 0;
}