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

int main(){
    int n;
    while (1){
	cin >> n;
	if (n == 0) break;
	vector<int> s;
	int b;
	for (int i = 0; i < n; i++){
	    cin >> b;
	    s.push_back(b);
	}
	int c = 0;
	while (1){
	    vector<int> freq(13, 0);
	    for (int i = 0; i < n; i++)
		freq[s[i]]++;

	    vector<int> ss = s;
	    for (int i = 0; i < n; i++)
		ss[i] = freq[ss[i]];

	    if (ss == s){
		cout << c << endl;
		for (int i = 0; i < s.size(); i++)
		    printf("%d%c", s[i], (i == s.size()-1)? '\n':' ');
		break;
	    }

	    s = ss;
	    c++;
	}
    }
}