(* O(n) *)
let kInf = 1 lsl 60
let n = Scanf.scanf " %d" @@ (+) 0
let hs = Array.init n @@ fun _ -> Scanf.scanf " %d" @@ (+) 0
let dp = Array.make n kInf
let cost i j = abs @@ hs.(i) - hs.(j)
let _ =
  dp.(0) <- 0;
  for i = 0 to n - 2 do
    dp.(i + 1) <- min dp.(i + 1) @@ dp.(i) + cost i (i + 1);
    if i < n - 2 then dp.(i + 2) <- min dp.(i + 2) @@ dp.(i) + cost i (i + 2) done;
  Printf.printf "%d\n" dp.(n - 1)