n = gets.to_i
arr = gets.split(' ').map(&:to_i)

ds = []
n.times do |i|
  case
  when !arr[i+1]
    ds[i] = nil
  when !arr[i+2]
    ds[i] = (arr[i] - arr[i+1]).abs
  else
    ds[i] = [(arr[i] - arr[i+1]).abs, (arr[i] - arr[i+2]).abs]
  end
end

def cost(a_s)
  return 0 if a_s[0].nil?
  return a_s[0] if a_s[0].is_a?(Integer)
  [a_s[0][0] + cost(a_s[1..-1]), a_s[0][1] + cost(a_s[2..-1])].min
end

puts cost(ds)