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;

bool t[250000];

int main(){
	int n,a,m=0;
	scanf("%d", &n);
	
	for(int i=0;i<n;i++){
		scanf("%d", &a);
		m=max(a,m);
		
		if(t[a]==true){
			while(t[a]==true){
				t[a]=false;
				a++;
				m=max(a,m);
			}
			t[a]=true;
			
		}else {
			t[a]=true;
		}
	}
	
	printf("%d\n", m);

}