#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;
const ld eps=1e-9;

//// < "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\a.txt"
int main() {
	while (1) {
		int N; cin >> N;
		if (!N)break;
		vector<int>vs(N);
		for (int i = 0; i < N; ++i) {
			cin >> vs[i];
		}
		int time = 0;
		while (1) {
			map<int, int>mp;
			for (int i = 0; i < N; ++i) {
				mp[vs[i]]++;
			}
			vector<int>nexvs(N);
			for (int i = 0; i < N; ++i) {
				nexvs[i] = mp[vs[i]];
			}
			if (vs == nexvs)break;
			vs = nexvs;
			time++;
		}
		cout << time << endl;
		for (int i = 0; i < N; ++i) {
			cout << vs[i];
			if (i != N - 1)cout << " ";
			else cout << endl;
		}
	}
	return 0;
}