#define	_USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <vector>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cfloat>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <string>
#include <set>
#include <complex>
#include <utility>
#define  rep(i,n) for(int i=0;i<(n);i++)
#define  REP(i,n) for(int i=1;i<(n);i++)
#define  rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define  VI	vector<int>
#define	 VS vector<string>
#define  all(a) (a).begin(),(a).end()
#define  debug(x) cout<<#x<<": "<<x<<endl
using namespace std;
typedef pair<int,int> P;
int main(){
	
	int n;
	while(cin>>n,n!=0){
		vector<int> s(n,0);
		vector<int> p(n,0);
		int count=0;
		rep(i,n)
			cin>>s[i];
		
		bool f=false;
		while(!f){
			f=true;
			map<int,int> m;
			
			rep(i,n){
				if(m.count(s[i])==0){
					m[s[i]]=1;
				}
				else
					m[s[i]]++;
			}
			rep(i,n)
				p[i]=m[s[i]];
			
			rep(i,n){
				if(p[i]!=s[i])
					f=false;
				
			}
			if(!f){
				rep(i,n)
					s[i]=p[i];
			count++;}
		}
		cout<<count<<endl;
		cout<<s[0];
		REP(i,n)
			cout<<" "<<s[i];
		cout<<endl;
		
	}
	
}