module main;

import std;

void main()
{
	// 入力
	auto N = readln.chomp.to!int;
	auto poly = readln.split.to!(long[]).reverse;
	// 答えの計算と出力
	while (poly.length >= 4) {
		poly[2] += poly[0];
		poly[0] = 0;
		while (poly.length > 1 && poly[0] == 0) poly.popFront;
	}
	writeln(poly.length - 1);
	writefln("%(%d %)", poly.reverse);
}