void main(){
  import std.stdio, std.string, std.conv, std.algorithm;

  int n; rd(n);
  auto x=readln.split.to!(int[]);
    int[200005] val,pre,nxt;
  for(int i=1;i<=n;i++) {
    val[i]=x[i-1];
    pre[i]=i-1;
    nxt[i]=i+1;
  } 
  nxt[0]=1;
  pre[n+1]=n;
  int cnt=n;
  for(int i=nxt[1];i<=n;i=nxt[i]) {
    while(val[i]==val[pre[i]]) {
        val[i]++;
        cnt--;
        nxt[pre[pre[i]]]=nxt[pre[i]];
        pre[nxt[pre[i]]]=pre[pre[i]];
    }
  }
  writeln(cnt);
  for(int i=nxt[0];i<=n;i=nxt[i])
    write(val[i]),write(' ');
}

void rd(T...)(ref T x){
  import std.stdio, std.string, std.conv;
  auto l=readln.split;
  assert(l.length==x.length);
  foreach(i, ref e; x){
    e=l[i].to!(typeof(e));
  }
}