import Data.List
import Debug.Trace

main = do
  n <- read <$> getLine :: IO Int
  as <- map read . words <$> getLine :: IO [Int]
  print $ solve as
--  print $ deb as 

solve :: [Int] -> Int
solve as =
--  traceShow as' $
--  traceShow (b1,b2) $
  ans
  where
    diffs = map (\(x,y) -> x-y) $ zip as [1..]
    as' = sort diffs
    b1 = mid as'
    b2 = average as'
    mi = abs $ minimum diffs
    ma = abs $ maximum diffs
    ans = minimum $ map (sadness as') [b1,b2,mi,ma,-mi,-ma]

sadness l b =
  sum $ map (\e -> abs (e-b)) l

average l =
  div s len
  where
    s = sum l
    len = length l
mid l =
  if odd len then
    l !! (div len 2)
  else
   div (( l !! (div len 2)) + (l !! (div len 2 + 1))) 2
  where
    len = length l
