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

using namespace std;

int main(){
	while(true){
		int n;
		cin >> n;
		if(n == 0){ break; }
		vector<int> s(n);
		map<int, int> table;
		for(int i = 0; i < n; ++i){
			cin >> s[i];
			if(table.find(s[i]) == table.end()){
				table.insert(pair<int, int>(s[i], table.size() + 1));
			}
			s[i] = table[s[i]];
		}
		int answer = 0;
		vector<int> prev = s;
		while(true){
			vector<int> b(n + 1, 0);
			for(int i = 0; i < n; ++i){ ++b[s[i]]; }
			for(int i = 0; i < n; ++i){ s[i] = b[s[i]]; }
			if(prev == s){ break; }
			prev = s;
			++answer;
		}
		cout << answer << endl;
		for(int i = 0; i < n; ++i){
			cout << s[i] << (i == n - 1 ? '\n' : ' ');
		}
	}
	return 0;
}