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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include <iostream>
#include <vector>
#include <cstdlib>
#include <algorithm>
#include <cmath>

using namespace std;

typedef vector<int> vi;

#define VAR(i, x) typeof(x) i = x
//#define FOREACH(i, x) for(VAR(i, x.begin()); i!=x.end(); i++)
void Max(vi & v){
	for(auto it = v.begin(); it!=v.end();it++){
		auto next = it;
		next++;
		if(*it == *next && *it != 0){
			*it = *it+1;
			*next = 0;
			it++;
		}
		
	}
}
bool repeat(vi & v){
	for(auto it = v.begin(); it!=v.end(); it++){
		auto next = it;
		next++;
		if(*it == *next && *it != 0)
			return true;
	}
	return false;
}

int main(void){
	std::ios::sync_with_stdio(false);
	cin.tie(0);
	vi dane;
	int n, p;
	cin>>n;
	while(n--){
		cin>>p;
		dane.push_back(p);
	}
	sort(dane.begin(), dane.end());
	while(repeat(dane)){
	
		Max(dane);	
		sort(dane.begin(), dane.end());
	}
	cout<<dane.back()<<"\n";
	
}