import Data.List
main :: IO ()
main = do
    n <- read <$> getLine
    xs <- map read . words <$> getLine
    print $ solve xs n
    return ()
solve :: [Int] -> Int -> Int
solve as n = sum . map (abs . subtract c) $ bs
    where   
        bs = sort $ zipWith (\l r -> l - r) as [1..]
        c = bs !! (n `div` 2)