gets class Nyan attr_accessor :e def initialize(h={1=> 1}) @e = h # 次数=>係数, return self end def *(z) y = self.clone h = {} z.e.each do |a| y.e.each do |b| d = a[0]+b[0] h[d] = h[d].to_i + a[1]*b[1] end end y.e = h return y end def +(z) y = self.clone z.e.each do |a| y.e[a[0]] = y.e[a[0]].to_i + a[1] end return y end end x = Nyan.new def d(w) h={} w.e.each do |d,k| h[d-1] = k*d if d>0 end r = Nyan.new r.e = h return r end m = gets.to_i str = gets.chomp str = str.gsub(/[0-9]+/,'Nyan.new(0=>\0)').gsub('{','(').gsub('}',')') ans = eval(str) puts (0..m).map{|e| ans.e[e].to_i}*" "