#include <iostream>

int main(){
  //nªzñ·³,countªvZñÌÂàè
  int n,count;
  while(std::cin >> n){
    //std::cout << n << std::endl;
    if(!n) {
      break;
    }
    int s[n];
    bool flag;
    int cnt[n];
    int cnt_of[n];
    int new_s[n];
    int old_s[n];
    
    //üÍtF[Y
    for(int i=0;i<n;i++){
      std::cin >> s[i];
    }

    for(int ans=0;;ans++){
      //½Â é©ð¦é
      cnt[0]=s[0];
      cnt_of[0]=1;
      int count=0;
      
      //iÔÚª¡ÜÅÉoÄ«½©mF
      for(int i=1;i<n;i++){
	for(int j=0;;j++){
	  if(cnt[j]==s[i]){
	    cnt_of[j]++;
	    break;
	  }
	  if(j==count){
	    count++;
	    cnt[count]=s[i];
	    cnt_of[count]=1;
	    //	    std::cout << count <<"count+" << i << std::endl;
	    break;
	  }
	}
      }//iÔÚ[v
      
      flag = true;
      //eiÉlðãü
      for(int i=0;i<n;i++){
	for(int j=0;j<=count;j++){
	  if(cnt[j]==s[i]){
	    new_s[i]=cnt_of[j];
	    break;
	  }
	}
	if(new_s[i]!=s[i]){
	  flag = false;
	  s[i]=new_s[i];
	}
      }
      
      //mFpoÍ

      /*      for(int i=0;i<n;i++){
	std::cout << new_s[i] << " ";
      }
      std::cout << std::endl;
      */

      if(flag){
	std::cout << ans << std::endl;
	//mFpoÍ
	for(int i=0;i<n;i++){
	  std::cout << new_s[i] << " ";
	}
	std::cout << std::endl;
	break;
      }
    }
  }//while
}