1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <iostream>
#include <vector>

const int LEN = 202000;

int main()
{
	std::ios::sync_with_stdio(0);
	std::cin.tie(NULL);
	int n, a, i;
	std::vector<int> arr(LEN);
	std::cin >> n;
	for (i = 0; i < n; ++i) {
		std::cin >> a;
		arr[a] += 1;
	}
	for (i = 0; i + 1 < LEN; ++i) {
		arr[i+1] += arr[i]/2;
	}
	for (i = LEN - 1; i >= 0 && !arr[i]; --i);
	std::cout << i;	
}