defmodule Main do

  def main do
    input()
    |> solve(%{})
    |> IO.puts()
  end

  def input do
    n = IO.gets("") |> String.trim() |> String.to_integer()
    h = IO.gets("")
        |> String.split()
        |> Stream.map(&String.to_integer/1)
        |> Stream.with_index()
        |> Enum.map(fn {k, v} -> {v, k} end)
        |> Map.new()
    {h, n-1}
  end

  def solve({_, 0}, _), do: 0
  def solve({h, i}, memo) when i >= 2 do
    case memo[i] do
      nil ->
        res = min(solve({h, i-1}, memo)+abs(h[i]-h[i-1]), solve({h, i-2}, memo)+abs(h[i]-h[i-2]))
        Map.put(memo, i, res)
        |> Map.get(i)
      res ->
        res
    end
  end
  def solve({h, i}, memo) do
    solve({h, i-1}, memo) + abs(h[i]-h[i-1])
  end

end
