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

const int mx = 500000;
bool v[mx];

int main() {
	int n;
	scanf("%d", &n);

	for (int i = 0; i < mx; i++)
		v[mx] = false;

	for (int i = 0; i < n; i++) {
		int a;
		scanf("%d", &a);

		while(v[a]) {
			v[a] = false;
			a++;
		}
		v[a] = true;
	}

	for (int i = mx - 1; i >= 0; i--)
		if (v[i]) {
			printf("%d\n", i);
			return 0;
		}
}