#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <iostream>
#include <climits>
#include <cfloat>


using namespace std;

int main()
{
	int n;
	while (scanf("%d", &n), n)
	{
		int hoge[2][32];
		for (int i = 0; i < n; ++i)
		{
			int t;
			scanf("%d", &t);
			hoge[0][i] = t;
		}

		for (int i = 0; ; ++i)
		{
			int* cur = hoge[i & 1];
			int* next = hoge[(i+1) & 1];
			map<int, int> c;
			for (int j = 0; j < n; ++j)
				++c[cur[j]];

			for (int j = 0; j < n; ++j)
				next[j] = c[cur[j]];

			bool eq = true;
			for (int j = 0; eq && j < n; ++j)
				eq = cur[j] == next[j];

			if (eq)
			{
				printf("%d\n", i);
				for (int j = 0; j < n; ++j)
				{
					printf("%d", cur[j]);
					if (j != n-1)
						printf(" ");
					else
						printf("\n");
				}
				break;
			}
		}
	}

	return 0;
}