(*
 * forall l r (p : forall n, l < n <= r -> bool),
 *   ( exists m,
 *     l < m <= r /\ forall n H, p n H = true <-> m <= n ) ->
 *   { m |
 *     l < m <= r /\ forall n H, p n H = true <-> m <= n }
 *)
let rec lower_bound l r p =
  if r <= 1 + l
  then r
  else let m = (l + r) / 2 in
       if p m
       then lower_bound l m p
       else lower_bound m r p

let () = Scanf.scanf "%d\n" @@ fun n ->
  let as_ = Array.init n @@ fun _ ->
    Scanf.scanf "%d " @@ fun a -> a in
  let sadness b =
    Array.fold_left ( + ) 0 @@
    Array.mapi (fun i a -> abs (a - b - i - 1)) as_
  in
  Printf.printf "%d\n" @@ sadness @@ lower_bound (-10000000000) 10000000000 @@ fun i ->
      0 <= sadness (i + 1) - sadness i
