#include <bits/stdc++.h>
using namespace std;
int a[400005];
int l[400005];
int r[400005];
int del[400005];
set<int> s;
int main() {
  int n;
  cin >> n;
  for (int i = 1; i < n + 1; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < n + 1; i++) {
    l[i] = i - 1;
    r[i] = i + 1;
  }
  for (int i = 1; i < n + 1; i++) {
    if (a[i] == a[i + 1]) s.insert(i);
  }
  while (!s.empty()) {
    int id = *s.begin();
    s.erase(s.begin());
    int next = r[id];
    int prev = l[id];
    a[id] += 1;
    del[next] = 1;
    if (s.find(prev) != s.end()) {
      s.erase(prev);
    }
    if (s.find(next) != s.end()) {
      s.erase(next);
    }
    int new_next = r[next];
    r[id] = new_next;
    l[new_next] = id;
    if (a[new_next] == a[id]) {
      s.insert(id);
    }
    if (a[prev] == a[id]) {
      s.insert(prev);
    }
  }
  vector<int> ans;
  for (int i = 1; i < n + 1; i++) {
    if (!del[i]) ans.push_back(a[i]);
  }
  cout << ans.size() << '\n';
  for (auto x : ans) cout << x << " ";
  cout << '\n';
  ;
  return 0;
}
