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

using namespace std;

int main () {
  while( 1 ) {
    int n;
    cin >> n;
    if( !n ) { return EXIT_SUCCESS; }
    
    vector<int> seq;
    
    seq.reserve( n );
    for( int i = 0; i < n; i++ ) {
      cin >> seq[ i ];
    }
    
    int ct;
    for( ct = 0; ; ct++ ) {
      map<int, int> m;
      for( int i = 0; i < n; i++ ) {
        if( m.find( seq[ i ] ) == m.end() ) {
          m[ seq[ i ] ] = 1;
        } else {
          m[ seq[ i ] ]++;
        }
      }

      bool changed = false;
      for( int i = 0; i < n; i++ ) {
        if( seq[ i ] != m[ seq[ i ] ] ) { changed = true; }
        seq[ i ] = m[ seq[ i ] ];
      }
      /*
      // <for-debug>
      for( int i = 0; i < n; i++ ) {
        cout << seq[ i ] << flush;
        if( i == n - 1 ) { cout << endl; }
        else { cout << " " << flush; }
      }
      // </for-debug>
      */
      if( !changed ) { break; }
    }

    cout << ct << endl;
    for( int i = 0; i < n; i++ ) {
      cout << seq[ i ] << flush;
      if( i == n - 1 ) { cout << endl; }
      else { cout << " " << flush; }
    }
  }
}