n = gets.to_i
a = []
n.times { a << gets.to_i }
score = 0
more = a.sort.reverse
less = a.sort
ans = []
i = 0
op_more = 0 # 0のとき左から
op_less = 0 # 0のとき左から
while i < n
  if i % 2 == 0
    if op_less == 0
      ans.unshift(less.shift)
    else
      ans.push(less.shift)
    end
    op_less = 1 - op_less
  else
    if op_more == 1
      ans.unshift(more.shift)
    else
      ans.push(more.shift)
    end
    op_more = 1 - op_more
  end
  i += 1
end

score = [score, ans.each_cons(2).map { |(x, y)| (x - y).abs }.inject(:+)].max

ans = []
i = 0
more = a.sort.reverse
less = a.sort
op_more = 0 # 0のとき左から
op_less = 0 # 0のとき左から
while i < n
  if i == n - 1
    ans.push(more.shift)
  elsif i % 2 == 0
    if op_less == 0
      ans.unshift(less.shift)
    else
      ans.push(less.shift)
    end
    op_less = 1 - op_less
  else
    if op_more == 1
      ans.unshift(more.shift)
    else
      ans.push(more.shift)
    end
    op_more = 1 - op_more
  end
  i += 1
end
score = [score, ans.each_cons(2).map { |(x, y)| (x - y).abs }.inject(:+)].max

ans = []
i = 0
op_more = 0 # 0のとき左から
op_less = 0 # 0のとき左から
more = a.sort.reverse
less = a.sort
while i < n
  if i == n - 1
    ans.unshift(more.shift)
  elsif i % 2 == 0
    if op_less == 0
      ans.unshift(less.shift)
    else
      ans.push(less.shift)
    end
    op_less = 1 - op_less
  else
    if op_more == 1
      ans.unshift(more.shift)
    else
      ans.push(more.shift)
    end
    op_more = 1 - op_more
  end
  i += 1
end
score = [score, ans.each_cons(2).map { |(x, y)| (x - y).abs }.inject(:+)].max

p score