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
#include<bits/stdc++.h>
#define PII pair<int,int>
#define f first
#define s second
#define VI vector<int>
#define LL long long
#define MP make_pair
#define LD long double
#define PB push_back
#define ALL(V) V.begin(),V.end()
#define abs(x) max((x),-(x))
#define PDD pair<LD,LD> 
#define VPII vector< PII > 
#define siz(V) ((int)V.size())
#define FOR(x, b, e)  for(int x=b;x<=(e);x++)
#define FORD(x, b, e) for(int x=b;x>=(e);x--)
#define REP(x, n)     for(int x=0;x<(n);x++)
#define mini(a,b) a=min(a,b)
#define maxi(a,b) a=max(a,b)
using namespace std;
const int MXN = 3e5;
int cnt[MXN];
int main()
    {
    int n;
    scanf("%d", &n);
    REP(i, n)
        {
        int a;
        scanf("%d", &a);
        cnt[a]++;
        }
    int res = 0;
    FOR(i, 0, MXN-2)
        {
        cnt[i+1] += cnt[i]/2;
        if(cnt[i])maxi(res, i);
        }
    printf("%d\n", res);
    }