#include<iostream>
#include<vector>
using namespace std;
int main(){
	int n, cnt, i, j, inpt, sousa_cnt;
	vector<int> S, P;
	vector<int> *Sp, *Pp, *tmpp;
	Sp=&S;
	Pp=&P;
	while(true){
		cin>>n; if(n==0)break;
		Pp->resize(n, 0);
		Sp->resize(n, 0);
		for(i=0;i<n;i++){
			cin>>inpt;
			(*Sp)[i] = inpt;
		}
		for(sousa_cnt=0; true; sousa_cnt++){
			for(i=0;i<n;i++){
				cnt = 0;
				for(j=0;j<n;j++){
					if((*Sp)[i] == (*Sp)[j]) cnt++;
				}
				(*Pp)[i] = cnt;
			}
			for(i=0;i<n;i++){
				if((*Pp)[i] != (*Sp)[i]) break;
			}
			if(i==n) break;
			tmpp = Sp; Sp = Pp; Pp = tmpp;
		}
		cout<<sousa_cnt<<endl;
		cout<<(*Pp)[0];
		for(i=1;i<n;i++){
			cout<<" "<<(*Pp)[i];
		}
		cout<<endl;
	}
	return 0;
}