#include<iostream>
#include<vector>

using namespace std;

struct DATA{
  int x;
  int isFound;
};

vector<int> Operation(vector<int>);

int main(){
  int i, n, a, count;
  vector<int> before, after;

  while(1){
    cin >> n;
    if(n == 0) break;

    for(i=0; i<n; ++i){
      cin >> a;
      before.push_back(a);
    }

    count = 0;
    while(1){
      after = Operation(before);
      if(after == before) break;
      before = after;
      ++count;
    }

    cout << count << endl;
    for(i=0; i<after.size()-1; ++i)
      cout << after[i] << " ";
    cout << after[after.size()-1] << endl;

    before.clear();
    after.clear();
  }
  return 0;
}

vector<int> Operation(vector<int> before){
  int i, j, count;
  vector<int> list, after;
  DATA onedata;
  vector<DATA> data;

  for(i=0; i<before.size(); ++i){
    onedata.x = before[i];
    onedata.isFound = 0;
    data.push_back(onedata);
  }

  i = 0;
  while(1){
    count = 0;
    list.clear();
    for(j=i; j<data.size(); ++j){
      if(data[j].isFound == 0 && data[i].x == data[j].x){
        data[j].isFound = 1;
        list.push_back(j);
        ++count;
      }
    }

    for(j=0; j<list.size(); ++j)
      data[list[j]].x = count;

    j = 1;
    while(1){
      if(i+j == data.size() || data[i+j].isFound == 0){
        i += j;
        break;
      }      
      ++j;
    }
    if(i == data.size()) break;
  }

  for(i=0; i<data.size(); ++i)
    after.push_back(data[i].x); 

  return after;

}