#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n,a;
    while (cin>>n) {
        if (n==0) {
            break;
        } else {
            std::deque<int> deq;
            for (int i=0;i<n;i++) {
                cin>>a;
                deq.emplace_back(a);
            }
            std::map<int, int> map;
            int count=0;
            while (1) {
                map.clear();
                count++;
                for (int i=0;i<n;i++) {
                    map[deq[i]]++;
                }
                int tmp=0;
                for (int i=0;i<n;i++) {
                    if (deq[i]==map[deq[i]]) {
                        tmp++;
                    } else {
                        deq[i]=map[deq[i]];
                    }
                }
                if (tmp==n) {
                    cout<<count-1<<endl;
                    for (int i=0;i<n;i++) {
                        cout<<deq[i];
                        if (i!=n-1) {
                            cout<<" ";
                        } else {
                            cout<<endl;
                        }
                    }
                    break;
                }
            }
        }
    }
}
