import Control.Monad (replicateM) import Control.Monad.State import Data.List (sortBy, findIndices) type Score = Int type Point = Int type Rank = Int main :: IO () main = do n <- readLn as <- replicateM n readLn mapM_ print $ evalState (solve n as 0) $ replicate n 0 solve :: Int -> [Score] -> Int -> State [Point] [Rank] solve n as t | t == n = return [] | otherwise = do pts <- get let npts = addIdx t (as!!t) pts put npts res <- solve n as (t+1) return $ rank npts : res rank :: [Point] -> Int rank = (+1) . head . findIndices ((==0) . snd) . sortBy tupleComp . flip zip [0..] where tupleComp (a,b) (c,d) | a == c = b `compare` d | otherwise = c `compare` a addIdx :: Int -> Int -> [Int] -> [Int] addIdx idx n xs = take idx xs ++ [xs!!idx+n] ++ drop (idx+1) xs