import qualified Control.Monad as Mo import qualified Control.Monad.State as S import qualified Data.Char as C import qualified Data.Ord as O import qualified Data.List as L import qualified Data.Map as M type Order = M.Map String ([Int], [Int]) type Answer = M.Map Char Int data ProcState = ProcState {order :: Order, answer :: Answer} deriving Show main :: IO () main = do examN <- readLn :: IO Int levels <- fmap (map read . words) getLine :: IO [Int] submitN <- readLn :: IO Int submits <- fmap lines getContents let answers = M.fromList $ zip (take examN ['A'..]) $ repeat 0 resultS = Mo.forM (zip [1..] submits) $ \d -> do s <- S.get let o = order s a = answer s count = fst d [name, levelC:[]] = words $ snd d (levelIndex, level) = getLevel levels levelC rank = (M.!) a levelC + 1 score = floor $ 50 * (realToFrac level) + 50 * (realToFrac level) / (0.8 + 0.2 * (realToFrac rank)) (scores, answers) = case M.lookup name o of Just (ss, as) -> (ss, as) Nothing -> (replicate examN 0, []) scores' = take levelIndex scores ++ (score : drop (levelIndex + 1) scores) o' = M.insert name (scores', count:answers) o a' = M.insert levelC rank a S.put $ ProcState o' a' result = M.toList . order . S.execState resultS $ ProcState M.empty answers result' = L.sortBy compareResult result Mo.forM_ (zip [1..] result') $ \(n, (name, (scores, _))) -> do putStrLn $ show n ++ " " ++ name ++ " " ++ (unwords $ map show scores) ++ " " ++ show (sum scores) getLevel :: [Int] -> Char -> (Int, Int) getLevel levels c = (index, levels !! index) where index = C.ord c - C.ord 'A' compareResult :: (String, ([Int], [Int])) -> (String, ([Int], [Int])) -> Ordering compareResult (_, (ss, o)) (_, (ss', o')) = if c /= EQ then c else O.comparing head o o' where c = O.comparing sum ss' ss