#include <bits/stdc++.h>
using namespace std;
int n, cnt, a[200005], nxt[200005], pre[200005];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++)
    scanf("%d", &a[i]), nxt[i] = i + 1, pre[i] = i - 1;
  nxt[n] = -1;
  nxt[0] = 1;
  for (int i = 1; i != -1; i = nxt[i]) {
    while (nxt[i] != -1 && a[i] == a[nxt[i]]) {
      a[i]++;
      nxt[i] = nxt[nxt[i]];
      pre[nxt[i]] = i;
      cnt++;
      i = pre[i];
    }
  }
  printf("%d\n", n - cnt);
  for (int i = 1; i != -1; i = nxt[i]) printf("%d ", a[i]);
  return 0;
}
