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

const unsigned int range = 201718+20; 
unsigned int data[range] = {0};
int main()
{
	unsigned int count;
	std::cin >> count;

	for (unsigned int i = 0; i < count; ++i)
	{
		unsigned int next;
		std::cin >> next;
		++data[next];		
    }
    
    for (unsigned int i = 0; i < range-1; ++i)
    {
      data[i+1] += (data[i] >> 1);	
	}

	unsigned int result = range-1;
	while (data[result]==0)
	  --result;
	std::cout << result;  
	return 0;
}