let inline scan () = System.Console.ReadLine()
let inline split (s: string) = s.Split(' ')

let n = scan () |> int
let xs = scan () |> split |> List.ofArray |> List.map int

let noskip = 
  let x = xs |> List.fold (fun (budget, location) next -> (budget + abs (next - location), next)) (0, 0) |> fst
  x + abs (xs |> List.last)

let rec f = function
  | pred :: current :: next :: _ & _ :: tail ->
    noskip + abs (next - pred) - abs (current - pred) - abs (current - next)
      |> printfn "%i"
    f tail
  | pred :: current :: [] ->
    noskip + abs pred - abs (current - pred) - abs current
      |> printfn "%i"

f (0 :: xs)
