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 <bits/stdc++.h>

using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define per(i, a, b) for (int i = (b) - 1; i <= (a); i--)

int n;
int cnt[210000];

int main(void)
{
	ios::sync_with_stdio(false);
	cin >> n;
	rep(i, 0, n) {
		int a;
		cin >> a;
		cnt[a]++;
	}

	int greatest = 0;
	rep(i, 0, 205000) {
		if (cnt[i])
			greatest = i;
		cnt[i + 1] += cnt[i] / 2;
	}

	cout << greatest << "\n";
}