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 <sstream>
#include <iostream>
#include <string>
#include <vector>
#include <map>

using namespace std;

#define MAX_ELEMENT 12
#define MAX_LINE 200

void calculate(vector<vector<int>>& calcVec) {
	map<int, int> calcMap, checkMap;
	int cnt, i, j;
	bool check;
	for (i = 0; i < calcVec.size(); i++) {
		for (j = 0; j < calcVec[i].size(); j++) {
			calcMap[calcVec[i][j]]++;
		}
		cnt = 1;
		while (cnt) {
			check = true;
			for (j = 0; j < calcVec[i].size(); j++) {
				calcVec[i][j] = calcMap[calcVec[i][j]];
				checkMap[calcVec[i][j]]++;
			}
			for (j = 0; j < calcVec[i].size(); j++) {
				check &= (calcVec[i][j] == checkMap[calcVec[i][j]]);
			}
			if (check)break;
			calcMap = checkMap;
			checkMap.clear();
			cnt++;
		}
		printf("%d\n",cnt);
		for (j = 0; j < calcVec[i].size(); j++) {
			printf("%d ", calcVec[i][j]);
		}
		printf("\n");
		calcMap.clear();
		checkMap.clear();
	}
}

void getInputValue(vector<vector<int>>& calcVec) {
	string num, buf1, buf2;
	vector<int> vec;
	for (int i = 0; i < MAX_LINE; i++) {
		getline(cin, num);

		int ele_length = atoi(num.c_str());
		if (!ele_length) { break; }

		vec.reserve(ele_length);
		getline(cin, buf1);
		stringstream ss(buf1);
		while (getline(ss, buf2, ' ')) {
			int value = atoi(buf2.c_str());
			if (!value) { break; }
			if (ele_length == vec.size()) { break; }
			vec.emplace_back(value);
		}
		calcVec.push_back(vec);
		vec.clear();
	}
}


int main() {
	vector<vector<int>> calcVec;
	getInputValue(calcVec);
	calculate(calcVec);
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
int main(void){
    int n,a;
    while (cin>>n) {
        if (n==0) {
            break;
        } else {
            std::deque<int> deq;
            for (int i=0;i<n;i++) {
                cin>>a;
                deq.emplace_back(a);
            }
            std::map<int, int> map;
            int count=0;
            while (1) {
                map.clear();
                count++;
                for (int i=0;i<n;i++) {
                    map[deq[i]]++;
                }
                int tmp=0;
                for (int i=0;i<n;i++) {
                    if (deq[i]==map[deq[i]]) {
                        tmp++;
                    } else {
                        deq[i]=map[deq[i]];
                    }
                }
                if (tmp==n) {
                    cout<<count-1<<endl;
                    for (int i=0;i<n;i++) {
                        cout<<deq[i];
                        if (i!=n-1) {
                            cout<<" ";
                        } else {
                            cout<<endl;
                        }
                    }
                    break;
                }
            }
        }
    }
}

C++: #include<iostream>

int main(){
	int n;
	while(std::cin>>n){
		int ans=0,data[12],back[12];
		if(n==0)break;
		for(int i=0;i<n;i++)std::cin>>data[i],back[i]=data[i];
		while(true){
			for(int i=0;i<n;i++){
				int count=0;
				for(int j=0;j<n;j++){
					if(back[i]==back[j])count++;
				}
				data[i]=count;
			}
			bool f=true;
			for(int i=0;i<n;i++){
				if(data[i]!=back[i])f=false;
			}
			if(f)break;
			for(int i=0;i<n;i++)back[i]=data[i];
			ans++;
		}
		std::cout<<ans<<std::endl;
		for(int i=0;i<n;i++)std::cout<<data[i]<<" ";
		std::cout<<std::endl;
	}
	return 0;
}

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

int a[12];
int udo[12];
int n;

void cp(void){
	for(int i=0;i<12;i++){
		udo[i]=a[i];
	}
}

bool check(void){
	for(int i=0;i<12;i++){
		if(udo[i]!=a[i])return false;
	}
	return true;
}

int main(void){
	int c;
	while(cin>>n,n){
		for(int i=0;i<n;i++){cin>>a[i];udo[i]=0;}
		for(c=0;!check();c++){
			map<int,int> m;
			for(int i=0;i<n;i++){
				m[a[i]]++;
			}
			cp();
			for(int i=0;i<n;i++){
				a[i]=m[a[i]];
			}
			if(check())break;
		}
		cout<<c<<endl;
		for(int i=0;i<n;i++){
			if(i!=n-1)cout<<a[i]<<" ";
			else cout<<a[i];
		}
		cout<<endl;
	}
}

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

bool jug(int* s1, int* s2, int len){
    for(int i = 0; i < len; ++i) {
        if (s1[i] != s2[i]) return false;
    }
    return true;
}
int main(){
    int n,count,tmp,x;
    int* s = new int[12];
    int* ans = new int[12];
    while(true) {
        cin >> n;
        if (n ==  0) {
            break;
            cout << endl;
        }
        for(int i = 0; i < n; ++i) {
            cin >> s[i];
        }
        x = 0;
        while(true){
            for(int i = 0; i < n; ++i) {
                count = 0;
                for(int j = 0; j < n; ++j) {
                    if (s[i] == s[j]) {
                        ++count;
                    }
                }
                ans[i] = count;
            }
            if (jug(s, ans, n)) break;
            x++;

            for (int i = 0; i < n; i++) {
                tmp = s[i];
                s[i] = ans[i];
                ans[i] = tmp;
            }
        }
        cout << x << endl;
        for (int i = 0; i < n; i++) {
            cout << s[i];
            if (i == n-1) {
                break;
            }
            cout << " ";
        }
        cout << endl;
    }
    delete s;
    delete ans;
}

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[12], sum = 0;
    int subcount[13] = {0};
        rep(i, n){
            l2[i] = count[ l1[i] ];
            subcount[ l2[i] ]++;
        }
        rep(i, n){
            l1[i] = l2[i];
            count[i] = subcount[i];
            sum+= count[ l1[i] ] - l1[i];
        }
        ans++;
        if(sum) solve(l1, count);
}

int main(){
    int l1[13], l2[13];
    while(cin >> n, n){
        int count[13] = {0};
        rep(i, n){
            cin >> l1[i];
            count[l1[i]]++;
        }
        ans = 0;
        solve(l1, count);
        cout << ans - 1 << endl;
        rep(i, n){
            if(i == 0);
            else if(i == 1) cout << l1[i];
            else cout << ' ' << l1[i];
        }cout << endl;
    }
}