{-# OPTIONS_GHC -O2 -funbox-strict-fields #-}
import qualified Data.ByteString.Char8 as BC
import qualified Data.IntMap           as IM
import           Data.Maybe            (fromJust)

main :: IO ()
main = do
  n <- readLn :: IO Int
  as <- readInts
  print $ solve n as

readInts :: IO [Int]
readInts = map (fst . fromJust . BC.readInt) . BC.words <$> BC.getLine

solve n as = IM.foldrWithKey' folder 0 counter where
  counter = foldr (IM.alter countup) IM.empty as
  countup Nothing  = Just 1
  countup (Just x) = Just $ x + 1
  folder k v s
    | k < v = s + (v - k)
    | k > v = s + v
    | otherwise = s
