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>
#include <vector>
#include <string>
#include <sstream>
#include <algorithm>
#include <map>
#include <set>
#include <cstdio>
#include <cmath>
#define rep(i,l,n) for(lint i=l;i<n;i++)
#define rer(i,l,n) for(lint i=l;i<=n;i++)
#define all(a) a.begin(),a.end()
#define o(a) cout<<a<<endl
#define pb(a) push_back(a)
#define mk(a,b) make_pair(a,b)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef vector<int> vi;
typedef vector<lint> vli;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

int main(){
	int n;
	string s;
	while(cin>>n){
		if(n==0) break;
		int ct=0;
		int s[13]={};
		rep(i,0,n){
			cin>>s[i];
		}
		int ans[13]={};
		for(ct=0;;ct++){
			rep(i,0,13){
				ans[i]=0;
			}
			int d[13]={};
			rep(i,0,n){
				d[s[i]]++;
			}
			rep(i,0,n){
				ans[i]=d[s[i]];
			}
			int c=0;
			rep(i,0,n){
				if(ans[i]==s[i]) c++;
			}
			if(c==n) break;
			rep(i,0,n){
				s[i]=ans[i];
			}
		}
		o(ct);
		rep(i,0,n){
			if(i==0) cout<<ans[i];
			else cout<<" "<<ans[i];
		}
		cout<<endl;
	}
}

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

int main()
{
    int n, s[12] = {0}, c[101] = {0};
    int p[12] = {0};

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

        int cnt = 0;
        bool judge = false;
        while( judge == false )
        {
            for( int i = 0; i < 101; i++ )
                c[i] = 0;

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

            for( int i = 0; i < n; i++ )
                s[i] = c[s[i]];

            for( int i = 0; i < n; i++ )
            {
                if( p[i] != s[i] )
                {
                    judge = false;
                    cnt++;
                    break;
                }
                else
                    judge = true;
            }
        }

        cout << cnt << endl;
        for( int i = 0; i < n; i++ )
        {
            cout << s[i];
            if( i != n - 1 )
                cout << " ";
        }
        cout << endl;
    }
    return 0;
}

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

using namespace std;

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

int main(int argc, char **argv)
{
	int n, *a, *b, *c, s;
	
	while(1){
		cin >> n;
		if(n == 0){
			break;
		}
		a = (int *)calloc(n+1, sizeof(int));
		b = (int *)calloc(n+1, sizeof(int));
		c = (int *)calloc(13, sizeof(int));
		for(int i = 0; i < n; i++){
			cin >> a[i];
			c[a[i]]++;
		}
		for(int i = 0; i < n; i++){
			b[i] = a[i];
			a[i] = c[a[i]];
		}
		s = 0;
		while(func(a, b, n)){
			for(int i = 0; i < n; i++){
				b[i] = a[i];
				a[i] = c[a[i]];
			}
			for(int i = 0; i < n; i++){
				c[i] = 0;
			}
			for(int i = 0; i < n; i++){
				c[a[i]]++;
			}
			s++;
		}
		cout << (s-1) << endl;
		for(int i = 0; i < n-1; i++){
			cout << a[i] << " ";
		}
		cout << a[n-1] << endl;
		
		free(c);
		free(b);
		free(a);
	}
	
	return 0;
}

C++: #include<stdio.h>
#include<iostream>
#include<list>
#include<map>
#include<math.h>
#include<vector>
#include<algorithm>
#include<string.h>
#include<iomanip>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) range(i,0,b)
#define debug(x) cout << "debug" << x << endl;
using namespace std;

int n, ans = 0;

void solve(int l1[], int count[]){
    int l2[13], sum = 0;
    int subcount[13] = {0};
    range(i, 1, n + 1){
        l2[i] = count[ l1[i] ];
        subcount[ l2[i] ]++;
    }
    range(i, 1, n + 1){
        sum+= l1[i] - l2[i];
    }
    if(sum != 0){
        ans++;
        solve(l2, subcount);
    }else{
        cout << ans << endl;
        range(i, 1, n + 1){
            if(i == 1) cout << l1[i];
            else cout << ' ' << l1[i];
        }cout << endl;
    }
}

int main(){
    int l1[13], l2[13];
    while(cin >> n, n){
        int count[13] = {0};
        range(i, 1, n + 1){
            cin >> l1[i];
            count[l1[i]]++;
        }
        ans = 0;
        solve(l1, count);
    }
}

C++: #include<iostream>
#include<string>
using namespace std;
int main() {
	int n;
	while (cin >> n&&n != 0) {
		int b[12],c=0;
		string e[2] = { "","" };
		int d[101];
		fill(d, d + 101, 0);
		for (int i = 0; i < n; i++) {
			cin >> b[i];
			e[1] += to_string(b[i]);
			d[b[i]]++;
		}
		string h = "";
		c = 0;
		while (e[0] != e[1]) {
			e[0] = e[1];
			e[1] = "";
			for (int i = 0; i < n; i++) 
				b[i] = d[b[i]];
			fill(d, d + 101, 0);
			for (int i = 0; i < n; i++) {
				d[b[i]]++;
				e[1] += to_string(b[i]);
			}
			c++;
		}
		cout << c - 1 << endl;
		for (int i = 0; i < n; i++) {
			if (i == 0)
				cout << b[i];
			else
				cout << " " << b[i];
		}
		cout << endl;
	}
}

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

bool comp_array(int *prev,int *fig,int size){
  for(int i=0;i<size;i++){
    if(prev[i] != fig[i]) return true;
  }
  return false;
}

int main(){
  int n;
  int prev[13],fig[13],tmp[13];
  while(cin >> n,n){
    int cont = 0;
    for(int i=0;i<n;i++) cin >> fig[i];
    while(comp_array(prev,fig,n)){
      cont++;
      copy(fig,fig+n,prev);
      for(int i=0;i<n;i++){
	int cnt = 0;
	for(int j=0;j<n;j++){
	  if(fig[i] == fig[j]) cnt++;
	}
	tmp[i] = cnt;
      }
      copy(tmp,tmp+n,fig);
    }
    cout << --cont << endl;
    for(int i=0;i<n;i++){
      cout << fig[i] << ((i == n-1)? "\n" : " ");
    }
  }
}

C++: #include <stdio.h>
int n, a[12], b[12];
int main() {
	while(true) {
		scanf("%d", &n);
		if(n == 0) break;
		for(int i = 0; i < n; i++) scanf("%d", &a[i]);
		int ret = 0;
		while(true) {
			for(int i = 0; i < n; i++) {
				b[i] = 0;
				for(int j = 0; j < n; j++) {
					if(a[i] == a[j]) {
						b[i]++;
					}
				}
			}
			bool flag = true;
			for(int i = 0; i < n; i++) {
				if(a[i] != b[i]) {
					flag = false;
				}
				a[i] = b[i];
			}
			if(flag) break;
			ret++;
		}
		printf("%d\n", ret);
		for(int i = 0; i < n; i++) {
			if(i) printf(" ");
			printf("%d", a[i]);
		}
	}
	return 0;
}

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,m;
		while(true)
		{
			int kazu[13] = {},hh = 0;
			for (int i = 0; i < n; i++)
				++kazu[retu[i]];
			for (int i = 0; i < n; i++)
			{
				mae[i] = retu[i];
				retu[i] = kazu[retu[i]];
			}
			for (int i = 0; i < n; i++)
			{
				hh += (retu[i] == mae[i]);
			}
			if(hh == n)
			{
				cout << ans << endl;
				break;
			}
			++ans;
		}
	}
}