#include<cstdio>
#include<cmath>
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<cstdlib>
#include<iomanip>
#include<queue>
#include<set>


using namespace std;

void Solution()
{
    int n;
    
    while (cin>>n, n)
    {
        vector<int> s(n), nextSequence(n);
        int count = 0;
        
        for (int i = 0; i < n; i++)
        {
            cin>>s[i];
        }
        
        while (1)
        {
            for (int i = 0; i < n; i++)
            {
                nextSequence[i] = 0;
                
                for (int j = 0; j < n; j++) //repeat this step for every element, so start from 0, everytime.
                {
                    if (s[i] == s[j])
                    {
                        nextSequence[i]++;
                    }
                }
            }
            
            if ( s == nextSequence)
            {
                cout<<count<<endl;
                
                for (int i = 0; i < n; i++)
                {
                    if (i != 0)
                    {
                        cout<<" ";
                    }
                    
                    cout<<s[i];
                }
                
                cout<<endl;
                break;
            }
            else
            {
                s = nextSequence;
                count++;
            }
        }
    }

}

int main()
{
    Solution();
    return 0;
}