import Data.List import Data.Maybe import Control.Monad main = do dic <- replicateM 5 readKV (n1, a) <- readReel (map fst dic) (n2, b) <- readReel (map fst dic) (n3, c) <- readReel (map fst dic) -- [0] [1] [2] [3] [4] -- 000 0 0 -- 000 0 0 -- 000 0 0 let cnt = map (\k -> let x = a!!k; y = b!!k; z = c!!k in 5*x*y*z) $ [0..4] let ans = sum $ zipWith (*) cnt (map snd dic) print $ fromIntegral ans / fromIntegral (n1 * n2 * n3) mapM_ print cnt readKV :: IO (String, Int) readKV = do [k, v] <- words <$> getLine return (k, read v) readReel :: [String] -> IO (Int, [Int]) readReel dic = do n <- readLn :: IO Int x <- replicateM n (fromJust . flip elemIndex dic <$> getLine) return (n, [length . filter (==i) $ x | i <- [0..4]])