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
#include <iostream>
using namespace std;

void add(long dummy, long * it,long * maxValue){
	
	if(*(it+dummy) != 1){
		*(it+dummy) =1;
		if(dummy>*maxValue){
			*maxValue = dummy;
		}
	}else{
		*(it+dummy) = 0;
		add(dummy+1,it,maxValue);
	}
	
}

int main(int argc, char** argv) {
	
	ios_base::sync_with_stdio(0);
	
	long N = 1;
	cin>>N;
	
	long mySet[201739];
	long * it;
	long maxV = 0;
	long * maxValue = &maxV;
	
	fill(mySet,mySet+N,0);
	
	long dummy;
	
	for(long i = 0;i<N;i++){
	it = mySet;
	cin>>dummy;
	add(dummy,it,maxValue);
	}
	

	cout<<*maxValue;
	
	return 0;
}