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
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
	int i, j, n, a;
	scanf("%d", &n);
	vector<int> num(202000, 0);
	for (i = 0; i < n; ++i) {
		scanf("%d", &a);
		num[a]++;
	}
	int ma = -1;
	for (i = 0; i < 202000; ++i) {
		if (num[i] > 0)
			ma = i;
		int new_num = i;
		while(num[i] > 1) {
			num[i] /= 2;
			new_num++;
		}
		num[new_num]++;
	}
	printf("%d", ma);
	return 0;
}