#include <bits/stdc++.h>
#pragma GCC optimize(2)
using namespace std;
const int N = 2e5 + 50;
const int inf = 0x3f3f3f3f;
stack<long long> st;
int main() {
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    long long s;
    cin >> s;
    while (!st.empty() && s == st.top()) {
      st.pop();
      s++;
    }
    st.push(s);
  }
  cout << st.size() << endl;
  vector<long long> v;
  while (!st.empty()) {
    v.push_back(st.top());
    st.pop();
  }
  reverse(v.begin(), v.end());
  for (auto i : v) cout << i << ' ';
  cout << endl;
  return 0;
}
