def exrem a, b
  _a = a.dup
  _b = b.dup
  _b.each do |p|
    idx = _a.index(p)
    _a.delete_at(idx)
  end
  _a
end
N = gets.chomp.to_i
a = []
max = 0
N.times do
  a << gets.chomp.to_i
end
a.each do |n|
  l = []
  l << n
  while l.length != N
    cnum = l.last
    # p a - l
    rem = exrem(a, l)
    ma = rem.max
    mi = rem.min
    # p rem
    if (ma-cnum).abs > (mi-cnum).abs
      l << ma
    else 
      l << mi
    end
  end
  t = 0
  l.each_with_index do |p, i|
    break if i == N-1
    t += (p - l[i+1]).abs
  end
  max = t if max < t
end
p max