def func(str)
  str=str.split(' ').map(&:to_i)
  hash={}
  str.each do |e|
    if hash.key?(e)
      hash[e] += 1
    else
      hash[e] = 1
    end
  end
  str.map!{|e|hash[e]}
  str.join(' ')
end

def main(str,before="",n = -1)
  buf=func(str)
  if buf == before
    puts n
    puts buf
  else
    main(buf,str,n+1)
  end
end

while gets.to_i != 0 do
  main(gets.chomp)
end