def sum r
  s = 0
  r.each_cons(2) do |x1, x2|
    s += (x2 - x1).abs
  end
  s
end

def test input
  input_array = input.split.map(&:to_i).drop(1)
  s = []
  input_array.permutation do |r|
    s << sum(r)
  end
  puts s.max
end

test(ARGF.read)
