let n = stdin.ReadLine() |> int
let h = stdin.ReadLine().Split() |> Array.map int64

Array.scan (fun (h1,c1,h2,c2) t -> (h2,c2,t,Array.min [|c1+(abs (t-h1));c2+(abs (t-h2))|])) (h.[0],0L,h.[1],(abs (h.[1]-h.[0]))) h.[2..n-1]
|> ((fun x -> x.[n-2]) >> (fun (_,_,_,c2) -> c2))
|> stdout.WriteLine