#include <bits/stdc++.h>
int main() {
  int n;
  scanf("%d", &n);
  long long a[2 * 100000 + 5];
  for (int i = 0; i < n; i++) scanf("%I64d", &a[i]);
  int left[2 * 100000 + 5], right[2 * 100000 + 5];
  for (int i = 0; i < n; i++) {
    left[i] = i - 1;
    right[i] = i + 1;
  }
  right[n - 1] = -1;
  for (int i = 0; i < n; i++) {
    int cur = i;
    while (left[cur] != -1 && a[left[cur]] == a[cur]) {
      int l = left[cur], r = right[cur];
      a[l]++;
      right[l] = r;
      left[r] = l;
      cur = l;
    }
  }
  int cnt = 0;
  for (int i = 0; i != -1;) {
    cnt++;
    i = right[i];
  }
  printf("%d\n", cnt);
  for (int i = 0; i != -1;) {
    printf("%I64d ", a[i]);
    i = right[i];
  }
  printf("\n");
}
