#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  vector<int> arr(n);
  map<int, int> s;
  for (int i = (0); i < (n); i++) {
    cin >> arr[i];
    s[i] = arr[i];
  }
  auto cur = s.begin();
  auto prev = s.begin();
  cur++;
  while (cur != s.end()) {
    if (cur->second == prev->second) {
      s.erase(cur);
      cur = prev;
      cur->second = prev->second + 1;
      if (prev != s.begin()) {
        prev--;
      } else {
        cur++;
      }
    } else {
      cur++;
      prev++;
    }
  }
  cout << s.size() << '\n';
  for (auto& el : s) {
    cout << el.second << " ";
  }
  cout << '\n';
  return 0;
}
