while true
    n = gets.to_i
    break if n == 0
    arr = gets.chomp.split.map(&:to_i)
    count = 0
    while true
        h = Hash.new(0)
        arr.each{|x| h[x] += 1}
        arr2 = []
        arr.each{|x| arr2 << h[x]}
        break if arr == arr2
        arr = arr2
        count += 1
    end
    puts count
    puts arr.join(" ")
end
