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
#include <iostream>
#include <cmath>
using namespace std;




int main() {


	int n, a;
	cin >> n;
	int max = 0;
	int min = 201720;
	double tab[201720] = {};
	int wynik = 0;
	for (int i = 0; i < n; i++)
	{
		cin >> a;
		tab[a]++;
		if (a > max)max = a;
		if (a < min)min = a;
	}
	for (int i = min; i <= max; i++)
	{
		if (tab[i] >= 2)
		{
			wynik = (int)(log2(tab[i]));
			tab[i] -= (wynik * 2);
			tab[i + wynik]++;
			if ((i + wynik) > max)max = i + wynik;
		}
		
	}

	cout << max;
	return 0;
}