import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines D,*A = map(int,read().split()) A[1] += sum(A[3::2]) A[2] += sum(A[4::2]) A = A[:3] while A and A[-1] == 0: A.pop() if not A: print(0) print(0) else: print(len(A) - 1) print(*A)