#include <iostream>
#include <cstdio>
#include <cstdlib>
using namespace std;
int main(void){
  char d1[12],d2[12];
  int n1,n2;
  int n,a;
  while(cin>>n,n!=0){
    for(int i=0;i<n;i++){
      scanf("%d",&d2[i]);
      d2[i]+='0';
    }
    a=0;
    n1=0;
    n2=atoi(d2);
    while(n1!=n2){
      n1=n2;
      for(int j=0;j<n;j++){
	d1[j]=d2[j];
	d2[j]=0;
      }
      for(int j=0;j<n;j++){
	for(int k=0;k<n;k++){
	  if(d1[j]==d1[k]){
	    d2[j]++;
	  }
	}
	d2[j]+='0';
      }
      n2=atoi(d2);
      a++;
    }
    cout<<a-1<<endl;
    for(int j=0;j<n-1;j++){
      printf("%d ",d1[j]-'0');
    }
    cout<<d1[n-1]-'0'<<endl;
  }
  return 0;
}