require 'pp' def divide(poly, div, q) 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 return [_poly, q] end d = gets.to_i poly = gets.strip.split.map{|e| e.to_i} div = [0, -1, 0, 1] q = [] while div.length <= poly.length poly, q = divide(poly, div, q) end if poly.empty? puts 0 puts 0 else puts (poly.length - 1) puts poly.join(' ') end