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(int 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;
	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 <algorithm>
#include <string>
#include <iostream>
using namespace std;


bool mani(int a[12], int n)
{
	int b[12];
	fill(b, b + 12, 0);
	for (int i = 0; i < n; i++)
		for (int j = 0; j < n; j++)
			if (a[i] == a[j])
				b[i]++;
	bool f = true;
	for (int i = 0; i < n; i++)
	{
		if (a[i] != b[i])
		{
			f = false;
			break;
		}
	}
	for (int i = 0; i < n; i++)
		a[i] = b[i];
	return f;
}


int main()
{
	int n, a[12];
	cin >> n;
	while (true)
	{
		int c = 0;
		int it = 0;
		while (cin >> a[it])
		{
			it++;
			if (it == n)
				break;
		}
		if (it < n) break;
		while (true)
		{
			if (mani(a, n))
				break;
			c++;
		}
		cout << c << endl;
		cout << a[0];
		for (int i = 1; i < n; i++)
			cout << " " << a[i];
		cout << endl;
	}
	return 0;
}

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){
      bool used[100];
      mp.clear();
      rep(i,N) mp[s[i]]++;
      rep(i,100) used[i] = false;

//      rep(i,N) cout << s[i] << ' '; cout << endl;
//      foreach(mp,itr) cout << itr->first << ',' << itr->second << ' '; cout << endl;

      rep(i,N) foreach(mp,itr) if(s[i] == itr->first && !used[i]){
        s[i] = itr->second;
        used[i] = true;
      }

//      rep(i,N) cout << s[i] << ' '; cout << endl;

      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;
}

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;
		v = next(v);
		if (v == w)break;
		cnt++;
	}
	cout << cnt << endl;
	rep(i, 0, v.size()) cout << v[i] << (i == v.size() - 1 ? '\n' : ' ');

	return 0;
}

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

using namespace std;

#define loop(i,a,b) for(int i=(a); i<(b); i++)
#define rep(i,b) loop(i,0,b)

int main(){
    int n;
    while(cin >> n && n){
        int a[15];
        rep(i,n) cin >> a[i];
        int c = 0;
        while(1){
            map<int,int> m;
            rep(i,n) m[a[i]]++;
            bool up = false;
            rep(i,n){
                if(a[i] != m[a[i]]){
                    a[i] = m[a[i]];
                    up = true;
                }
            }
            if(!up) break;
            else c++;
        }
        cout << c << endl;
        rep(i,n) cout<<a[i]<<(i==n-1 ? "\n" : " ");
    }
}

C++: #include <bits/stdc++.h>
using namespace std;
#include <iostream>
#include <cstdio>
#include <algorithm>

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n)  FOR(i,0,n)

int main()
{
    int n;
    while (1) {
        int cnt[13] = { 0 };
        cin >> n;
        if (n == 0) break;
        REP(i, n) cin >> cnt[i];
        int pre[13] = { 0 };
        for(int k = 0, f = 1; ; k++, f = 1) {
            int sum[100] = { 0 };
            REP(i, n) {
                pre[i] = cnt[i];
                sum[pre[i]]++;
            }
            REP(i, n) {
                cnt[i] = sum[pre[i]];
                if (cnt[i] != pre[i]) f = 0;
            }
            if (f) {
                cout << k << endl;
                REP(i, n) {
                    if (i < n - 1) printf("%d ", cnt[i]);
                    else printf("%d\n", cnt[i]);
                }
                break;
            }
        }
    }
    return 0;
}

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


int main(){
	int n,s[12],c[12],m;
	while(cin>>n,n){
		m=0;
		for(int i=0;i<n;i++)cin>>s[i];
		while(1){
			for(int i=0;i<n;i++){
				c[i]=count(s,s+n,s[i]);
			}
			if(equal(s,s+n,c))break;
			copy(c,c+n,s);
			m++;			
		}
		cout<<m<<'\n'<<s[0];
		for(int i=1;i<n;i++)cout<<' '<<s[i];
		cout<<endl;
	}
	return 0;
}

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


void f(std::vector<int> &vector, const int &count = 0){
	bool flag = true;
	std::map<int, int> freq;
	for (const auto &i : vector) {
		if (freq.find(i) == freq.end()) {
			freq[i] = 1;
		}
		else {
			++freq.at(i);
		}
	}
	for (auto &i : vector) {
		flag = (i == freq.at(i)) && flag;
		i = freq.at(i);
	}
	if (flag) {
		std::cout << count << "\n";
		for (auto i = 0; i < vector.size() - 1; ++i){
			std::cout << vector.at(i) << " ";
		}
		std::cout << vector.back() << "\n";
	}
	else {
		f(vector, count + 1);
	}
}
int main() {
	int n;
	std::cin >> n;
	while (n != 0) {
		std::vector<int> vec(n);
		for (auto &i : vec) {
			int temp;
			std::cin >> temp;
			i = temp;
		}
		f(vec);
		std::cin >> n;
	}
	return 0;
}

C++: #include<iostream>
#include<vector>
using namespace std;
vector<int> f(vector<int> v) {
	int cnt[110] = {};
	for (int i = 0; i < v.size(); i++) 
		cnt[v[i]]++;
	vector<int> r;
	for (int i = 0; i < v.size(); i++)
		r.push_back(cnt[v[i]]);
	return r;
}
int main() {
	int n;
	while (cin >> n, n) {
		vector<int>b, a;
		for (int i = 0; i < n; i++) {
			int k; cin >> k;
			b.push_back(k);
		}
		int cnt = 0;
		while (true) {
			cnt++;
			a = f(b);
			if (a == b)break;
			b = a;
		}
		cout << --cnt << endl;
		for (int i = 0; i < a.size(); i++) {
			if (i)cout << ' '; cout << b[i];
		}cout << endl;
	}
}