N = gets.to_i Y = gets.split.map(&:to_i).sort y_ = Y[N/2] puts Y.inject(0){|s, y| s + (y - y_).abs }