#include <bits/stdc++.h>
using namespace std;
inline void readln(int &I) {
  I = 0;
  char C = getchar();
  while (!isdigit(C)) C = getchar();
  while (isdigit(C)) I = I * 10 + C - '0', C = getchar();
}
using namespace std;
int a[200005] = {-1, 0}, n, top, in;
int main() {
  readln(n);
  for (register int i = 1; i <= n; i++) {
    readln(in);
    while (in == a[top]) top--, in++;
    a[++top] = in;
  }
  printf("%d\n", top);
  for (register int i = 1; i <= top; i++) printf("%d ", a[i]);
}
