#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<cctype>
#include<complex>
#include<iostream>
#include<sstream>
#include<algorithm>
#include<functional>
#include<utility>
#include<vector>
#include<string>
#include<stack>
#include<queue>
#include<map>
 
using namespace std;
const int dx[] = {1,0,-1,0},dy[] = {0,1,0,-1};
#define INF 1e+9
#define EPS 1e-9
#define rep(i,j) for(int i = 0; i < (j); i++)
#define reps(i,j,k) for(int i = j; i < (k); i++)
typedef long long ll;
bool check(int data[],int bef[],int n){
    rep(i,n){
        if(data[i] != bef[i])return false;
    }
    return true;
}
int main(){
    int n;
    while(scanf("%d",&n),n){
        int data[12800]={0};
        int bef[12800]={0};
        rep(i,n){
            scanf("%d",&data[i]);
        }
        int ans=0;
        while(true){
            if(check(data,bef,n)){
                printf("%d\n",--ans);
                rep(i,n-1){
                    printf("%d ",data[i]);
                }
                printf("%d\n",data[n-1]);
                break;
            }
            ans++;
            rep(i,n)bef[i] = data[i];
            int memo[12800]={0};
            rep(i,n){
                if(memo[bef[i]])data[i] = memo[bef[i]];
                else{
                    int cnt = 0;
                    rep(j,n)if(data[i] == bef[j])cnt++;
                    memo[data[i]] = cnt;
                    data[i] = cnt;
                }
            }
        }
    }
    return 0;
}