gets m=t=0 l=$<.map{|s|s.split.map &:to_i}.sort_by{|e|t+=v=e[2];-v} [*0...$_.to_i].permutation.map{|a|s=t;l.all?{|e|x,y,v=*e;a.index(y)m};m