1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
#include <iostream>
using namespace std;
int cnt[202000];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n, a, res = 0;
  cin >> n;
  while (n--) {
    cin >> a;
    cnt[a]++;
    res = max(res, a);
  }
  for (int i=0; i<=res; i++) {
    if (cnt[i] >= 2) res = max(res, i+1);
    cnt[i+1] += cnt[i] / 2;
  }
  cout << res << "\n";
  return 0;
}