n=gets.to_i a=gets.split.map &:to_i d=10**99 p a.sort_by!(&:abs).map{|x|a.reduce(0){|s,y|s+(y-x).abs}}.min