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
54
55
56
57
58
#include <cstdio>
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <stdlib.h>
#include <string.h>
#include <stdlib.h>
#include <list>
#include <algorithm>
#include <set>
#include <unordered_map>
#include <math.h>
#define FOR(x,y,z) for(int x = (y); x < (z); x++)
#define FORD(x,y,z) for(int x = (y); x >= z; x--)
#define REP(r,n) for(int r = 0; r < (n); r++)
#define MP make_pair
#define ST first
#define ND second
#define PB push_back
#define MAXUS 202000
#define PI 3.1415926
#define epsilon 0.000001
using namespace std;

typedef long long LL;
typedef long double LD;
typedef vector<int> VI;
typedef pair<int, int> PR;

#define SIZE(c) ((int)((c).size()))
#define FOREACH(i,x) for (__typeof((x).begin()) i=(x).begin(); i!=(x).end(); i++)
#define ALL(u) (u).begin(),(u).end()

using namespace std;

int main() {
    int n;
    cin >> n;
    int in[MAXUS];
    REP(i, MAXUS) in[i] = 0;
    REP(i,n) {
      int a;
      cin >> a;
      in[a]++;
    }
    int resultIndex = 0;
    REP(i, MAXUS-2) {
      int current = in[i] / 2;
      in[i+1] += current;
      if (in[i] % 2 == 1) {
        resultIndex = i;
      }
      
    }
    cout << resultIndex << endl;
    return 0;
}