n=gets.to_i a=gets.split.map &:to_i n=d=9e9 a.sort_by!(&:abs) a.map{|x| t=a.reduce(0){|s,y|s+y-x}.abs if t<=d d=t n=x else break end } p a.reduce(0){|s,y|s+(y-n).abs}