gets e=gets.split.map &:to_i d=[0,-1,0,1] until d.size>e.size x=e[-1] d.size.times{|i|e[i+e.size-d.size]-=x/d[-1]*d[i]} e.pop end e.pop while e.size>1&&e[-1]==0 p e.size-1 puts e*' '