x = gets.to_i
m = x.times.map{gets.to_i}
k = m.sort
l = m.sort.reverse
s = []
j = []
for i in 0..x/2-1
s << l[i]
s << k[i]
end
if x.odd?
    s << k[x/2+1]
end
for i in 1..x-1
 j << (s[i]-s[i-1]).abs
 end
 puts j.inject(:+)