Scanf.scanf "%d" (fun n ->
    let a = Array.init n (fun _ -> Scanf.scanf " %d" (fun a -> a)) in
    let b = Array.mapi (fun i v -> v - i - 1) a in
    Array.sort compare b;
    let q = b.(n / 2) in
    let rec loop i acc =
        if i = n then acc else loop (i + 1) (acc + abs (a.(i) - (q + i + 1)))
    in
    loop 0 0 |> Printf.printf "%d\n"
)