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

int main() {
	std::ios::sync_with_stdio(false); std::cin.tie(0);

	int total; std::cin >> total;
	std::vector<int> powers(total);

	for (int& x : powers) {
		std::cin >> x;
	}

	std::sort(powers.begin(), powers.end());
	int carry = 0, level = 0;

	for (int cur : powers) {
		while (carry > 0 && level < cur) {
			carry /= 2;
			level++;
		}

		level = cur;
		carry++;
	}

	while (carry > 1) {
		carry /= 2;
		level++;
	}

	std::cout << level << std::endl;
	return 0;
}