readArray::IO String -> IO[Int]
readArray = fmap $ map read . words

difList::[Int] -> [Int] -> [Int] -> [Int]
difList (x:xs) (y:ys) sumList
    |xs == [] = sumList++[x-y]
    |otherwise = difList xs ys (sumList ++ [x-y])
    
absDif x y
    | x > y = x - y
    |otherwise = y - x
qSort::[Int] -> [Int]
qSort [] = []
qSort (x:xs)
    | xs == [] = [x]
    | otherwise = qSort [y|y<-xs, y < x] ++ [x] ++ qSort [z|z<-xs, z >= x]

median::[Int] -> Int
median xs = 
    let l = length xs
        n = div l 2
        ms = qSort xs
    in if mod l 2 == 0 then
        div ((ms !! (n - 1)) + (ms !! n)) 2
    else
        (ms !! n)
        
main = do
    getLine
    a <- readArray getLine
    let len = length a
    let b = difList a [1..len] []
    print $  sum $ map (absDif $ median b) (qSort b)