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
32
33
#include <iostream>
#include <cmath>
#include <vector>
using namespace std;
vector<bool> money;
int maxBit = 0;
void storeBucks(int i) {
	if (money[i]) {
		do {
			money[i] = false;
		} while(money[++i]);
		money[i] = true;
	} else {
		money[i] = true;
	}
	if (maxBit < i) {
		maxBit = i;
	}
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	unsigned n, k;
	cin >> n;
	money.resize(201718 + 21);
	for (unsigned i = 0; i < n; ++i) {
		cin >> k;
		storeBucks(k);
	}
	cout << maxBit << '\n';
	return 0;
}