n = gets.to_i
seq = []
n.times { |i|
  seq[i] = gets.to_i
}
tmp = 0
max = 0

seq.permutation { |array|
  result = 0
  (array.length-1).times { |i|
    tmp = array[i+1] - array[i]
    result += tmp < 0 ? -tmp : tmp
  }
  max = result > max ? result : max
}
puts max
