lib C fun strtoll(s : UInt8*, p : UInt8**, b : Int32) : Int64 end class String def to_i64 C.strtoll(self, nil, 10) end end n = read_line.to_i b = (1..n).map { read_line.to_i64 } a = Array.new(n + 1, 0i64) n.times { |i| a[i + 1] = i.even? ? b[i] - a[i] : a[i] - b[i] } need = (0..n).select { |i| i % 4 == 0 || i % 4 == 3 }.max_of { |i| {1i64 - a[i], 0i64}.max } can = (0..n).select { |i| i % 4 == 1 || i % 4 == 2 }.min_of { |i| {a[i] - 1i64, 0i64}.max } if need <= can (0..n).each do |i| if i % 4 == 0 || i % 4 == 3 a[i] += need else a[i] -= need end end puts n + 1, a.join("\n") else puts -1 end