let input_int_array n =
	Array.init n (fun _ -> Scanf.scanf "%d " (fun v -> v))
let get_int () = Scanf.scanf "%d " (fun v -> v)

(* let test a b =
  Array.fold_left (fun (u,i) v -> 
    (* Printf.printf "  %d::abs(%d-(%d+%d))=%d\n"
      i v b i (abs (v-(b+i)))
    ; *)
    (u + (abs (v - (b+i)))), i+1) (0,1) a
  |> fst *)

let () =
  let n = get_int ()
  in let a = input_int_array n
  in let lmax = a |> Array.to_list |> List.fold_left max min_int
  in let a_res = Array.init n (fun i -> a.(i) - lmax - i)
  in let b_lmax = ref 0 in let f = ref true
  in let la = ref max_int
  in while !f do
    let r = Array.fold_left (fun u v -> u + abs v) 0 a_res
    in
    (* Printf.printf "%d::%d\n" (lmax + !b_lmax) r; *)
    if r < !la then (
      la := r; b_lmax := !b_lmax - 1;
      for i=0 to Array.length a - 1 do
        a_res.(i) <- a_res.(i) + 1
      done
    ) else (
      f := false
    )
  done;
  !la |> string_of_int |> print_endline