N = gets.to_i
HEIGHTS = gets.split.map(&:to_i)
# $count = 0
$costs = Array.new(N) { nil }

def get_cost(num)
  # $count += 1

  if $costs[num]
    # メモ化済みの場合には何もしない
  elsif num == 0
    $costs[num] = 0
  elsif num == 1
    $costs[num] = (HEIGHTS[num] - HEIGHTS[num-1]).abs + get_cost(num-1)
  else
    $costs[num] = [
      (HEIGHTS[num] - HEIGHTS[num-1]).abs + get_cost(num-1),
      (HEIGHTS[num] - HEIGHTS[num-2]).abs + get_cost(num-2),
    ].min
  end
  $costs[num]
end

puts get_cost(N-1)
# puts "count: #{$count}"
