#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>
#include <sstream>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <numeric>
#include <cmath>
#include <climits>
#include <limits>
#include <cfloat>
#include <fstream>
using namespace std;

void freqApp (vector <int> s, vector <int>& p )
{
	int size = s.size();
	map <int, int> count;
	int i;

	for (i = 0; i < size; ++i){
		++count[s[i]];
	} // end for

	for (i = 0; i < size; ++i){
		p[i] = count[s[i]];
	} // end for
}

bool isfixpoint (vector <int> s, vector <int> p )
{
	int size = s.size();
	int i;

	for (i = 0; i < size; ++i){
		if (s[i] == p[i] ){
			continue;
		}else{
			return false;
		} // end if
	} // end for

	return true;
}

void disp_array (vector <int> a )
{
	int size = a.size();
	int i;

	for (i = 0; i < size; ++i){
		cout << a[i];
		if (i != size - 1){
			cout << ' ';
		} // end if
	} // end for
	cout << endl;
}

int main()
{
//	cut here before submit 
//	freopen("testcase.ofa", "r", stdin);
	string str = "";

	while (getline (cin, str ) ){
		int n;
		stringstream ssn(str);
		ssn >> n;
		
		if (n == 0 ){
			break;
		} // end if
		
		vector <int> s (n, 0 );
		vector <int> p (n, 0 );
		int count = 0;
		int i;

		getline (cin, str );
		stringstream ss (str );

		for (i = 0; i < n; ++i){
			ss >> s[i];
		} // end for

		while (1){
			freqApp (s, p ); 
//			cout << "s: "; disp_array (s );
//			cout << "p: "; disp_array (p );

			if (isfixpoint (s, p ) ){
				break;
			} // end if
			++count;
			s = p;
		} // end while
		
		cout << count << endl;
		for (i = 0; i < p.size(); ++i){
			cout << p[i];
			if (i != p.size() - 1){
				cout << ' ';
			} // end if
		} // end for
		cout << endl;
	} // end loop
		
	return 0;
}