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

bool check(vector<int> s, vector<int> freq_s);

int main()
{
	int n;
	
	while (scanf("%d", &n), n != 0){
		vector<int> s, freq_s;
		map<int, int> freq;
		
		for (int i = 0; i < n; i++){
			int t;
			scanf("%d", &t);
			s.push_back(t);
		}
		int cnt;
		for (cnt = 0; ; cnt++){
			freq.clear();
			freq_s.clear();
			for (int i = 0; i < s.size(); i++){
				freq[s[i]]++;
			}
			for (int i = 0; i < s.size(); i++){
				freq_s.push_back(freq[s[i]]);
			}
			if (check(s, freq_s)) break;
			else s = freq_s;
		}
		printf("%d\n", cnt);
		printf("%d", freq_s[0]);
		for (int i = 1; i < freq_s.size(); i++){
			printf(" %d", freq_s[i]);
		}
		puts("");
	}
	
	return 0;
}

bool check(vector<int> s, vector<int> freq_s)
{
	if (s.size() != freq_s.size()) return false;
	for (int i = 0; i < s.size(); i++){
		if (s[i] != freq_s[i]) return false;
	}
	return true;
}