module main;

import std.stdio;
import std.string;

int main(string[] argv)
{
	int n, j = 0; 
	scanf("%d", &n);
    int [] a = new int[n];
    for(int i = 0; i < n; i++) 
    { 
    scanf("%d", &a[j]);
    while(j > 0 && a[j] == a[j - 1]) 
    { 
        a[j - 1]++; 
         a[j] = 0; 
        j--; 
     }       
    j++; 
    } 
    writeln(j);
    for(int i = 0; i < j; i++) 
       write(a[i]," "); 

	return 0;
}