import Control.Applicative import Control.Monad import Data.Map (Map) import qualified Data.Map as M main :: IO () main = do cns <- replicateM 5 (f <$> getLine) n1 <- readLn ma <- M.fromListWith (+) <$> replicateM n1 (g <$> getLine) n2 <- readLn mb <- M.fromListWith (+) <$> replicateM n1 (g <$> getLine) n3 <- readLn mc <- M.fromListWith (+) <$> replicateM n1 (g <$> getLine) prt $ solve cns (n1*n2*n3) ma mb mc where f = (\[str, coin] -> (str, read coin)) . words g s = (s, 1) solve :: [(String, Int)] -> Int -> Map String Int -> Map String Int -> Map String Int -> (Double, [Int]) solve cns n ma mb mc = (exp, cts) where exp = (fromIntegral $ sum $ zipWith g cts cns) / fromIntegral n cts = map f cns f (s, _) = M.findWithDefault 0 s ma * M.findWithDefault 0 s mb * M.findWithDefault 0 s mc * 5 g c (_,p) = c * p prt :: (Double, [Int]) -> IO () prt (e,ps) = do print e mapM_ print ps