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
#include <bits/stdc++.h>
using namespace std;

const int N = 1000005;

#define REP(i, n) for (int i = 0; i < (n); ++i)

typedef long long ll;

int n, c[N];

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);

	cin >> n;
	REP(i, n) {
		int x;
		cin >> x;
		++c[x];
	}
	int result = 0;
	for (int i = 0; i < N - 1; ++i) {
		c[i + 1] += c[i] / 2;
		c[i] %= 2;
		if (c[i] > 0) result = i;
	}
	cout << result << '\n';

	return 0;
}