#include <bits/stdc++.h>
using namespace std;
struct sss {
  long long id;
  long long next;
  friend bool operator<(struct sss x, struct sss y) {
    if (x.next == y.next) {
      return x.id > y.id;
    }
    return x.next > y.next;
  }
} a[200005];
long long n;
priority_queue<struct sss> q;
long long b[200005], c[200005];
int main() {
  long long n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    a[i].id = i;
    if (i != n)
      a[i].next = i + 1;
    else
      a[i].next = -1;
  }
  for (int i = 1; i <= n; i++) {
    cin >> b[i];
    q.push({i, b[i]});
  }
  long long num = 0;
  while (q.size() >= 2) {
    struct sss x, y;
    x = q.top();
    q.pop();
    y = q.top();
    q.pop();
    if (a[x.id].next == y.id && x.next == y.next) {
      x.next++;
      a[x.id].next = a[y.id].next;
      q.push(x);
      num++;
    } else {
      c[x.id] = x.next;
      q.push(y);
    }
  }
  if (!q.empty()) {
    struct sss x = q.top();
    q.pop();
    c[x.id] = x.next;
  }
  if (!q.empty()) {
    struct sss x = q.top();
    q.pop();
    c[x.id] = x.next;
  }
  cout << n - num << "\n";
  for (int i = 1; i <= n; i++) {
    if (c[i] != 0) {
      cout << c[i] << " ";
    }
  }
}
