#include <bits/stdc++.h>
int main() {
  int ar[200005];
  int n, m, i, a, f;
  scanf("%d", &n);
  m = 0;
  while (n--) {
    scanf("%d", &a);
    f = 1;
    while (f) {
      if (m == 0)
        ar[m++] = a, f = 0;
      else {
        if (ar[m - 1] == a)
          m--, a++;
        else
          ar[m++] = a, f = 0;
      }
    }
  }
  printf("%d\n", m);
  for (i = 0; i < m; i++) printf("%d ", ar[i]);
  printf("\n");
}
