#include<stdio.h>
#include<iostream>
#include<list>
#include<map>
#include<math.h>
#include<vector>
#include<algorithm>
#include<string.h>
#include<iomanip>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) range(i,0,b)
#define debug(x) cout << "debug" << x << endl;
using namespace std;

int n, ans = 0;

void solve(int l1[], int count[]){
    int l2[13], sum = 0;
    int subcount[13] = {0};
    range(i, 1, n + 1){
        l2[i] = count[ l1[i] ];
        subcount[ l2[i] ]++;
    }
    range(i, 1, n + 1){
        sum+= l1[i] - l2[i];
    }
    if(sum != 0){
        ans++;
        solve(l2, subcount);
    }else{
        cout << ans << endl;
        range(i, 1, n + 1){
            if(i == 1) cout << l1[i];
            else cout << ' ' << l1[i];
        }cout << endl;
    }
}

int main(){
    int l1[13], l2[13];
    while(cin >> n, n){
        int count[13] = {0};
        range(i, 1, n + 1){
            cin >> l1[i];
            count[l1[i]]++;
        }
        ans = 0;
        solve(l1, count);
    }
}