#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<int> v(n);
  for (int i = 0; i < n; i++) cin >> v[i];
  stack<int> stk;
  for (int i = 0; i < n; i++) {
    if (!stk.empty() && stk.top() == v[i]) {
      int merged = v[i] + 1;
      stk.pop();
      while (!stk.empty() && stk.top() == merged) {
        stk.pop();
        ++merged;
      }
      stk.push(merged);
    } else {
      stk.push(v[i]);
    }
  }
  vector<int> seq;
  while (!stk.empty()) {
    seq.push_back(stk.top());
    stk.pop();
  }
  cout << seq.size() << endl;
  for (auto itr = seq.rbegin(); itr != seq.rend(); ++itr) {
    cout << *itr << " ";
  }
  cout << endl;
}
