#include <iostream>
using namespace std;

bool isEqualArray(int n, int* s1, int* s2) {
    for (int i = 0; i < n; i++) {
        if (s1[i] != s2[i]) {
            return false;
        }
    }
    return true;
}

int main() {
    while (true) {
        int n;
        cin >> n;
        if (n == 0) {
            break;
        }
        int* s1 = new int [n];
        for (int i = 0; i < n; i++) {
            cin >> s1[i];
        }
        int count = 0;
        int* s2 = new int [n];
        while (!isEqualArray(n, s1, s2)) {
            for (int i = 0; i < n; i++) {
                s2[i] = s1[i];
            }
            for (int i = 0; i < n; i++) {
                int exist = 0;
                for (int j = 0; j < n; j++) {
                    if (s2[i] == s2[j]) {
                        exist++;
                    }
                }
                s1[i] = exist++;
            }
            count++;
        }
        cout << count - 1 << endl;
        for (int i = 0; i < n - 1; i++) {
            cout << s1[i] << " ";
        }
        cout << s1[n - 1] << endl;
        delete[] s1;
        delete[] s2;
    }
}