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
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main() {
  
  int N;
  cin >> N;
  
  constexpr int MAX_M = 300000;
  vector<int> d(MAX_M);
  
  while (N--) {
    int x;
    cin >> x;
    ++d[x];
  }
  
  int ans = 0;
  for (int i = 0; i < MAX_M-1; ++i) {
    if (d[i]) ans = i;
    d[i+1] += d[i]/2;
  }
  
  cout << ans << endl;
  
  return 0;
}