#include <bits/stdc++.h>
long long n, m, p;
long long a[1000005];
int main() {
  int s = 0;
  scanf("%lld", &n);
  for (int i = 1; i <= n; i++) {
    long long x;
    scanf("%lld", &x);
    while (s && a[s] == x) {
      s--;
      x++;
    }
    a[++s] = x;
  }
  printf("%d\n", s);
  for (int i = 1; i <= s; i++) printf("%lld ", a[i]);
  return 0;
}
