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 MAXN = 3e5;
int tab[MAXN];

int main() {
	int n;
	cin>>n;
	while (n--) {
		int x;
		cin >> x;
		tab[x]++;
	}
	int res = 0;
	for (int i = 1; i < MAXN ; i++) {
		tab[i] += tab[i-1] / 2;
		if (tab[i] > 0) res = i;
	}
	cout << res << endl;
	return 0;
}