{-# LANGUAGE BangPatterns #-}
import Data.Maybe
import Data.List
import qualified Data.IntMap.Strict as IntMap

countElements :: [Int] -> IntMap.IntMap Int
countElements xs = fst4 $ foldl' acc (IntMap.singleton maxI 0, maxI, maxLen, 1) (xs' ++ [(0, 10^9+1)])
  where ((maxLen, maxI) : xs') = sortBy (flip compare) $ zip xs [1..]
        acc (!counter, !current, !lastLen, !countMet) (l, i) =
          let nextCount = IntMap.adjust ((lastLen - l) * countMet +) current counter
          in if i < current
               then (IntMap.insert i 0 nextCount, i, l, countMet + 1)
               else (nextCount, current, l, countMet + 1)
        fst4 (x, _, _, _) = x

im2is :: Int -> IntMap.IntMap Int -> [Int]
im2is n cnt = map (fromMaybe 0 . flip IntMap.lookup cnt) [1..n]

main :: IO ()
main = do
  n <- readLn
  as <- mapM readIO . words =<< getLine
  let cnt = countElements as
  mapM_ print $ im2is n cnt
