N = gets.to_i
A = N.times.map{gets.to_i}.sort
B = [A.shift]
(N-1).times{|i|
    x = i % 2 == 0 ? A.pop : A.shift
    if (B.last - x).abs < (B.first - x).abs then
        B.unshift x
    else
        B.push x
    end
}
ans = 0
(N - 1).times{|i|
    ans += (B[i] - B[i + 1]).abs
}
puts ans