loop {
    n = gets.to_i
    break if n == 0
    a = gets.split.map &:to_i
    c = 0
    loop {
        hash = Hash.new(0)
        a.each{|x| hash[x] += 1}
        b = a.map{|x| hash[x]}
        break if a == b
        a = b
        c += 1
    }
    p c
    puts a * ' '
}