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<iomanip>
#include<algorithm>
#include<array>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<functional>
#include<limits>
#include<list>
#include<map>
#include<numeric>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<unordered_map>
#include<queue>
#include<vector>
using namespace std;

//#define int long long
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;

#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()
#define dump(o) {cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) {cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
const int MOD = 1e9 + 7;

signed main() {
	for (int n; cin >> n&&n;) {
		int cnt[2][110] = {};
		int s[110] = {};
		rep(i, 0, n) {
			cin >> s[i];
			cnt[0][s[i]]++;
		}
		int ans = 0;
		while (true) {
			fill(cnt[1], cnt[2], 0);
			rep(i, 0, n) {
				s[i] = cnt[0][s[i]];
				cnt[1][s[i]]++;
			}
			bool flag = true;
			rep(i, 0, n) {
				if (cnt[0][i] != cnt[1][i]) {
					flag = false; break;
				}
			}
			if (flag)break;
			swap(cnt[0], cnt[1]);
			ans++;
		}
		cout << ans << endl;
		cout << s[0];
		rep(i, 1, n)cout << " " << s[i];
		cout << endl;
	}
	return 0;
}

C++: #include <iostream>
using namespace std;
int main(){
	int i,j,n;
	while(cin >> n, n){
		int p,s[2][14]={0};
		for(i=1;i<=n;i++) cin >> s[0][i];
		for(p=1;;p++){
			for(i=1;i<=n;i++){
				s[1][i]=0;
				for(j=1;j<=n;j++) 
					if(s[0][j] == s[0][i]) s[1][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];
		}
		cout << p << endl;
		for(i=1;i<=n;i++) cout << s[1][i] << ' ';
		cout << endl;
	}
}

C++: #include <iostream>
#include <algorithm>
#include <cctype>
#include <cstdio>
#include <math.h>
#include <map>
#include <queue>
#include <string>
using namespace std;

int n,t,a[12],b[12],s[12];

int main(){
	while(cin>>n){
		if(n==0)return 0;
		for(int i=0;i<n;i++)cin>>a[i];
		t=0;
		while(1){
			for(int i=0;i<n;i++){b[i]=a[i];s[i]=0;}
			for(int i=0;i<n;i++)for(int j=0;j<n;j++)if(a[j]==a[i])s[i]++;
			for(int i=0;i<n;i++)a[i]=s[i];
			bool same=true;
			for(int i=0;i<n;i++)if(a[i]!=b[i])same=false;
			if(same){
				cout<<t<<endl;
				for(int i=0;i<n;i++){cout<<a[i];if(n!=n-1)cout<<" ";}
				cout<<endl;
				break;
			}
			t++;
		}
	}
}