#include <bits/stdc++.h>
const int N = 100500 * 2;
int a[100500 * 2];
int prev[100500 * 2];
int b[100500 * 2];
int pos = 0;
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%d", &a[i]);
    prev[i] = i - 1;
  }
  for (int i = 1; i < n; ++i) {
    while (prev[i] != -1 && a[i] == a[prev[i]]) {
      ++a[i];
      a[prev[i]] = 0;
      prev[i] = prev[prev[i]];
    }
  }
  for (int i = 0; i < n; ++i) {
    if (a[i] != 0) {
      b[pos++] = a[i];
    }
  }
  printf("%d\n", pos);
  for (int i = 0; i < pos; ++i) {
    printf("%d ", b[i]);
  }
  return 0;
}
