#include <bits/stdc++.h>

#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)

using namespace std;


int main()
{
	int n;
	while(cin >>n){
		if(n ==0) break;
		vector<int> p(n);
		rep(i,n){ cin >> p[i];}
		int ans =0;
		vector<int> q(105), np(n, -1);
		while(np != p){
			ans++;
			fill(q.begin(), q.end(),0);
			rep(i,n) q[p[i]]++;
			rep(i,n) np[i] = q[p[i]];
			//for(auto x :np) printf("%d, ",x); puts("");
			swap(p, np);
		}
		cout << ans -1 <<"\n";
		rep(i,n)  printf("%s%d",(i? " ":""),p[i]);
		printf("\n");
		
		
	}
	return 0;

}