import Data.List (elemIndices)
import Control.Monad (unless)
import Control.Applicative ((<$>))

findFixedPoint :: [Int] -> (Int, [Int])
findFixedPoint = findFixedPoint' 0
    where
        findFixedPoint' m ss
            | ss == cs  = (m, ss)
            | otherwise = findFixedPoint' (m + 1) cs
            where
                cs = map (\k -> length $ elemIndices (ss !! k) ss) [0 .. (length ss) - 1]

main :: IO ()
main = do
    n <- readLn
    unless (n == 0) $ do
        (m, p) <- findFixedPoint . map read . words <$> getLine
        putStrLn $ show $ m
        putStrLn $ unwords $ map show $ p
        main