#include <bits/stdc++.h>
using namespace std;
long long A[300001];
int main() {
  long long n;
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> A[i];
  stack<long long> st;
  for (int i = 1; i <= n; i++) {
    long long x = A[i];
    while (!st.empty()) {
      if (st.top() == x) {
        x++;
        st.pop();
      } else
        break;
    }
    st.push(x);
  }
  vector<long long> ans;
  while (!st.empty()) {
    ans.push_back(st.top());
    st.pop();
  }
  n = ans.size();
  cout << n << endl;
  n--;
  for (int i = n; i >= 0; i--) cout << ans[i] << " ";
  printf("\n");
}
