Let x be a sequence of zeros and ones. An utterly forlorn one (UFO) in x is an extreme one (either the first or the last one in the sequence) that additionally does not neighbour any other one. For example, the sequence 10001010 has two UFOs, the sequence 1101011000 has no UFO, and the sequence 1000 has exactly one UFO.
Let sks(n) denote the total number of UFOs in the binary representations of the numbers from 1 to n. For example, sks(5)=5, sks(64)=59, sks(128)=122, and sks(256)=249.
We will work with very large numbers, so we represent them succinctly. Let x be a positive integer and let (x)2 be its binary representation, which starts with 1. The succinct representation of x is the sequence REP(x) of positive integers giving the lengths of the successive maximal blocks of equal digits. For example:
REP(460288)=REP(11100000110000000002)=(3,5,2,9)
REP(408)=REP(1100110002)=(2,2,2,3)
Given REP(n), compute the sequence REP(sks(n)).
The first line contains one integer k (1≤k≤106), the length of the succinct representation of a positive integer n. The second line contains k integers x1,x2,…,xk (0<xi≤109) separated by single spaces; this sequence is the succinct representation of n. You may assume that x1+x2+⋯+xk≤109, that is 0<n<2109.
Print two lines. The first line contains a single positive integer l. The second line contains l positive integers y1,y2,…,yl separated by single spaces, forming the succinct representation of sks(n).