#include <bits/stdc++.h>
using namespace std;
int n, i, a[200005], h;
vector<pair<int, int>> v;
int main() {
  cin >> n;
  h = n;
  for (i = 0; i < n; i++) {
    cin >> a[i];
    while (v.size() && a[i] == v[v.size() - 1].first) {
      a[v[v.size() - 1].second] = 0;
      v.pop_back();
      a[i]++;
      h--;
    }
    v.push_back(make_pair(a[i], i));
  }
  cout << h << "\n";
  for (i = 0; i < n; i++) {
    if (a[i]) cout << a[i] << " ";
  }
}
