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 min_listi ls = 
	let rec f0 i l v vi = match l with
	| [] -> (v,i) | h::t -> if (h < v) then f0 (i+1) t h i else f0 (i+1) t v vi
	in f0 0 ls max_int (-1)

let () =
	let n = get_int ()
	in let a = input_int_array n
	in let a_cal b = Array.init n (fun i -> a.(i)-b-i-1)
	in let (m,mi) = min_listi (a|>Array.to_list)
	in
	let f = ref true
	in let b = ref m
	in let la = ref max_int
	in let a_res = a_cal !b
	in
	while !f do
		let r = Array.fold_left (fun u v -> u + abs v) 0 a_res
		in 
		(* Printf.printf "%d::%d\n" !b r; *)
		if r < !la then (
			la := r; b := !b - 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
