#include<iostream>
#include<cmath>
#include<vector>
#include<algorithm>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;

int main(){
  int n;
  while(cin>>n,n){
    vector<int>in1(n);
    vector<int>in2(n);
    int count=0;
    rep(i,n)cin>>in1[i];
    while(1){
      count++;
      bool h=true;
      rep(i,in1.size()){
	int co=0;
	rep(j,in1.size()){
	  if(in1[j]==in1[i])co++;
	}
	in2[i]=co;
	//cout<<co<<endl;
	if(in1[i]!=co)h=false;
      }
      if(h)break;
      //
      count++;
      h=true;
      rep(i,in2.size()){
	int co=0;
	rep(j,in2.size()){
	  if(in2[j]==in2[i])co++;
	}
	in1[i]=co;
	if(in2[i]!=co)h=false;
      }
      if(h)break;
    }
    cout<<count-1<<endl;
    cout<<in1[0];
    rep(i,in1.size()-1)cout<<" "<<in1[i+1];
    cout<<endl;
  }
}


  /*
  while(cin>>n,n){
    int co=0;
    vector< vector<int> >in(n);
    rep(i,n)cin>>in[0][i];
    do{
      vector<int>n;
      vector<int>num;
      rep(i,in[co].size()){
	bool han=false;
	int a;
	rep(j,n.size())if(num[j]==in[co][i]){a=j;han=true;}
	if(han){
	  n[a]++;
	}else{
	  n.push_back(in[co][a]);
	  num.push_back(1);
	}
      }
      rep(i,in[co].size()){
	rep(i,num.size())if(in[co][i]==num[
	in[co+1][i]=


      bool han1=false;
      
    }while();*/