#include <bits/stdc++.h>
using namespace std;
int arr[1000000];
int main() {
  int n;
  cin >> n;
  set<int> si;
  set<int, greater<int> > si1;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
    si.insert(i);
    si1.insert(i);
  }
  for (int i = 0; si.upper_bound(i) != si.end(); i = *si.upper_bound(i)) {
    if (si.upper_bound(i) != si.end() && si.find(i) != si.end()) {
      int yo = *si.upper_bound(i);
      while (arr[i] == arr[yo]) {
        arr[i]++;
        arr[yo] = -1;
        si.erase(yo);
        si1.erase(yo);
        if (si1.upper_bound(i) != si1.end()) {
          yo = i;
          i = *si1.upper_bound(i);
        } else {
          i = -1;
          break;
        }
      }
    }
  }
  vector<int> vi;
  for (int i = 0; i < n; i++)
    if (arr[i] != -1) vi.push_back(arr[i]);
  cout << vi.size() << '\n';
  for (int i = 0; i < vi.size(); i++) cout << vi[i] << " ";
  return 0;
}
