1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <stdio.h>

const int M = 201718;
static int MAX;
static int t[M+30];

int main() {
	int n,a,i,p;

	scanf("%d", &n);

	for (i=1; i<=n; i++) {
		scanf("%d", &a);
		if (a>MAX) MAX = a;
		t[a]++;
	}

	for (i=0; i<MAX+25; i++) {
		t[i+1] += t[i]/2;
		if (t[i]>0) p = i;
	}
	printf("%d\n", p);
	return 0;
}