# your code goes here D=int(input()) a=[int (i) for i in input (). split ()] while len(a)>3: a[2]+=a[0] a.pop(0) # print (a) print (len(a)-1) i=len(a)-1 b="" while i>=0: b+=str(a[i])+" " i-=1 if a[0]==0 and a[1]==0 and a[2]==0: b="0" print (b)