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

using namespace std;

int n, a, result;
int tab[215000];

int main ()
{
	scanf("%d", &n);
	for (int i = 0; i < n; ++i)
	{
		scanf("%d", &a);
		tab[a]++;
	}
	for (int i = 0; i < 210000; ++i)
	{
		if (tab[i] > 0) result = i;
		tab[i + 1] += (tab[i] >> 1);
	}
	printf("%d\n", result);
	return 0;
}