n=gets.to_i
a=[]
n.times do
  a << gets.to_i
end
a.sort!
if n==2
  puts a[1]-a[0]
elsif n.odd?
  if a[n/2]-a[n/2+1]>a[n/2-1]-a[n/2]
    puts -2*a[0..n/2-1].sum+a[n/2..n/2+1].sum+2*a[n/2+2..n-1].sum
  else
    puts -2*a[0..n/2-2].sum-a[n/2-1..n/2].sum+2*a[n/2+1..n-1].sum
  end
else
  puts -2*a[0..n/2-2].sum-a[n/2-1]+a[n/2]+2*a[n/2+1..n-1].sum
end
