#include<iostream>
#include<vector>
#include<map>
using namespace std;
typedef long long ll;

int main(){
  int n;
  while(cin >> n,n){
    vector<ll> cur(n);
    for(int i=0;i<n;i++)cin >> cur[i];

    int ans = 0;
    for(;;){
      map<ll,ll> freq;
      
      for(int i=0;i<n;i++)freq[cur[i]]++;

      vector<ll> nxt(n);
      for(int i=0;i<n;i++)nxt[i] = freq[cur[i]];

      bool f = true;
      for(int i=0;i<n;i++){
	if(nxt[i] != cur[i])f = false;
      }
      if(f)break;
      ans++;
      cur = nxt;
    }

    cout << ans << endl;
    for(int i=0;i<n;i++)cout << cur[i] << " \n"[i==n-1];
  }
}
      