#include<iostream>
#include<vector>
#include<map>
using namespace std;

int main()
{
	int n, i, count, f;
	vector<int> s;
	map<int, int> m;
	while (cin>>n, n) {
		s.clear();
		for (i = 0; i < n; i++) {
			cin>>count;
			s.push_back(count);
		}

		f = 0;
		count = 0;
		while (f!=n) {
			f = 0;
			count++;

			m.clear();
			for (i = 0; i < n; i++) {
				if (m.count(s[i])) m[s[i]]++;
				else m[s[i]] = 1;
			}
			for (i = 0; i < n; i++) {
				if (s[i]==m[s[i]]) f++;
				s[i] = m[s[i]];
			}
		}
		cout<<--count<<endl;
		for (i = 0; i < n; i++) {
			if (i) cout<<" ";
			cout<<s[i];
		}
		cout<<endl;
	}
	return 0;
}