#include <iostream>
#include <vector>
using namespace std;

vector< int > alterSequence( vector< int >& seq ){
	int size = seq.size();
	vector< int > ret( size, 0 );
	for( int i = 0; i < size; ++i ){
		if( ret[ i ] != 0 ){
			continue;
		}
		int target = seq[ i ];
		int count = 0;
		for( int j = i; j < size; ++j ){
			if( seq[ j ] == target ){
				++count;
			}
		}
		for( int j = i; j < size; ++j ){
			if( seq[ j ] == target ){
				ret[ j ] = count;
			}
		}
	}
	return ret;
}

int main()
{
	int n;

	while( cin >> n && n ){
		vector< int > seq;
		for( int i = 0; i < n; ++i ){
			int d;
			cin >> d;
			seq.push_back( d );
		}
		int alt_count = 0;
		vector< int > alt;
		bool first = true;
		while( alt != seq ){
			if( first ){
				first = false;
			}else{
				seq = alt;
				++alt_count;
			}
			alt = alterSequence( seq );
		}
		cout << alt_count << endl;
		first = true;
		for( int i = 0; i < (int)seq.size(); ++i ){
			if( first ){
				first = false;
			}else{
				cout << " ";
			}
			cout << seq[ i ];
		}
		cout << endl;
	}
	return 0;
}