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

using namespace std;

int main() {
	long n;
	cin >> n;
	long value;
	map<long, long> counter;
	for (long i = 0; i < n; i++) {
		cin >> value;
		if (counter.find(value) == counter.end()) {
			counter[value] = 1;
		} else {
			counter[value]++;
		}
	}
	for (auto it = counter.begin(); it != counter.end(); it++) {
		long power = it->first;
		long count = it->second;
		if (count > 1) {
			counter[power + 1] += count / 2;
		}
	}
	cout << counter.rbegin()->first << endl;
	return 0;
}