import std.stdio, std.bigint, std.string;

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