import Control.Applicative ((<$>)) import Control.Arrow (second) import Control.Monad import Control.Monad.State import Data.Char (ord) import Data.List (elemIndices, sortBy) import Data.Function (on) import Data.Monoid ((<>)) import qualified Data.Array as A import qualified Data.Map as M type Submission = (String, Int) type AcCnt = M.Map Int Int main :: IO () main = do n <- readLn ls <- map read . words <$> getLine t <- readLn subs <- replicateM t $ do [name, p] <- words <$> getLine return (name, ord (head p)-ord 'A') let upds = map (second A.elems) $ M.toList $ evalState (proc subs ls n) $ M.fromList $ zip [0..n-1] $ repeat 1 forM_ (zip [1..] (sortBy (comp subs) upds)) $ \(i, (name, xs)) -> do putStr $ show i ++ " " ++ name mapM_ (putStr . (" "++) . show) xs putStrLn $ " " ++ show (sum xs) proc :: [Submission] -> [Double] -> Int -> State AcCnt (M.Map String (A.Array Int Int)) proc [] _ _ = return M.empty proc ((name, p):xs) ls n = do acCnt <- get let pts = evalState (proc xs ls n) (M.insert p (acCnt M.! p+1) acCnt) pts' = if name `M.notMember` pts then M.insert name (A.listArray (0, n-1) $ repeat 0) pts else pts return $ M.insert name (pts' M.! name A.// [(p, floor $ 50*(ls!!p)+50*(ls!!p)/(0.8+0.2*fromIntegral (acCnt M.! p)))]) pts' comp :: [Submission] -> (String, [Int]) -> (String, [Int]) -> Ordering comp subs (lName, l) (rName, r) = (compare `on` sum) r l <> idxL `compare` idxR where idxL = last $ elemIndices lName $ map fst subs idxR = last $ elemIndices rName $ map fst subs