#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n;
  cin >> n;
  long long a[n];
  stack<long long> st;
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (long long i = 0; i < n; i++) {
    if (st.size() && a[i] == st.top()) {
      long long x = a[i];
      while (!st.empty() && st.top() == x) {
        st.pop();
        x++;
      }
      st.push(x);
    } else {
      st.push(a[i]);
    }
  }
  vector<long long> ans;
  while (st.size()) {
    ans.push_back(st.top());
    st.pop();
  }
  reverse(ans.begin(), ans.end());
  cout << ans.size() << endl;
  for (long long x : ans) {
    cout << x << " ";
  }
  cout << endl;
}
