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