Ones

No attempts yetTime limit3sMemory limit512 MB

Problem

Let xx be a sequence of zeros and ones. An utterly forlorn one (UFO) in xx 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 1000101010001010 has two UFOs, the sequence 11010110001101011000 has no UFO, and the sequence 10001000 has exactly one UFO.

Let sks(n)sks(n) denote the total number of UFOs in the binary representations of the numbers from 11 to nn. For example, sks(5)=5sks(5)=5, sks(64)=59sks(64)=59, sks(128)=122sks(128)=122, and sks(256)=249sks(256)=249.

We will work with very large numbers, so we represent them succinctly. Let xx be a positive integer and let (x)2(x)_2 be its binary representation, which starts with 11. The succinct representation of xx is the sequence REP(x)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(460288) = REP(1110000011000000000_2) = (3, 5, 2, 9)

REP(408)=REP(1100110002)=(2,2,2,3)REP(408) = REP(110011000_2) = (2, 2, 2, 3)

Given REP(n)REP(n), compute the sequence REP(sks(n))REP(sks(n)).

Input

The first line contains one integer kk (1k1061 \le k \le 10^6), the length of the succinct representation of a positive integer nn. The second line contains kk integers x1,x2,,xkx_1, x_2, \ldots, x_k (0<xi1090 < x_i \le 10^9) separated by single spaces; this sequence is the succinct representation of nn. You may assume that x1+x2++xk109x_1 + x_2 + \cdots + x_k \le 10^9, that is 0<n<21090 < n < 2^{10^9}.

Output

Print two lines. The first line contains a single positive integer ll. The second line contains ll positive integers y1,y2,,yly_1, y_2, \ldots, y_l separated by single spaces, forming the succinct representation of sks(n)sks(n).