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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define INT(x) int x; scanf("%d", &x)

int a[1000000];

int main() {
	INT(n);
	REP(i,n) scanf("%d", &a[i]);
	sort(a, a + n);
	int b = 0, s = 0;
	REP(i,n) {
		while (b < a[i]) {
			s >>= 1;
			++b;
		}
		++s;
	}
	while (s > 1) {
		s >>= 1;
		++b;
	}
	printf("%d\n", b);
}