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
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>

using namespace std;

const int limit = 203718;
long long pows[limit+5];

int main() {
  memset(pows, 0, sizeof(pows));
  int n;
  
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    int tmp;
    scanf("%d", &tmp);
    pows[tmp]++;
  }

  for (int i = 0; i <= limit; ++i) {
    long long move = pows[i]/2LL;
    pows[i+1] += move;
    pows[i] -= 2LL*move;
  }

  int maxx = -1;
  for (int i = 0; i <= limit; ++i) {
    if (pows[i])
      maxx = i;
  }
  printf("%d\n", maxx);

  return 0;
}