#include <bits/stdc++.h>
int main(int argc, const char* argv[]) {
  int n = 0, l = 1, sub = 0, r, pp;
  int value[200007], nex[200007], pre[200007];
  scanf("%d", &n);
  for (int i = 0; i <= n + 1; i++) {
    nex[i] = i + 1;
    pre[i] = i - 1;
  }
  for (int i = 1; i <= n; i++) scanf("%d", &value[i]);
  while (l <= n && value[l] != value[l + 1]) l++;
  if (l == n + 1) {
    printf("%d\n", n);
    for (int i = 1; i <= n; i++) printf("%d ", value[i]);
    printf("\n");
    return 0;
  }
  r = l;
  while (r != n + 1) {
    if (value[l] == value[pre[l]]) {
      pp = pre[pre[l]];
      nex[pp] = l;
      pre[l] = pp;
      value[l]++;
      sub++;
    } else if (value[l] == value[nex[l]]) {
      pp = nex[nex[l]];
      nex[l] = pp;
      pre[pp] = l;
      value[l]++;
      sub++;
    } else if (nex[l] == n + 1) {
      break;
    } else {
      while (nex[l] != n + 1 && value[l] != value[nex[l]]) {
        l = nex[l];
      }
    }
  }
  printf("%d\n", n - sub);
  l = nex[0];
  while (l != n + 1) {
    printf("%d ", value[l]);
    l = nex[l];
  }
  printf("\n");
  return 0;
}
