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
29
#include <vector>
#include <cstdio>
#define wied(i,a,b) for (int i=a;  i<b; i++)
#define debug //
using namespace std;
vector <int> tab; //tutaj zliczymy sobie wynik;
int n, m;
int main ()
{
	int x, suma=0;
	m=1e6;
	tab.resize(m, 0);
	scanf ("%d", &n);
	wied(i,0,n)
	{
		scanf ("%d", &x);
		tab[x]++;
	}
	x=0;
	while ((suma!=0) || (n!=0))
	{
		n-=tab[x];
		suma+=tab[x];
		tab[x]=suma%2;
		suma=suma>>1;
		x++;
	}
	printf ("%d\n", x-1);
}