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
#include <cstdio>
#include <map>
#include <cstdlib>


int main(){
	int n;
	std::map<long long,int> powers;
	int dummy;
	
	scanf ("%d", &n);

	for (int i = 0; i < n; i++) {
		scanf ("%d", &dummy);
		auto emplace_pair = powers.emplace(dummy, 0);
		emplace_pair.first->second += 1;
	}

	for (auto it = powers.begin(); it != powers.end(); ++it){
		int result = it->second / 2;
		if (result > 0) {
			auto emplace_pair = powers.emplace(it->first + 1, 0);
			emplace_pair.first->second += result;
			it->second = 0;
		}
	}

	printf("%lld\n", powers.rbegin()->first);

	return 0;
}