#include <bits/stdc++.h>
using namespace std;
int main(int argc, char *argv[]) {
  list<long long> data;
  long long n, temp;
  cin >> n;
  for (long long i = 0; i < n; i++) {
    cin >> temp;
    data.push_back(temp);
  }
  for (auto i = data.begin(); i != data.end();) {
    auto j = i;
    j++;
    if (j != data.end()) {
      if (*i == *(j)) {
        data.erase(j);
        *i = *i + 1;
        n--;
        if (i != data.begin()) {
          i--;
        }
      } else {
        i++;
      }
    } else {
      i++;
    }
  }
  cout << n << endl;
  for (auto i = data.begin(); i != data.end(); i++) {
    cout << *i << ' ';
  }
}
