#include <bits/stdc++.h>
using namespace std;
stack<unsigned long long> q;
void foo(unsigned long long x) {
  while (!q.empty() && q.top() == x) {
    q.pop();
    x++;
  }
  q.push(x);
}
int main() {
  int n;
  cin >> n;
  while (n--) {
    unsigned long long x;
    cin >> x;
    foo(x);
  }
  int sz = q.size();
  vector<unsigned long long> v;
  while (!q.empty()) {
    v.push_back(q.top());
    q.pop();
  }
  cout << sz << "\n";
  for (int i = sz - 1; i >= 0; i--) {
    cout << v[i] << " ";
  }
  cout << "\n";
  return 0;
}
