#!/usr/bin/env python3 #fileencoding: utf-8 D = int(input()) a = [int(i) for i in input().strip().split(" ")] a.reverse() for i in range(D-2): a[i+2] += a[i] a[i] = 0 a.reverse() D = 0 lastzero = 0 for i in range(len(a)): if D == 0 and a[i] != 0: D = i+1 if a[i] != 0: lastzero = i print(D) if D == 0: print(0) else: for i in range(lastzero+1): print(a[i], end=" ") print()