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 <cstdio>
#include <algorithm>
#include <map>
using namespace std;
int arr[12], arr2[12];

int main(){
    int n, idx;
    bool flag;
    for(; ;) {
        scanf("%d", &n);
        if (n == 0) break;
        idx = 0;
        for (int i = 0; i < n; i++) scanf("%d", &arr[i]);

        for (; ;) {
            map<int, int> m;
            for (int i = 0; i < n; i++) {
                if (m.find(arr[i]) == m.end()) m.insert({arr[i], 1});
                else m[arr[i]]++;
            }
            for (int i = 0; i < n; i++) arr2[i] = m[arr[i]];
            flag = true;
            for (int i = 0; i < n; i++) if (arr[i] != arr2[i]) { flag = false; arr[i] = arr2[i]; };
            if (flag) break;
            else idx++;
        }
        printf("%d\n", idx);
        for (int i = 0; i < n; i++) { if(i) printf(" "); printf("%d", arr2[i]); }
        printf("\n");
    }
    return 0;
}

C++: #include<iostream>
#include<vector>
#include<queue>
#include<algorithm>
#include<string>
#include<map>
using namespace std;
#define rep(i,n) for(int i = 0 ; i < n ; i++ )

int main(){
  int N;
  while(cin >> N , N){
    int cnt = 0;
    vector<int> data(N);
    rep(i,N) cin >> data[i];
    while("homo"){
      vector<int> now = data;
      rep(i,N) now[i] = count(data.begin(),data.end(),data[i]);
      if(now == data) break;
      data = now;
      cnt++;
    }
    cout << cnt << endl;
    rep(i,N) cout << (i?" ":"") << data[i];
    cout << endl;
  }
}

C++: #include <bits/stdc++.h>

using namespace std;

typedef unsigned long long ull;
#define loop(i,a,b) for(int i=(a);i<ull(b);++i)
#define rep(i,n) loop(i,0,n)
#define all(a) (a).begin(), (a).end()

const double eps = 1e-10;
const double pi  = acos(-1.0);
const double inf = (int)1e8;

int main(){
	int n;
	while(cin >> n, n){
		vector<int> v(n);
		rep(i, n) cin >> v[i];
		int ret = 0;
		while(true){
			vector<int> vv(n);
			rep(i, n){
				int c = 0;
				rep(j, n) if(v[i] == v[j]) c++;
				vv[i] = c;
			}

			bool possible = true;
			rep(i, n) if(v[i] != vv[i]) possible = false;
			if(possible) break;
			rep(i, n) v[i] = vv[i];
			ret++;
		}
		cout << ret << endl;
		rep(i, n) cout << (i == 0 ? "" : " ") << v[i];
		cout << endl;
	}
}

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

vector<int>solve(vector<int>vec){
    vector<int>r;
    map<int,int>m;
    for(int i=0;i<vec.size();i++)
        m[vec[i]]++;
    for(int i=0;i<vec.size();i++)
        r.push_back(m[vec[i]]);
    return r;
}
int main(){
    int n,t,suc;
    while(cin>>n,n){
        vector<int>las,cur;
        while(n--){
            cin>>t;
            las.push_back(t);
        }
        t=0;
        while(1){
            cur=solve(las);
            suc=1;
            for(int i=0;i<cur.size();i++){
                if(cur[i]!=las[i]){
                    suc=0;
                    break;
                }
            }
            if(suc==1&&cur.size())break;
            for(int i=0;i<cur.size();i++)
                las[i]=cur[i];
            t++;
        }
        cout<<t<<endl;
        for(int i=0;i<cur.size()-1;i++)
            cout<<cur[i]<<" ";
        cout<<cur[cur.size()-1]<<endl;
    }
}

C++: #include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    while(cin>>n,n){
        int ans[2][12]={};
        for(int i=0;i<n;i++){
                cin>>ans[0][i];
                ans[1][i]=ans[0][i];
        }
        for(int i=0;;i++){
            int num[100]={};
            for(int j=0;j<n;j++)num[ans[0][j]]++;
            bool rever=1;
            for(int j=0;j<n;j++){
                ans[0][j]=num[kawa[j]];
                if(ans[0][j]!=ans[1][j])rever=0;
            }
            if(rever){
                cout<<i<<endl;
                for(int j=0;j<n-1;j++)cout<<ans[0][j]<<" ";
                cout<<ans[0][n-1]<<endl;
                break;
            }
            for(int j=0;j<n;j++)ans[1][j]=ans[0][j];
        }
    }
}

C++: #define _USE_MATH_DEFINES
#include "bits/stdc++.h"
using namespace std;

//#define int long long
#define DBG 1
#define dump(o) if(DBG){cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) if(DBG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#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 each(it,c) for(auto it=(c).begin();it!=(c).end();it++)
#define all(c) c.begin(),c.end()
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);
const double EPS = 1e-10;
vector<int> next(vector<int>v) {
	
	vector<int>res;
	rep(i, 0, v.size()) {
		res.push_back(count(all(v), v[i]));
	}
	return res;
}
signed main() {
	int n; cin >> n; vector<int>w,v(n); rep(i, 0, n)cin >> v[i];
	vector<int>c(101, 0);
	int cnt(0);
	while (1) {
		w = v;
		rep(i, 0, w.size())v[i] = count(all(w), w[i]);
		if (v == w)break;
		cnt++;
	}
	cout << cnt << endl;
	rep(i, 0, v.size()) cout << v[i] << (i == v.size() - 1 ? '\n' : ' ');

	return 0;
}

C++: //	created : 15/12/27
// 	autor   : Rp7rf
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <set>

using namespace std;
#define rep(i,a) for(int i = 0 ; i < a ; i ++)
#define loop(i,a,b) for(int i = 0 ; i < a ; i ++)
#define vi vector<int>


int main(void){
	int n;
	while(cin>>n,n){
		vi in(n),l(n);
		int ret = 0;
		rep(i,n)cin>>in[i];
		while(true){
			//rep(i,n)cout<<in[i]<<" ";cout<<endl;
			/*
			int cnt[13];
			rep(i,13)cnt[i]=0;
			rep(i,n)cnt[in[i]]++;
			rep(i,n)in[i] = cnt[in[i]];
			*/
			rep(i,n){
				l[i] = 0;
				rep(j,n)l[i] += (in[i] == in[j]);
			}
			if(in == l)break;
			ret ++;
			in = l;
		}
		cout<<ret<<endl;
		rep(i,n-1)cout<<in[i]<<" ";
		cout<<in[n-1]<<endl;
	}
}

C++: #include <iostream>
#include <map>
#include <vector>

using namespace std;

#define rep(i,n) for((i)=0;(i)<(int)(n);(i)++)
#define foreach(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)

int main(){
  int N,i;
  vector<int> s,in;
  map<int,int> mp;

  while(cin >> N){
    if(N == 0) break;

    s.clear(); in.clear();
    s.resize(N); in.resize(N);
    rep(i,N){
      cin >> in[i];
      s[i] = in[i];
    }

    int res = 0;
    while(1){
      mp.clear();
      rep(i,N) mp[s[i]]++;
      foreach(mp,itr) rep(i,N) if(s[i] == itr->first) s[i] = itr->second;
      if(s == in) break;
      in = s;
      res++;
    }

    cout << res << endl;
    rep(i,N){
      cout << s[i];
      if(i == N-1) cout << endl; else cout << ' ';
    }
  }

  return 0;
}