n = gets.to_i a = gets.split.map(&:to_i).sort puts a.map { |v| (v - a[n / 2]).abs } .reduce(:+)