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

using namespace std;

void solve()
{
	int N;
	while(cin >> N, N)
	{
		vector<int> Vec(N);
		for(int i = 0; i < N; ++i)
		{
			cin >> Vec[i];
		}
		int count = 0;
		bool Flag = true;
		while(Flag)
		{
			++count;
			map<int, int> Map;
			Flag = false;
			for(int i = 0; i < N; ++i)
			{
				++Map[Vec[i]];
			}
			vector<int> VecBuf(N);
			for(int i = 0; i < N; ++i)
			{
				VecBuf[i] = Map[Vec[i]];
			}
			for(int i = 0; i < N; ++i)
			{
				if(Vec[i] != VecBuf[i])
				{
					Flag = true;
					for(int j = 0; j < N; ++j)
					{
						Vec[j] = VecBuf[j];
					}
					goto NEXT;
				}
			}
NEXT:
			;
		}
		cout << --count << endl;
		for(int i = 0; i < N - 1; ++i)
		{
			cout << Vec[i] << " ";
		}
		cout << Vec[N - 1] << endl;
	}
}

int main()
{
	solve();
	return(0);
}