Scanf.scanf "%d %d" (fun n k ->
    let x = Array.init n (fun _ -> Scanf.scanf " %d" (fun x -> x)) in

    let rec loop p acc =
        if p = n then acc else
            let s1 = x.(p - k + 1) in
            let s2 = x.(p) in
            let v1 = if s1 < 0 && s2 <= 0 then abs s1 else
                     if s1 >= 0 && s2 > 0 then s2 else
                         min (abs s1 * 2 + s2) (abs s1 + s2 * 2)
            in
            let acc = min acc v1 in
            loop (p + 1) acc
    in
    loop (k - 1) max_int |> Printf.printf "%d\n"
)