def operation_of_foa(input_seq, times)
	operated_seq = Array.new
	input_seq.each { |x| operated_seq << input_seq.count(x) }
	if operated_seq == input_seq
		return [operated_seq, times]
	else
		operation_of_foa(operated_seq, times+1)
	end
end

while gets
	n = $_.to_i
	break if n == 0
	input_seq = gets.chomp.split.map(&:to_i)
	operated_seq, times = operation_of_foa(input_seq, 0)
	puts times
	puts operated_seq.join(" ")
end