D=int(input()) A=list(map(int,input().split())) for i in range(D-2): if A[i]!=0: A[i+2]+=A[i] A[i]=0 A=A[::-1] while len(A)>0 and A[-1]==0: A.pop() A=A[::-1] print(len(A)-1) if len(A)==0: print(0) else: print(*A)