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

template <class T, class U>
bool remax(T &a, const U &b) { return b > a ? a = b, true : false; }

const int N = 202020;
bool T[N];
int mx = 0;

bool flip(int idx) {
	remax(mx, idx);
	return !(T[idx] ^= 1);
}

int main() {
	ios::sync_with_stdio(0);
	int n;
	cin >> n;
	while (n--) {
		int a;
		cin >> a;
		while (flip(a)) {
			++a;
		}
	}
	cout << mx << '\n';
}