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
30
31
32
33
34
35
36
37
38
39
40
41
// Piotr Golda
#include <iostream>
#include <vector>

using Container = std::vector < bool > ;
using size_type = Container::size_type;


size_type N;
const size_type SIZE{ 201718 + 20 + 2 };

Container V( SIZE, false );


int main()
{
	std::ios_base::sync_with_stdio(false);
	std::cin >> N;
	size_type value;
	for (size_type i = 0; i < N; ++i)
	{
		std::cin >> value;
		while (V[value])
		{
			V[value] = false;
			++value;
		}
		V[value] = true;
	}

	for (size_type i = SIZE - 1; i > 0; --i)
	{
		if (V[i])
		{
			std::cout << i << std::endl;
			break;
		}
	}

	return 0;
}