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
#include <algorithm>
#include <cstdio>
#include <vector>

using namespace std;

struct exponent_counter {
  int exponent;
  int counter;
  exponent_counter(int exponent, int counter)
    : exponent(exponent), counter(counter) {}
};

int main() {
  vector<int> exponents;
  int n;
  scanf("%d", &n);
  while (n--) {
    int a;
    scanf("%d", &a);
    exponents.push_back(a);
  }
  sort(exponents.begin(), exponents.end());
  exponent_counter ec(-1, 0);
  for (int expo : exponents) {
    while (ec.exponent < expo) {
      ec.exponent++;
      ec.counter /= 2;
    }
    ec.counter++;
  }
  while (ec.counter > 1) {
    ec.exponent++;
    ec.counter /= 2;
  }
  printf("%d\n", ec.exponent);
  return 0;
}