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

constexpr int kMaxPower = 201718 + 50; // 10^6 ~= 2^20, 50 to be safe

int n;
int digit[kMaxPower];

int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    int x;
    scanf("%d", &x);
    ++digit[x];
  }

  for (int d = 0; d < kMaxPower; ++d) {
    digit[d + 1] += digit[d] / 2;
    digit[d] %= 2;
  }

  for (int d = kMaxPower - 1; d >= 0; --d) {
    if (digit[d] > 0) {
      printf("%d\n", d);
      break;
    }
  }

  return 0;
}