summaryrefslogtreecommitdiff
path: root/1-2.hs
blob: 3fc718e605cc2d06bb995f78085d58f309512ed3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
count :: Eq a => a -> [a] -> Int
count x = foldr f 0
  where
    f y n | x == y = n + 1
          | otherwise = n

main :: IO ()
main = do
  ls <- getContents
  let ns = map (map read . words) . lines $ ls
  let xs = map head ns
  let ys = map last ns
  let ms = map (\x -> x * count x ys) xs
  print (sum ms)