#include <iostream>
#include <map>
#include <vector>

using namespace std;

#define rep(i,n) for((i)=0;(i)<(int)(n);(i)++)
#define foreach(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)

int main(){
  int N,i;
  vector<int> s,in;
  map<int,int> mp;

  while(cin >> N){
    if(N == 0) break;

    s.clear(); in.clear();
    s.resize(N); in.resize(N);
    rep(i,N){
      cin >> in[i];
      s[i] = in[i];
    }

    int res = 0;
    while(1){
      bool used[100];
      mp.clear();
      rep(i,N) mp[s[i]]++;
      rep(i,100) used[i] = false;

//      rep(i,N) cout << s[i] << ' '; cout << endl;
//      foreach(mp,itr) cout << itr->first << ',' << itr->second << ' '; cout << endl;

      rep(i,N) foreach(mp,itr) if(s[i] == itr->first && !used[i]){
        s[i] = itr->second;
        used[i] = true;
      }

//      rep(i,N) cout << s[i] << ' '; cout << endl;

      if(s == in) break;
      in = s;
      res++;
    }

    cout << res << endl;
    rep(i,N){
      cout << s[i];
      if(i == N-1) cout << endl; else cout << ' ';
    }
  }

  return 0;
}