#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  list<int> elems;
  for (int i = 0; i < n; ++i) {
    int x;
    cin >> x;
    elems.push_back(x);
  }
  auto cur = elems.begin();
  while (cur != elems.end()) {
    bool found = false;
    if (cur != elems.begin() && !found) {
      auto prev = cur;
      prev--;
      if (*prev == *cur) {
        elems.erase(prev);
        *cur += 1;
        found = true;
      }
    }
    if (cur != elems.end() && !found) {
      auto next = cur;
      next++;
      if (*next == *cur) {
        elems.erase(next);
        *cur += 1;
        found = true;
      }
    }
    if (!found) {
      cur++;
    }
  }
  cout << elems.size() << '\n';
  for (auto it = elems.begin(); it != elems.end(); ++it) {
    std::cout << *it << ' ';
  }
}
