import Data.List
import Control.Applicative

solve :: [Int] -> (Int, [Int])
solve xs = rec 0 xs
    where rec i xs
            | xs == nextXs = (i, xs)
            | otherwise    = rec (i+1) nextXs
            where nextXs = next xs
          next xs = map (length . flip filter xs . (==)) xs
                    

main = do
    n <- readLn :: IO Int
    if n == 0 then return ()
    else do
        xs <- map read <$> words <$> getLine
        let (count, fixXs) = solve xs
        print count
        putStrLn $ unwords $ map show $ fixXs
        main