1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
#include <iostream>
int tab[1000100],n,a,wyn;
int main()
{
	std::ios_base::sync_with_stdio(0);
	std::cin >> n;
	for (int i=1; i<=n; ++i) std::cin>>a,tab[a]++;
	for (int i=0; i<=1000000; ++i){
		if (tab[i]) wyn = i;
		tab[i + 1] += tab[i] / 2;
	}
	std::cout << wyn;
}