#include <iostream>
#include <cstring>
#include <map>
using namespace std;

void operate(int *s, int size) {
    map<int, int> ns;
    for (int i = 0; i < size; i++) {
        ns[s[i]]++;
    }
    for (int i = 0; i < size; i++) {
        s[i] = ns[s[i]];
    }
}

bool finish(int *s, int size) {
    int ns[size];
    for (int i = 0; i < size; i++) {
        ns[i] = s[i];
    }
    operate(ns, size);
    for (int i = 0; i < size; i++) {
        if (ns[i] != s[i]) {
            return false;
        }
    }
    return true;
}

int main() {
    int n;
    while (cin >> n, n != 0) {
        int s[n];
        for (int i = 0; i < n; i++) {
            cin >> s[i];
        }
        int count = 0;
        while (!finish(s, n)) {
            operate(s, n);
            count++;
        }
        cout << count << endl;
        cout << s[0];
        for (int i = 1; i < n; i++) {
            cout << ' ' << s[i];
        }
        cout << endl;
    }
    return 0;
}