1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <cstdio>

const int MAX_N = 1000009;
const int MAX_A = 201718;
bool coins[MAX_A+30];

int main() {
  int n;
  scanf("%d", &n);
  int max = 0;
  for (int i = 0; i < n; ++i) {
    int c;
    scanf("%d", &c);
    while (coins[c]) {
      coins[c] = false;
      ++c;
    }
    coins[c] = true;
    if (c > max) {
      max = c;
    }  
  }
  printf("%d\n", max);
}