1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
#include<bits/stdc++.h>
using namespace std;
int Count[300000];
int main(){
ios_base::sync_with_stdio(false);
int n;
cin>>n;
for(int i=0;i<n;i++){
    int a; cin>>a;
    Count[a]++;
}
for(int i=0;i<300000;i++){
    Count[i+1]+=Count[i]/2;
}
int id=299999;
while(Count[id]==0)id--;

cout<<id<<"\n";

return 0;
}