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
#include <algorithm>
#include <cstdint>
#include <iostream>
#include <vector>

int main() {
	std::ios::sync_with_stdio(false);
	unsigned int n;
	unsigned int maxM = 0;
	std::cin >> n;
	std::vector<uint8_t> num;
	for (unsigned int i = 0; i < n; ++i) {
		unsigned int k;
		std::cin >> k;
		while (k < num.size() && num[k] != 0) {
			num[k] = 0;
			++k;
		}
		if (k >= num.size()) {
			num.resize(k + 1, uint8_t(0));
		}
		num[k] = 1;
		maxM = std::max(k, maxM);
	}
	std::cout << maxM << "\n";
}