#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  scanf("%d", &n);
  int v[n + 69], k = 0;
  for (int i = 0; i < n; ++i) {
    int x;
    scanf("%d", &x);
    while (x == v[k]) --k, ++x;
    ++k;
    v[k] = x;
  }
  printf("%d\n", k);
  for (int i = 1; i <= k; ++i) printf("%d ", v[i]);
  printf("\n");
  return 0;
}
