class Calc0040 def initialize(args) args = args.map { |l| l.chomp.split(/\s+/) } @d = args.shift.first.to_i @as = args.shift.map(&:to_i) end def run as = @as.reverse until as.size <= 3 a = as.first as[0] -= a as[2] += a as = as.drop_while { |a| a == 0 } end if as.empty? [0, 0] else [as.size - 1, as.reverse.join(' ')] end end end puts Calc0040.new(STDIN.readlines).run if __FILE__ == $0