# -*- coding: utf-8 -*- D = int(input()) a = list(map(int, input().split())) for i in range(D, 2, -1): q = a[i] e = i - 3 a[e+1] += q d = min(2, D) for i in range(d, -1, -1): d = i if a[i] != 0: break print(d) for i in range(d+1): if i==0: print(str(a[i]), end='') else: print(' '+str(a[i]), end='') print()