1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <bits/stdc++.h>
using namespace std;

const int nax = 3e5 + 5;
int cnt[nax];

int main() {
	int n;
	scanf("%d", &n);
	while(n--) {
		int x;
		scanf("%d", &x);
		++cnt[x];
	}
	int answer = 0;
	for(int i = 0; i < nax - 1; ++i)
		if(cnt[i]) {
			cnt[i+1] += cnt[i] / 2;
			answer = i;
		}
	printf("%d\n", answer);
}