#include <iostream>
#include <vector>
#include <map>
using namespace std;
int N;

void solve(vector<int> cur, vector<int> prev, int turn) {
    if(cur == prev) {
        cout << turn-1 << endl;
        for(int i=0; i<N; i++) cout << (i!=0 ? " " : "") << cur[i];
        cout << endl;
        return;
    }

    map<int, int> m;
    for(int i=0; i<N; i++) m[ cur[i] ]++;
    vector<int> nx(N);
    for(int i=0; i<N; i++) nx[i] = m[ cur[i] ];
    solve(nx, cur, turn+1);
}

int main() {
    while(cin >> N, N) {
        vector<int> v(N);
        for(int i=0; i<N; i++) cin >> v[i];
        solve(v, vector<int>(N, 0), 0);
    }
    return 0;
}