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
#include <cstdio>
#include <vector>

int main () {
	int n;
	scanf("%d", &n);
	std::vector<bool> d(false, 210000);
	int m = 0;
	for (int i = 0; i < n; ++i) {
		int x;
		scanf("%d", &x);
		while (true) {
			if (d[x]) {
				d[x] = false;
				++x;
			}
			else {
				d[x] = true;
				if (x > m) {
					m = x;
				}
				break;
			}
		}
	}
	printf("%d\n", m);
	return 0;
}