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
#include <bits/stdc++.h>

using namespace std;

#define fru(j,n) for(int j=0; j<(n); ++j)
#define tr(it,v) for(auto it=(v).begin(); it!=(v).end(); ++it)
#define x first
#define y second
#define pb push_back
#define ALL(G) (G).begin(),(G).end()

#define DEBUG
#ifdef DEBUG
#define DEB printf
#else
#define DEB(...)
#endif

typedef double D;
typedef long long LL;
typedef pair<int,int> pii;
typedef vector<int> vi;

const int mod = 1000000007;
const int MAXN = 1000006;//10^6

int T[MAXN];

int main(){
	 int n;
	 scanf("%d",&n);
	 fru(i,n){
		  int a;
		  scanf("%d",&a);
		  T[a]++;
	 }
	 int ret=0;
	 fru(i,MAXN-1){
		  T[i+1]+=T[i]/2;
		  T[i]%=2;
	 }
	 fru(i,MAXN) if(T[i]) ret=i;
	 printf("%d\n",ret);

	 return 0;
}