quicksort :: (Ord a) => [a] -> [a]
quicksort [] = []
quicksort (x:xs) =
  let small = [a | a <- xs , a <= x]
      large = [a | a <- xs , a > x]
  in quicksort small ++ [x] ++ quicksort large

subi :: [Int] -> Int -> [Int]
subi [] _ = []
subi (x:xs) n = (x-n) : subi xs (n-1)

main = do
  n <- (read :: String -> Int) <$> getLine
  x <- map (read :: String -> Int) . words <$> getLine
  let y = subi (reverse x) n
      b = head $ drop (div n 2) $ quicksort y
      ans = foldl (\acc t -> (acc + abs(t-b))) 0 y
  putStrLn $ show ans
