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
#include <map>
#include <iostream>
#include <string>
#include <sstream>

int main()
{
    auto count_string = std::string{};
    std::getline(std::cin, count_string);
    auto count = std::stoi(count_string);

    auto numbers = std::string{};
    std::getline(std::cin, numbers);
    std::istringstream intstream{numbers};

    auto map = std::map<long unsigned int, long unsigned int>{};
    for(int i = 0; i < count; ++i)
    {
        int next;
        intstream >> next;
        map[next] += 1;
    }

    for(const auto& kv : map)
    {
        auto key = kv.first;
        auto value = kv.second;

        int next = value / 2;
        if(next > 0)
            map[key+1] += next;
    }

    auto last_elem = *map.rbegin();
    std::cout << last_elem.first << std::endl;
}