#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int n;
  cin >> n;
  stack<int> s;
  for (int i = 0; i < n; ++i) {
    int a;
    cin >> a;
    if (s.size() == 0 || s.top() != a) {
      s.push(a);
    } else {
      while (s.size() > 0 && s.top() == a) {
        s.pop();
        ++a;
      }
      s.push(a);
    }
  }
  vector<int> a;
  while (!s.empty()) {
    a.push_back(s.top());
    s.pop();
  }
  cout << a.size() << "\n";
  for (int i = a.size() - 1; i >= 0; --i) {
    cout << a[i] << " ";
  }
  return 0;
}
