def operation_of_foa(input_seq, times)
	operated_seq = Array.new
	count_seq = Hash.new
	input_seq.each do |n|
		if count_seq.has_key?(n)
			count_seq[n] += 1
		else
			count_seq[n] = 1
		end
	end
	input_seq.each do |n|
		operated_seq << count_seq[n]
	end
	if operated_seq == input_seq
		return [operated_seq, times]
	else
		operation_of_foa(operated_seq, times+1)
	end
end

def print_seq(seq_times)
	puts seq_times.last
	seq_times.first.each.with_index { |x,i| print (i.zero? ? x : " #{x}") }
	puts ""
end
while gets
	n = $_.to_i
	break if n == 0
	input_seq = gets.chomp.split.map(&:to_i)
	print_seq(operation_of_foa(input_seq, 1))
end