def divide(poly, div, q) if poly.length < div.length return [q.reverse, poly] end c = poly[-1] / div[-1] q << c _poly = [] _div = div.clone while _div.length < poly.length _div.unshift(0) end poly.length.times{|d| _poly[d] = poly[d] - c * _div[d] } while _poly[-1] == 0 _poly.pop() end divide(_poly, div, q) end d = gets.to_i as = gets.strip.split.map{|e| e.to_i} div = [0, -1, 0, 1] q, r = divide(as, div, []) puts r.length if r.empty? puts 0 else puts r.join(' ') end