blob: c3871d6d09c42cb3f75a2ef9dada34e066e3b8e5 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
|
{-# 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.fromListWith (+) (map (,1 :: Int) b)
print $ sum [n * Map.findWithDefault 0 n hist | n <- a]
|