Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

func main() {
	stdin := bufio.NewScanner(os.Stdin)
	for stdin.Scan() {
		n, _ := strconv.Atoi(stdin.Text())
		if n == 0 {
			break
		}
		stdin.Scan()
		res := stdin.Text()
		prev := ""
		c := 0
		for ; res != prev; c++ {
			elm := strings.Split(res, " ")
			cnt := make(map[string]int)
			nxt := make([]string, n)
			for _, v := range elm {
				cnt[v]++
			}
			for i, v := range elm {
				nxt[i] = strconv.Itoa(cnt[v])
			}
			prev = res
			res = strings.Join(nxt, " ")
		}
		if res == prev {
			fmt.Println(c - 1)
			fmt.Println(res)
		}
	}
}

C++: #include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iostream>
#include <cctype>
#include <sstream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <complex>
#include <fstream>
#include <iomanip>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b){ if(a < b) a = b; }
template<class T, class C> void chmin(T& a, C b){ if(b < a) a = b; }
template<class T, class C> pair<T, C> mp(T a, C b){ return make_pair(a, b); }


bool check(vint s, int n)
{
	rep(i, n) if(s[i] != count(ALL(s), s[i]))
		return false;

	return true;
}


int main()
{
	int n;
	while(cin >> n && n)
	{
		vint s(n);
		int res = 0;

		rep(i, n)
			cin >> s[i];

		while(!check(s, n))
		{
			vint prv = s;

			rep(i, n)
				s[i] = count(ALL(prv), s[i]);

			res++;
		}

		cout << res << endl;
		rep(i, n)
			cout << s[i] << (i + 1 == n ? "\n" : " ");
	}
}

C++: #include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <string>
#include <bitset>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <sstream>
#include <fstream>
#include <string.h>

#define X first
#define Y second
#define MP make_pair
#define FOR(i, n) for(int (i) = 0; (i) < (n); (i)++)
typedef long long ll;
using namespace std;
const int MAX = 101;

template<class T, class U>
void convert(T &t, U &u){
    stringstream ss;
    ss << t;
    ss >> u;
}

int main(){
	int n;
	while(cin >> n && n){
		vector<int> seq(n, 0);
		map<int, int> tb;
		int c = 0;
		FOR(i, n) cin >> seq[i];
		while(1){
			vector<int> seq2(n, 0);
			bool f = true;

			FOR(i, n) tb[seq[i]]++;

			FOR(i, n){
				seq2[i] = tb[seq[i]];
				if(seq2[i]!=seq[i]) f = false;
			}

			if(f){
				cout << c << endl;
				FOR(i, n){
					if(i) cout << " ";
					cout << seq[i];
				}
				cout << endl;
				break;
			}else{
				seq = seq2;
				map<int, int>().swap(tb);
				c++;
			}
		}
	}
	return 0;
}

C++: #include <iostream>
#include <vector>
#include <map>

using namespace std;

void solve()
{
	int n;
	while(cin >> n, n)
	{
		vector<int> Vec(n);
		for(int i = 0; i < n; ++i)
		{
			cin >> Vec[i];
		}
		
		bool flag = true;
		int count = 0;
		while(flag)
		{
			map<int, int> Map;
			for(int i = 0; i < n; ++i)
			{
				Map[Vec[i]]++;
			}
			vector<int> Vec_buf(n);
			for(int i = 0; i < n; ++i)
			{
				for(map<int, int>::iterator Ite = Map.begin(); Ite != Map.end(); ++Ite)
				{
					if((*Ite).first == Vec[i])
					{
						Vec_buf[i] = (*Ite).second;
					}
				}
			}
			if(Vec == Vec_buf)
			{
				flag = false;
			}
			Vec = Vec_buf;
			count++;
		}
		count--;
		cout << count << endl;
		for(int i = 0; i < n - 1; ++i)
		{
			cout << Vec[i] << " ";
		}
		cout << Vec[n - 1] << endl;
	}
}

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

C++: //48
#include<iostream>
#include<vector>

using namespace std;

int main(){
  for(int n;cin>>n,n;){
    vector<int> v(n);
    for(int i=0;i<n;i++){
      cin>>v[i];
    }
    int ans;
    for(ans=0;;ans++){
      vector<int> temp(n);
      for(int i=0;i<n;i++){
	for(int j=0;j<n;j++){
	  temp[i]+=v[i]==v[j];
	}
      }
      if(v==temp)break;
      v=temp;
    }
    cout<<ans<<endl;
    for(int i=0;i<n;i++){
      cout<<v[i]<<((i+1==n)?'\n':' ');
    }
  }
  return 0;
}

C++: #define _USE_MATH_DEFINES
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>

using namespace std;

typedef long long ll;
typedef pair<int,int> P;

int main(){
	int n;
	while(~scanf("%d",&n)){
		if(n==0) break;
		vector<int> S;
		vector<int> S_old;
		for(int i=0;i<n;i++){
			int s;
			scanf("%d",&s);
			S.push_back(s);
			S_old.push_back(-1);
		}

		int c=0;
		while(1){
			map<int,int> freq;
			for(int i=0;i<S.size();i++){
				freq[S[i]]++;
			}

			for(int i=0;i<S.size();i++){
				S[i] = freq[S[i]];
			}

			bool isok=true;
			for(int i=0;i<S.size();i++){
				if(S_old[i] != S[i]){
					isok=false;
					break;
				}
			}
			c++;
			if(isok) break;

			S_old = S;
		}

		cout << c-1 << endl;
		for(int i=0;i<S.size();i++){
			printf("%d%s",S[i],i==S.size()-1 ? "\n" : " ");
		}

	}
}

C++: #include <iostream>
#include <cstdio>
using namespace std;

int main(){
	while(1){	
		int n, count=0;
		long before[13], after[13], c[13];
	
		scanf(" %d", &n);
		if(n==0) break;
		for(int i=0; i<n; ++i)scanf(" %ld", &before[i]);
				
		//loop
		while(1){
			
			for(int i=0; i<=12; ++i) c[i]=0;
			
			for(int i=0; i<n; ++i){
				for(int j=0; j<n; ++j){
					if(before[i] == before[j]) c[i]++;
				}
			}
				
			for(int i=0; i<n; ++i) after[i]=c[i];	
			
			bool flag=true;
			for(int i=0; i<n; ++i){
				if(before[i]!=after[i]){
					flag=false;
					break;	
				}
			}
			if(flag) break;
			
			/*
			for(int i=0; i<n; ++i){
				printf("%ld", after[i]);
				if(i<n-1) printf(" ");
			}
			printf("\n");
			*/
			
			count++;
			for(int i=0; i<n; ++i) before[i]=after[i];
		}
		
		printf("%d\n", count);
		for(int i=0; i<n; ++i){
			printf("%ld", after[i]);
			if(i<n-1) printf(" ");
		}
		printf("\n");
	}
	return 0;
}

C++: #include <iostream>
#include <string>
#include <cstring>
#include <vector>
#include <cstdlib>
#include <map>

#define rep(i,n) for(int i=0;i<n;i++)

using namespace std;

int main()
{
	int a[13];
	int n;
	while(cin >> n && n)
	{
		memset(a,0,sizeof(a));
		vector<int> res;
		rep(i,n) 
		{
			cin >> a[i];
			res.push_back(a[i]);
		}
		
		int count = 0;
		while(true)
		{
			map<int,int> m;

			rep(i,n)
			{
				m[a[i]]++;
			}

			rep(i,n)
			{
				a[i] = m[a[i]];
			}

			bool flag = true;
			rep(i,n)
			{
				if(res[i] != a[i])
				{
					flag = false;
				}
			}

			if(flag)
			{
				cout << count << endl;
				rep(i,n)
				{
					if(i == n-1) cout << a[i] << endl;
					else cout << a[i] << " ";
				}
				break;
			}
			else
			{
				rep(i,n)
				{
					res[i] = a[i];
				}
				count++;
			}
		}
	}
	return 0;
}

C++: #include <iostream>
#include <vector>
using namespace std;

void pr(vector<int> &v1) {
  for(int j = 0; j < (int)v1.size(); ++j) {
	cout << v1[j];
	cout << (j < (int)v1.size() - 1 ? " " : "\n");
  }
}
void op(vector<int> &v1) {
  vector<int> v2 = v1;
  for(int i = 0; i < (int)v1.size(); ++i) {
	int cnt = 0;
	for(int j = 0; j < (int)v1.size(); ++j) {
	  if(v1[j] == v1[i]) {
		cnt++;
		v2[j] = -1;
	  }
	}
	for(int j = 0; j < (int)v2.size(); ++j) {
	  if(v2[j] == -1) {
		v2[j] = cnt;
	  }
	}
  }
  if(v2 != v1) op(v2);
  else pr(v1);
}

int main() {
  int n;
  while(cin >> n && n) {
	vector<int> v(n);
	for(int i = 0; i < n; ++i) {
	  cin >> v[i];
	}
	op(v);
  }
  return 0;
}