#include <bits/stdc++.h>

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define EPS (1e-8)

typedef pair<int, int> pii;
typedef vector<pii> vp;
typedef vector<int> vi;

int n;

vi solve(vi& a) {
	vp cnt; //num, count
	REP(i, n) {
		bool f = true;
		REP(j, cnt.size()) {
			if (a[i] == cnt[j].first) {
				cnt[j].second++;
				f = false;
			}
		}
		if (f) cnt.push_back(pii(a[i], 1));
	}
	
	vi res(n);
	REP(i, n) {
		REP(j, cnt.size()) if (a[i] == cnt[j].first)
			res[i] = cnt[j].second;
	}
	
	return res;
}

bool check(const vi& a, const vi& b) {
	bool f = true;
	REP(i, n) if (a[i] != b[i]) f = false;
	return f;
}

int main() {
	while (cin >> n, n) {
		vi s1(n), s2;
		REP(i, n) scanf("%d", &s1[i]);
		
		int ans = 0;
		while (true) {
			s2 = solve(s1);
			if (check(s1, s2)) break;
			s1 = s2;
			ans++;
		}
		cout << ans << endl;
		REP(i, n - 1) printf("%d ", s1[i]);
		printf("%d\n", s1[n - 1]);
	}
	return 0;
}