#include<iostream>
using namespace std;

bool check(int *numl, int *newl, int n = 0){
  for (int i = 0; i < n; i++) {
    if(numl[i] != newl[i])return false;
  }
  return true;
}

void printline(int *line, int n){
  std::cout << "printline:" << std::endl;
  for (int i = 0; i < n; i++) {
    std::cout << line[i] << " ";
  }
  std::cout << std::endl;
}

int main(){
  int n;
  while(cin >> n, n){
    int numl[n], newl[n], ans = 0;
    int counter[1000] = {0};
    for (int i = 0; i < n; i++) {
      cin >> numl[i];
      counter[numl[i]]++;
    }
    
    while(!check(newl, numl, n)){
      ans++;
      for (int i = 0; i < n; i++) {
        newl[i] = numl[i];
        numl[i] = counter[numl[i]];
      }
      
      for (int i = 0; i < n; i++) {
        counter[i] = 0;
      }
      
      for (int i = 0; i < n; i++) {
        counter[numl[i]]++;
      }

      //printline(numl, n);
    }
    std::cout << ans - 1 << std::endl;
    for (int i = 0; i < n; i++) {
      std::cout << newl[i] << " ";
    }
    std::cout << std::endl;
  }
  return 0;
}