{-# OPTIONS_GHC -Wno-incomplete-uni-patterns #-} import Data.Bifunctor (bimap) import Data.List (sort) import qualified Data.Map.Strict as Map main :: IO () main = do (a, b) <- bimap sort sort . unzip . map (\l -> let [x,y] = words l in (read @Int x, read y)) . lines <$> getContents print $ sum (zipWith (\x y -> abs (x - y)) a b) let hist = Map.fromAscListWith (+) (map (,1 :: Int) b) print $ sum [n * Map.findWithDefault 0 n hist | n <- a]