def appearance_frequency(seq)
	h = Hash.new(0)
	seq.each {|i| h[i] += 1}
	return seq.map{|i| h[i]}
end

loop do
	n = $<.gets.to_i
	break if n.zero?

	seq = $<.gets.split.map(&:to_i)
	count = 0
	loop do
		s = appearance_frequency(seq)
		if s == seq
			p count
			puts s.join(' ')
			break
		end

		seq = s
		count += 1
	end
end