#include <bits/stdc++.h>
using namespace std;
template <typename... Args>
void logger(string vars, Args&&... values) {
  cout << vars << " = ";
  string delim = "";
  (..., (cout << delim << values, delim = ", "));
  cout << '\n';
}
void solve() {
  long long int n;
  cin >> n;
  long long int a[n + 5];
  for (long long int i = 0; i < (n); i++) cin >> a[i];
  stack<long long int> s;
  for (long long int i = 0; i < (n); i++) {
    long long int cur = a[i];
    while (!s.empty() && s.top() == cur) {
      s.pop();
      cur++;
    }
    s.push(cur);
  }
  vector<long long int> v;
  while (!s.empty()) {
    v.push_back(s.top());
    s.pop();
  }
  reverse((v).begin(), (v).end());
  cout << ((long long int)v.size()) << '\n';
  for (long long int u = 0; u < (((long long int)v.size())); u++)
    cout << v[u] << " ";
  cout << '\n';
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ;
  long long int test = 1;
  while (test--) {
    solve();
  }
}
