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
/*Anita Śledź */
#include <bits/stdc++.h>
using namespace std;


const int N = 1000 * 1000 +  8;
const int limit = 300000;

int kubelek[limit];

int n, mini = N;


int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);

  cin >> n;
  for(int i = 0; i < n; i++){
    int pom;
    cin >> pom;
    kubelek[pom]++;
    mini = min(pom, mini);
  }
  int odp = 0;
  for(int i = mini; i <= 300000-10; i++){
    kubelek[i + 1] += kubelek[i]/2;
    // cout << "rozpatruje kubelek" << i << "ktory ma" << kubelek[i] << "\n";
    if(kubelek[i] != 0){
      odp = i;
    }
  }
  cout << odp << "\n";
  return 0;
}