n = read_line.to_i a = read_line.split.map(&.to_i).reverse (n - 2).times do |i| k = a[i] a[i] -= k a[i + 2] += k end a.reverse! if p = a.rindex {|i| i != 0 } a = a[0..p] else a = [0] end puts a.size - 1, a.join(' ')