#include <vector>
#include <iostream>
#include <map>


void f(std::vector<int> &vector, const int &count = 0){
	bool flag = true;
	std::map<int, int> freq;
	for (const auto &i : vector) {
		if (freq.find(i) == freq.end()) {
			freq[i] = 1;
		}
		else {
			++freq.at(i);
		}
	}
	for (auto &i : vector) {
		flag = (i == freq.at(i)) && flag;
		i = freq.at(i);
	}
	if (flag) {
		std::cout << count << "\n";
		for (auto i = 0; i < vector.size() - 1; ++i){
			std::cout << vector.at(i) << " ";
		}
		std::cout << vector.back() << "\n";
	}
	else {
		f(vector, count + 1);
	}
}
int main() {
	int n;
	std::cin >> n;
	while (n != 0) {
		std::vector<int> vec(n);
		for (auto &i : vec) {
			int temp;
			std::cin >> temp;
			i = temp;
		}
		f(vec);
		std::cin >> n;
	}
	return 0;
}