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
#include <cstdio>
#include <iostream>
#include <cmath>
#include <string>
#include <sstream>
using namespace std;

long array[1000000] = { 0 };
long current_max = 0;

int main() {
  long n;
  scanf("%ld\n", &n);
  for (long i=0; i<n; i++) {
    long x;
    scanf("%ld", &x);
    x--;
    //printf("x = %ld\n", x);
    while (array[x] == 1) {
      array[x] = 0;
      x++;
    }
    array[x] = 1;
    // for (long j=6; j>=0; j--) {
    //   printf("%ld", array[j]);
    // }
    // printf("\n");
    current_max = max(current_max, x);
  }
  printf("%ld\n", current_max + 1);
  return 0;
}