#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>

#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define repi(i,a,b) for(int i = (a); i < (b); i++)

using namespace std;

typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;

const int INF=1<<29;
const double EPS=1e-9;

const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};

int main(){
	int n;
	while(cin>>n,n){
		map<int,int> data;
		map<string,int> m;
		std::vector<int> v;
		string tmp;
		for(int i =0 ;i < n;i++){
			int x;
			cin>>x;
			stringstream ss;
			ss <<x;
			tmp +=ss.str();
			v.push_back(x);
			data[x]++;
		}
		//cout <<tmp<<endl;
		m[tmp]++;
		std::vector<int> ans;
		int cnt =0;
		map<int,int> t;
		while(1){
			string str ="";
			cnt++;
			ans.clear();
			t.clear();
			for(int i =0;i < v.size();i++){
				stringstream ss;
				ss <<data[v[i]];
				str +=ss.str();
				t[data[v[i]]]++;
				ans.push_back(data[v[i]]);
			}
			if(m[str]){
				break;
			}else{
				m[str]++;
			}
			//cout <<str<<endl;
			v=ans;
			data.clear();
			data =t;
		}
		cout <<cnt-1<<endl;
		for(int i =0;i < ans.size();i++){
			cout <<ans[i];
			if(i!=ans.size()-1)cout <<" ";
		}
		cout <<endl;
	}
	return 0;
}