#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int stack[200100];
  int head = 0;
  for (int i = 0; i < n; i++) {
    scanf("%d", &stack[head++]);
    while (head > 1 && stack[head - 1] == stack[head - 2]) {
      stack[head - 2]++;
      head--;
    }
  }
  printf("%d\n", head);
  for (int i = 0; i < head; i++) {
    printf("%d ", stack[i]);
  }
}
