import qualified Data.IntMultiSet as IMultiSet import Data.List (sort, transpose) import Data.List.Split (splitOn) solve :: [[Int]] -> Int solve [l, r] = sum $ map (\x -> x * IMultiSet.occur x rs) l where rs = IMultiSet.fromList r main :: IO () main = print . solve . transpose . map parseLine . lines =<< readFile "data.txt" where parseLine = map read . filter (not . null) . splitOn " "