D = int(input()) a = [int(i) for i in input().split()] for i in range(D,2,-1): a[i - 2] += a[i] a[i] = 0 ans = 0 for i in range(len(a)): if a[i] != 0: ans = i print(ans) print(' '.join([str(a[i]) for i in range(ans + 1)]))