length = gets.to_i
while length != 0
  c = Array.new(length)
  p1 = Array.new(length)
  s = gets.split.map { |e| e.to_i }
  c = Marshal.load(Marshal.dump(s))
  time = 0
  while true
    i = 0
    time += 1
    p1 = Marshal.load(Marshal.dump(c))
    p1.each { |e|
      c[i] = p1.select {|g| g == e}.size
      i += 1
    }
    break if p1 == c
  end
  p time-1
  puts p1.join(" ")
  length = gets.to_i
end