#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t, i, j, n, m, l, r;
  cin >> n;
  int a[n];
  for (i = 0; i < n; i++) cin >> a[i];
  stack<int> s;
  for (i = 0; i < n;) {
    if (i + 1 < n && a[i] == a[i + 1]) {
      l = a[i] + 1;
      i += 2;
      while (i < n) {
        int f = 0;
        while (!s.empty() && s.top() == l) {
          l++;
          s.pop();
        }
        if (a[i] == l) l++, i++, f = 1;
        if (f == 0) break;
      }
      while (!s.empty() && s.top() == l) {
        l++;
        s.pop();
      }
      s.push(l);
    } else
      s.push(a[i++]);
  }
  cout << (int)s.size() << "\n";
  vector<int> v;
  while (!s.empty()) v.push_back(s.top()), s.pop();
  for (i = v.size() - 1; i >= 0; i--) cout << v[i] << " ";
  return 0;
}
