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<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    while(cin>>n,n){
        int ans[12]={},kawa[12];
        for(int i=0;i<n;i++){
                cin>>kawa[i];
                ans[i]=kawa[i];
        }
        for(int i=0;;i++){
            int num[100]={};
            for(int j=0;j<n;j++)num[kawa[j]]++;
            bool rever=1;
            for(int j=0;j<n;j++){
                kawa[j]=num[kawa[j]];
                if(kawa[j]!=ans[j])rever=0;
            }
            if(rever){
                cout<<i<<endl;
                for(int j=0;j<n-1;j++)cout<<kawa[j]<<" ";
                cout<<ans[n-1]<<endl;
                break;
            }
            for(int j=0;j<n;j++)ans[j]=kawa[j];
        }
    }
}

C++: #include <iostream>

using namespace std;

int n, m;
int S[12], oldS[12], memo[2][12];

void init(void);
void ope(void);
void change(void);
int check(void);
int search(int num);

int main() {
	int ans;

	while (cin >> n) {
		if (n == 0) break;

		for (int i = 0; i < n; i++)
			cin >> oldS[i];
		
		init();
		ope();
		ans = 0;
		m = 0;
		while (check()) {
			change();
			ope();
			ans++;
		}

		cout << ans << endl;
		for (int i = 0; i < n; i++) {
			cout << S[i];
			if (i < 11)
				cout << " ";
		}
		cout << endl;
	}
}

void init(void) {
	for (int i = 0; i < 2; i++) {
		for (int j = 0; j < 12; j++) {
			memo[i][j] = -1;
		}
	}
}

void ope(void) {
	int num, cont;
	for (int i = 0; i < n; i++) {
		num = oldS[i];
		cont = 0;
		if (search(num)) {
			cont = search(num);
		}
		else {
			for (int j = 0; j < n; j++) {
				if (oldS[j] == num)
					cont++;
			}
			memo[0][m] = num;
			memo[1][m] = cont;
		}
		S[i] = cont;
	}
}

void change(void) {
	for (int i = 0; i < n; i++) {
		oldS[i] = S[i];
	}
}

int check(void) {
	for (int i = 0; i < n; i++) {
		if (oldS[i] != S[i])
			return 1;
	}

	return 0;
}

int search(int num) {
	for (int i = 0; i < 12; i++) {
		if (memo[0][i] == num) {
			return memo[1][i];
		}
	}

	return 0;
}

C++: #include <stdio.h>
#include<math.h>
#include <algorithm>

using namespace std;


int main(){

	int n,table[101],count;
	bool FLG;

	while(true){
		scanf("%d",&n);
		if(n == 0)break;

		for(int i=0; i< 101; i++)table[i] = 0;
		int array[n],pre[n];
		count = 0;

		for(int i=0; i< n; i++){
			scanf("%d",&array[i]);
			table[array[i]]++;
		}

		while(true){
			FLG = true;

			if(count != 0){
				for(int i=0; i < n; i++){
					if(array[i] != pre[i]){
						FLG = false;
						break;
					}
				}
				if(FLG)break;
			}

			for(int i=0; i< n; i++){
				pre[i] = array[i];
				array[i] = table[array[i]];
			}

			for(int i=0; i< 101; i++)table[i] = 0;

			for(int i=0; i < n; i++)table[array[i]]++;
			count++;
		}

		printf("%d\n",count-1);

		printf("%d",array[0]);
		for(int i=1; i<n; i++)printf(" %d",array[i]);
		printf("\n");

	}

    return 0;
}

C++: #include <iostream>
#include <algorithm>

using namespace std;

bool check(int a[12], int b[12], int n)
{
	bool f = true;
	
	for(int i = 0; i < n; i++){
		if(a[i] != b[i]){
			f = false;
			break;
		}
	}
	
	return f;
}

int main()
{
	int n;
	
	while(cin>>n && n){
		int a[12], b[10000], c[12], t=0, s;
		for(int i = 0; i < n; i++){
			cin >> a[i];
		}
		fill(c, c+n, -1);
		while(1){
			fill(b, b+10000, 0);
			for(int i = 0; i < n; i++){
				b[a[i]]++;
			}
			s = 1;
			for(int i = 1; i <= n; i++){
				s = max(b[s], b[i]);
			}
			if(check(a, c, n)){
				break;
			}
			
			for(int i = 0; i < n; i++){
				c[i] = a[i];
				a[i] = b[a[i]];
			}
			t++;
		}
		
		cout << (t-1) << endl;
		cout << a[0];
		for(int i = 1; i < n; i++){
			cout << " " << a[i];
		}
		cout << endl;
	}
	
	return 0;
}

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

int main(){
	int n;
	int C[12];
	while(1){
		cin >> n;
		if(n == 0) break;
		for(int i=0;i<n;i++){
			cin >> C[i];
		}
		int ans = 0;
		int cou = 0;
		while(1){
			if(cou == n) break;
			cou = 0;
			int k[12]={0};
			for(int i=0;i<n;i++){
				int tmp = C[i];
				for(int j=0;j<n;j++){
					if(tmp == C[j]){
						k[i]++;
					}
				}
			}
			for(int i=0;i<n;i++){
				if(C[i] == k[i]){
					cou++;
				}
				C[i] = k[i];
			}
			ans++;
		}
		ans--;
		cout << ans << endl;
		for(int i=0;i<n;i++){
			cout << C[i];
			if(n != i+1) cout << " ";
		}
		cout << endl;
	}
}

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

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

C++: #include<iostream>
#include<cmath>
#include<vector>
#include<algorithm>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;

int main(){
  int n;
  while(cin>>n,n){
    vector<int>in1(n);
    vector<int>in2(n);
    int count=0;
    rep(i,n)cin>>in1[i];
    while(1){
      count++;
      bool h=true;
      rep(i,in1.size()){
	int co=0;
	rep(j,in1.size()){
	  if(in1[j]==in1[i])co++;
	}
	in2[i]=co;
	//cout<<co<<endl;
	if(in1[i]!=co)h=false;
      }
      if(h)break;
      //
      count++;
      h=true;
      rep(i,in2.size()){
	int co=0;
	rep(j,in2.size()){
	  if(in2[j]==in2[i])co++;
	}
	in1[i]=co;
	if(in2[i]!=co)h=false;
      }
      if(h)break;
    }
    cout<<count-1<<endl;
    cout<<in1[0];
    rep(i,in1.size()-1)cout<<" "<<in1[i+1];
    cout<<endl;
  }
}


  /*
  while(cin>>n,n){
    int co=0;
    vector< vector<int> >in(n);
    rep(i,n)cin>>in[0][i];
    do{
      vector<int>n;
      vector<int>num;
      rep(i,in[co].size()){
	bool han=false;
	int a;
	rep(j,n.size())if(num[j]==in[co][i]){a=j;han=true;}
	if(han){
	  n[a]++;
	}else{
	  n.push_back(in[co][a]);
	  num.push_back(1);
	}
      }
      rep(i,in[co].size()){
	rep(i,num.size())if(in[co][i]==num[
	in[co+1][i]=


      bool han1=false;
      
    }while();*/

C++: #include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <iostream>
#include <climits>
#include <cfloat>


using namespace std;

int main()
{
	int n;
	while (scanf("%d", &n), n)
	{
		int hoge[2][32];
		for (int i = 0; i < n; ++i)
		{
			int t;
			scanf("%d", &t);
			hoge[0][i] = t;
		}

		for (int i = 0; ; ++i)
		{
			int* cur = hoge[i & 1];
			int* next = hoge[(i+1) & 1];
			map<int, int> c;
			for (int j = 0; j < n; ++j)
				++c[cur[j]];

			for (int j = 0; j < n; ++j)
				next[j] = c[cur[j]];

			bool eq = true;
			for (int j = 0; eq && j < n; ++j)
				eq = cur[j] == next[j];

			if (eq)
			{
				printf("%d\n", i);
				for (int j = 0; j < n; ++j)
				{
					printf("%d", cur[j]);
					if (j != n-1)
						printf(" ");
					else
						printf("\n");
				}
				break;
			}
		}
	}

	return 0;
}