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"

#define REP(i,num) for(int i=0;i<(num);++i)
#define ALL(c) c.begin(),c.end()
#define LOOP(i) while(i--)
#define PRINTALL(c) for(auto pitr=c.begin();pitr!=c.end();++pitr){cout<<*pitr;if(next(pitr,1)!=c.end())cout<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);

	while(true){
		int N=in();
		if(!N) break;
		auto A=vecin(N);

		int num=0;
		while(true){
			int f=0;
			map<int,int> C;
			REP(i,N) C[A[i]]++;
			REP(i,N){
				if(A[i]!=C[A[i]]){
					f++;
					A[i] = C[A[i]];
				}
			}
			if(!f) break;
			num++;
		}
		out(num);
		PRINTALL(A);
	}
	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=1;i < n; i++){
					if(table[array[i]] != table[array[i-1]]){
						FLG = false;
						break;
					}
				}
			}else{
				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++;
		}

		if(count == 0){
			printf("0\n");
		}else{
			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<vector>
#include<map>
using namespace std;

int main()
{
	int n, i, count, f;
	vector<int> s;
	map<int, int> m;
	while (cin>>n, n) {
		s.clear();
		for (i = 0; i < n; i++) {
			cin>>count;
			s.push_back(count);
		}

		f = 0;
		count = 0;
		while (f!=n) {
			f = 0;
			count++;

			m.clear();
			for (i = 0; i < n; i++) {
				if (m.count(s[i])) m[s[i]]++;
				else m[s[i]] = 1;
			}
			for (i = 0; i < n; i++) {
				if (s[i]==m[s[i]]) f++;
				s[i] = m[s[i]];
			}
		}
		cout<<--count<<endl;
		for (i = 0; i < n; i++) {
			if (i) cout<<" ";
			cout<<s[i];
		}
		cout<<endl;
	}
	return 0;
}

C++: #include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main()
{
    for(;;){
        int n;
        cin >> n;
        if(n == 0)
            return 0;

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

        int ret = 0;
        for(;;){
            map<int, int> num;
            for(int i=0; i<n; ++i)
                ++ num[s[i]];
            vector<int> c(n);
            for(int i=0; i<n; ++i)
                c[i] = num[s[i]];
            if(s == c){
                cout << ret << endl;
                cout << s[0];
                for(int i=1; i<n; ++i)
                    cout << ' ' << s[i];
                cout << endl;
                break;
            }
            s = c;
            ++ ret;
        }
    }
}

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[13], c[12], t=0, s;
		for(int i = 0; i < n; i++){
			cin >> a[i];
		}
		fill(c, c+n, 0);
		while(1){
			fill(b, b+13, 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>
#include <string>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <set>
#include <vector>
#include <map>
#define loop(i,a,b) for(int i=a; i<b; i++)
#define rep(i,b) loop(i,0,b)
#define all(c) (c).begin(), (c).end()

using namespace std;

typedef vector<int> vi;

string const res[] = { "NA", "OK" };

int main(){
    int n;
    while (cin >> n && n){
        vi v(n);
        int c = 0;
        rep(i, n) cin >> v[i];
        while(1){
            vi next(n);
            map<int, int> m;
            rep(i, n) m[v[i]]++;
            rep(i, n) next[i] = m[v[i]];
            if (next == v) break;
            c++;
            v = next;
        }

        cout << c << endl;
        rep(i, n - 1){
            cout << v[i] << " ";
        }
        cout << v.back();
    }
}

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]);
        }
        printf("\n");
    }
    return 0;
}

C++: #include<iostream>


using namespace std;

int main(){
	int in;

	while(cin >> in){
		int rev = 0, max = 0;

		if(in == 0) break;

		int data[in];

		for(int i = 0; i < in; i++){
			cin >> data[i];
			if(data[i] < max) max = data[i];
		}

		int sum[max];

		while(1){

			for(int	i = 0; i < max; i++){
				sum[i] = 0;
			}
		
			for(int i = 0; i < in; i++){
				sum[data[i]]++;
			}
			for(int i = 0; i < in; i++){
				data[i] = sum[data[i]];
			}
			int status = 0;

			for(int i = 0; i < in; i++){
				if(data[i] != sum[data[i]]) status = 1;
			}

			if(status == 0){
				cout << rev << endl;
				for(int i = 0; i < in; i++){
					cout << data[i] << " ";
				}
				cout << endl;
				break;
			}
			rev++;
		}
	}

	return 0;
}