#include<iostream>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<cstdio>
#include<cstdlib>
using namespace std;
#define REP(i,a,n) for(int i = a ; i < n ; i++)
#define rep(i,n) REP(i,0,n)

typedef long long ll;

vector<int> solve(vector<int> v){
  map<int,int> cnt;
  rep(i,v.size()) cnt[v[i]]++;

  vector<int> res;
  rep(i,v.size()) res.push_back(cnt[v[i]]);
  return res;
}

int main(){
  int n;

  while(cin>>n,n){
    vector<int> v(n);
    rep(i,n) cin>>v[i];
    int cnt = 0;

    while(1){
      vector<int> next = solve(v);
      if(next == v){
        break;
      }
      v = next;
      cnt++;
    }

    cout<<cnt<<endl;
    rep(i,n){
      if(i != 0) cout<<" ";
      cout<<v[i];
    }
    cout<<endl;
  }
}