import sequtils,strutils var D = stdin.readline.parseInt A = stdin.readline.split.map(parseInt) for i in countdown(D,3): A[i - 2] += A[i] A[i] = 0 var D2 : int b = newSeq[int](0) for i in 0..2: if A[i] != 0: D2 = i for i in 0..D2: b.add(A[i]) echo D2 echo b.join(" ")