#include <bits/stdc++.h>
int stack[233333], sp = 0;
int main() {
  int n;
  scanf("%d", &n);
  while (n--) {
    scanf("%d", &stack[sp++]);
    while (sp > 1 && stack[sp - 1] == stack[sp - 2]) ++stack[--sp - 1];
  }
  printf("%d\n", sp);
  for (int i = 0; i < sp; ++i) printf("%d ", stack[i]);
  puts("");
  return 0;
}
