#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n;
  cin >> n;
  long long a[n + 1];
  for (long long i = 1; i <= n; i++) {
    cin >> a[i];
  }
  stack<long long> s;
  for (long long i = 1; i <= n; i++) {
    long long y = a[i];
    while (!s.empty() and s.top() == y) {
      s.pop();
      y++;
    }
    s.push(y);
  }
  vector<long long> ans;
  while (!s.empty()) {
    ans.push_back(s.top());
    s.pop();
  }
  reverse(ans.begin(), ans.end());
  cout << ans.size() << "\n";
  for (long long i : ans) cout << i << " ";
  cout << "\n";
}
