#include <bits/stdc++.h>
using namespace std;
struct node {
  long long ai;
  node *nxt, *prev;
  node() {
    nxt = NULL;
    prev = NULL;
    ai = -1;
  }
};
int32_t main() {
  long long n;
  cin >> n;
  node *s = new node();
  node *it = s;
  for (long long i = 0; i < n; ++i) {
    long long ai;
    cin >> ai;
    it->ai = ai;
    if (i != n - 1) {
      node *nw = new node();
      nw->prev = it;
      it->nxt = nw;
      it = nw;
    }
  }
  it = s;
  while (it != NULL) {
    while (it != NULL) {
      if (it->prev != NULL && it->prev->ai == it->ai) {
        it = it->prev;
        break;
      }
      if (it->nxt != NULL && it->nxt->ai == it->ai) break;
      it = it->nxt;
    }
    if (it == NULL) break;
    assert(it->nxt->ai == it->ai);
    it->nxt = it->nxt->nxt;
    if (it->nxt != NULL) it->nxt->prev = it;
    it->ai = it->ai + 1;
    n--;
  }
  cout << n << '\n';
  it = s;
  while (it != NULL) {
    printf("%lld ", it->ai);
    it = it->nxt;
  }
  printf("\n");
}
