#include <bits/stdc++.h>
using namespace std;
vector<pair<long long, char> > adj[100];
vector<pair<bool, bool> > oddeven[100];
signed main() {
  cin.tie(0);
  cout.tie(0);
  ios_base::sync_with_stdio(false);
  long long n;
  cin >> n;
  long long arr[n + 1];
  for (long long i = 0; i < n; i++) cin >> arr[i + 1];
  vector<long long> stk;
  stk.push_back(0);
  for (long long i = 1; i <= n; i++) {
    stk.push_back(arr[i]);
    while (stk[stk.size() - 1] == stk[stk.size() - 2]) {
      long long a = stk[stk.size() - 1];
      stk.pop_back();
      stk.pop_back();
      stk.push_back(a + 1);
    }
  }
  cout << stk.size() - 1 << endl;
  for (long long i = 1; i < stk.size(); i += 1) cout << stk[i] << " ";
  return 0;
}
