
def frequency_of_appearance(numbers, count = 0)
  new_numbers = numbers.map{ |number| numbers.count(number) }
  return frequency_of_appearance(new_numbers, count + 1) if numbers != new_numbers
  [count, new_numbers]
end

results = []
while num_numbers = gets.strip.to_i
  break if num_numbers == 0
  results << frequency_of_appearance(gets.strip.split[0, num_numbers].map(&:to_i))
end

puts results.map{ |a| "#{a[0]}\n#{a[1].join(" ")}" }.join("\n")