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 <iostream>
using namespace std;

int main()
{
	int n;
	while(cin >> n,n != 0)
	{
		int retu[13] = {},mae[13] = {};
		for (int i = 0; i < n; i++)
			cin >> retu[i];
		int ans = 0;
		while(true)
		{
			int kazu[13] = {};
			for (int i = 0; i < n; i++)
			{
				mae[i] = retu[i];
				++kazu[retu[i]];
			}
			for (int i = 0; i < n; i++)
				retu[i] = kazu[retu[i]];
			int h = 0;
			for (int i = 0; i < n; i++)
				h += (mae[i] == retu[i]);
			if(h == n)
			{
				cout << ans << endl;
				break;
			}
			++ans;
		}
	}
}

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

int main(){
	int n;
	while(1){
		cin >> n;
		if(n==0) break;
		int a[n];
		int e = 0;
		for(int i=0;i<n;i++) cin >> a[i];
		while(1){
			int b[n+1],c[n];
			for(int i=0;i<n;i++) b[i] = 0;
			for(int i=0;i<n;i++) b[a[i]]++;
			for(int i=0;i<n;i++) c[i] = b[a[i]];
			int d = 0;
			for(int i=0;i<n;i++) if(a[i]==c[i]) d++;
			if(d==n) break;
			e++;
			for(int i=0;i<n;i++) a[i] = c[i];
		}
		cout << e << endl;
		cout << a[0];
		for(int i=1;i<n;i++) cout << " " << a[i];
		cout << endl;
	}
}

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

int ans[115][2][12];//二つ目の次元の0の0に数列の長さ、0の1に操作回数、1に答えの数列

int counter=0,flag=0;

void solve(){
	int n;
	cin >> n;
	if(n==0){flag=1;return;}
	ans[counter][0][0]=n;
	
	int S[12];//数列
	for(int i=0;i<n;i++){
		cin >> S[i];
	}
	
	bool check=false;//操作の有無のフラグ
	int time=0;//操作回数
	do{
		map<int,int> marker;
		for(int i=0;i<n;i++){
			marker[S[i]];
			marker[S[i]]++;
		}
		check=false;
		for(int i=0;i<n;i++){
			if(S[i]!=marker[S[i]]){
				check=true;
				S[i]=marker[S[i]];
			}
		}
		if(check) time++;
	}while(check);
	
	ans[counter][0][1]=time;
	for(int i=0;i<n;i++){
		ans[counter][1][i]=S[i];
	}
	counter++;
}

int main(){
	while(flag==0)solve();
	for(int i=0;i<counter;i++){
		cout << ans[i][0][1] << endl;
		for(int j=0;j<ans[i][0][0]-1;j++){
			cout << ans[i][1][j]<<" ";
		}
		cout << ans[i][1][ans[i][0][0]-1] << endl;
	}
}

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

int main(void)
{
    while (1){
        int n;
        scanf("%d", &n);
        if (!n) break;
        int num[13] = {0};
        int prev[13] = {0};
        int ans = 0;
        for (int i = 0; i < n; i++){
            scanf("%d", &num[i]);
        }
        while (1){
            ans++;
            for (int i = 0; i < n; i++){
                prev[i] = 0;
                for (int j = 0; j < n; j++){
                    if (num[i] == num[j]){
                        prev[i]++;
                    }
                }
            }
/*            printf("%d\n", ans);
            for (int i = 0; i < n; i++){
                printf("%d", prev[i]);
                ((i + 1) == n) ? printf("\n") : printf(" ");
            }*/
            
            bool flag = true;
            for (int i = 0; i < n; i++){
                if (num[i] != prev[i]) flag = false;
            }
            if (flag) break;
            
            for (int i = 0; i < n; i++){
                num[i] = prev[i];
            }
        }
        printf("%d\n", ans - 1);
        for (int i = 0; i < n; i++){
            printf("%d", num[i]);
            ((i + 1) == n) ? printf("\n") : printf(" ");
        }
    }
    
    return (0);
}

C++: #include <iostream>
using namespace std;
int main(){
	int i,n;
	while(cin >> n, n){
		int p,s[3][14]={0};
		for(i=1;i<=n;i++) cin >> s[0][i]; 
//		for(i=1;i<=n;i++) cout << s[0][i] << ' ';
		for(p=0;;p++){
			for(i=1;i<=n;i++) s[2][s[0][i]] ++;
			for(i=1;i<=n;i++) s[1][i] = s[2][s[0][i]];			
			for(i=1;i<=n;i++) if(s[0][i] != s[1][i]) break;
			if(i>n) break;
			for(i=1;i<=n;i++){
				s[0][i] = s[1][i];
				s[2][i] = 0;
			}
		}
		cout << p << '\n';
		for(i=1;i<=n;i++) cout << s[1][i] << ' ';
		cout << '\n';
	}
	return 0;
}

C++: #include <iostream>
using namespace std;
bool issame(int *a,int *b,int n){
	for(int i = 0;i < n;++i){
		if(a[i] != b[i]) return false;
	}
	return true;
}
int main(){
	int n,seq[12],count,tmp[12];
	bool f;
	while(cin >> n,n){
		f = false;
		count = 0;
		for(int i = 0;i < n;++i){
			cin >> seq[i];
		}
		while(!f){
			for(int i = 0;i < n;++i){
				int same = 0;
				for(int j = 0;j < n;++j){
					if(seq[i] == seq[j]) ++same;
				}
				tmp[i] = same;
			}
			++count;
			f = issame(seq,tmp,n);
			for(int i = 0;i < n;++i){
				seq[i] = tmp[i];
				tmp[i] = 0;
			}
		}
		cout << count - 1 << endl;
		for(int i = 0;i < n;++i){
			if(i) cout << " ";
			cout << seq[i];
		}
		cout << endl;
	}
	return 0;
}

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

int main() {
  int n;
  while(cin >> n) {
    int s[10000] = {0},c[10000] = {0},c2[10000] = {0},k,check=1;
    if(n==0)break;

    for(int i=0;i<n;i++) {
      cin >> s[i];
    }

    for(int i=0;i<n;i++) {
      for(int j=0;j<n;j++) {
        if(s[i] == s[j]) {
          c[i]++;
        }
      }
    }

    //ok
    k=1;
    while(check){
      check = 0;

      int c2[10000] = {0};
      for(int i=0;i<n;i++) {
        for(int j=0;j<n;j++) {
          if(c[i] == c[j]) {
            c2[i]++;
          }
        }
      }
      for(int i=0;i<n;i++) {
        if(c2[i] != c[i]) {
          for(int j=0;j<n;j++) {
            c[j] = c2[j];
          }
          check = 1;
          k++;
        }
      }

    }
    if(k != 1)
    cout << k << endl;
    else
      cout << k-1 << endl;
    for(int i=0;i<n;i++) {
      cout << c[i] << " ";
    }
    cout << "\b" << endl;
  }
}