gets b=gets.to_f as=gets.split.map(&:to_f) p as.map{|a|a*b**(a-1)}.inject :+ p as.map{|a|a==-1 ?Math.log(b):b**(a+1)/(a+1)}.inject :+