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

#define MAX_N	1000010
#define MAX_A	210748

int N, ai, b;
int a[MAX_A];

int main() {
	scanf("%d", &N);
	for (int i = 0; i < N; ++i) {
		scanf("%d", &ai);
		a[ai]++;
	}

	for (int i = 0; i < MAX_A - 1; ++i) {
		if (a[i] > 0) {
			b = i;
		}
		a[i + 1] += a[i] / 2;
	}

	printf("%d\n", b);
	return 0;
}