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
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <set>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <cmath>
#include <bitset>
#include <fstream>
using namespace std;

#define pi pair<int,int>
#define mp(x,y) make_pair(x,y)
#define fi first
#define se second
#define pl pair<long long,long long>
#define pb push_back
#define vi vector<int>
#define ll long long

const int MAXN=1e6+5, mod=1e9+7;
int t[MAXN];

int main ()
{
    int a,b,c,d,e,f,g,z,k,n;

    scanf("%d", &n);

    while (n--)
    {
        scanf("%d", &a);
        t[a]++;
    }

    b=0;

    for (a=0; a<MAXN; a++)
        if (t[a])
        {
            b=a;
            t[a+1]+=t[a]/2;
        }

    printf("%d", b);

    return 0;
}