#include <bits/stdc++.h>
using namespace std;
const int mxi = 2e5 + 7;
const int mod = 1e9 + 7;
long long n, b;
stack<long long> st;
vector<long long> v;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (long long i = 0; i < n; i++) {
    cin >> b;
    while (!st.empty() && st.top() == b) {
      st.pop();
      b++;
    }
    st.push(b);
  }
  while (!st.empty()) {
    v.push_back(st.top());
    st.pop();
  }
  reverse(v.begin(), v.end());
  cout << v.size() << "\n";
  for (long long i = 0; i < v.size(); i++) cout << v[i] << " ";
}
