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
#include<iostream>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
using namespace std;

#define ll long long
#define pn push_back

#define FOR(i, a, b) for(int i =(a); i <=(b); ++i)
#define REP(i, n) for(int i = 0;i <(n); ++i)

int A[1000000];
int B[1000000];
int main(){
    ios_base::sync_with_stdio(0);
    int n,a;
    cin>>n;
    REP(i,n)
        cin>>A[i];
    sort(A,A+n);
    B[0]=A[0];int b =1;
    FOR(i,1,n){
        if(B[b-1]==A[i]){
            B[b-1]=B[b-1]+1;
        }else if(B[b-1]<A[i]){
            B[b-1]=A[i];
            while(b>1 && B[b-1]==B[b-2]){
                B[b-2]=B[b-1]+1;
                b--;
            }
        }else if(B[b-1]>A[i]){
            B[b++]=A[i];
        }
    }
    int m = 0;
    REP(i,b)m=max(m,B[i]);
    cout<<m<<"\n";
    return 0;
}