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

using namespace std;

vector<int> C(vector<int> v) {
	map<int, int> m;

	for (int i = 0; i < v.size(); ++i)
		++m[v[i]];

	vector<int> ret;
	for (int i = 0; i < v.size(); ++i)
		ret.push_back(m[v[i]]);

	return ret;
}

int main() {
	int n;
	while (cin >> n, n) {
		vector<int> v;
		for (int i = 0; i < n; ++i) {
			int a; cin >> a;
			v.push_back(a);
		}

		int count = 0;
		vector<int> bv = v;
		while (1) {
			v = C(v);
			if (v == bv) break;
			bv = v;
			++count;
		}

		cout << count << endl;
		for (int i = 0; i < v.size(); ++i)
			if (i == v.size()-1) cout << v[i] << endl;
			else cout << v[i] << " ";
	}
}