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
37
38
39
40
41
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;

namespace {

int solve(vector<int> const& data)
{
  int m = *max_element(data.begin(), data.end());
  vector<int> cnt(m + 1);
  for (int x: data) ++cnt[x];
  for (int i = 0; i < m; ++i) {
    cnt[i + 1] += cnt[i] / 2;
    cnt[i] %= 2;
  }
  while (cnt.back() >= 2) {
    int x = cnt.back() / 2;
    cnt.back() %= 2;
    cnt.push_back(x);
  }
  return cnt.size() - 1;
}

}

int main()
{
  iostream::sync_with_stdio(false);
  cin.tie(nullptr);

  int n;
  cin >> n;

  vector<int> data(n);
  for (auto& x: data) cin >> x;

  cout << solve(data) << endl;

  return 0;
}