#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:16777216")
using namespace std;
const int inf = (int)1e9 + 5;
const long long INF = (long long)1e18 + 5;
void solve() {
  long long n;
  cin >> n;
  long long x;
  list<long long> a;
  for (long long i = 0; i < n; i++) {
    cin >> x;
    a.push_back(x);
  }
  auto it = a.begin();
  while (it != a.end()) {
    if (it != a.begin()) {
      auto it_prev = it;
      it_prev--;
      if (*it == *it_prev) {
        a.erase(it_prev);
        *it = *it + 1;
        continue;
      }
    }
    if (it != --a.end()) {
      auto it_next = it;
      it_next++;
      if (*it == *it_next) {
        a.erase(it_next);
        *it = *it + 1;
        continue;
      }
    }
    it++;
  }
  cout << a.size() << endl;
  it = a.begin();
  while (it != a.end()) {
    cout << *it << " ";
    it++;
  }
}
int main() {
  string filename = "acm";
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.precision(15);
  solve();
  (void)0;
  return 0;
}
