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 <cstdio>
#include <string>
#include <sstream>
#include <algorithm>
#include <math.h>
#include <map>
#include <iomanip>
#include <vector>

using namespace std;



int n;
int S[12];
int C[12];
int cnt;	//操作回数
bool first_flag;
map<int, int> hindo;



//numは数列の長さ
void operation(int num)
{
	hindo.clear();
	
	for (int i=0; i<num; i++)
	{
		if (hindo.find(S[i]) == hindo.end())
		{
			//初めての数だった場合
			hindo[S[i]] = 1;
		} else {
			hindo[S[i]]++;
		}
	}
	
	for (int i=0; i<num; i++)
	{
		C[i] = hindo[S[i]];
	}
}



//numは数列の長さ
bool check_same_array(int num)
{
	bool flag = true;
	
	for (int i=0; i<num; i++)
	{
		if (S[i] != C[i])
		{
			flag = false;
			break;
		}
	}
	
	return flag;
}



void replace_array(int num)
{
	for (int i=0; i<num; i++)
	{
		S[i] = C[i];
	}
}



int main()
{
	while (cin >> n)
	{
		if (n == 0) break;
		
		for (int i=0; i<n; i++)
		{
			cin >> S[i];
		}
		
		cnt = 0;
		while (1)
		{
			operation(n);
			cnt++;
			if (check_same_array(n))
			{
				//数列が同じだった場合
				cout << cnt - 1 << endl;
				first_flag = true;
				for (int i=0; i<n; i++)
				{
					if (first_flag)
					{
						cout << C[i];
						first_flag = false;
					} else {
						cout << " " << C[i];
					}
				}
				cout << endl;
				break;
			} else {
				replace_array(n);
			}
		}
		
		/*
		for (int i=0; i<n; i++)
		{
			cout << C[i] << " ";
		}
		*/
	}
	
	return 0;
}

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

int main() {
  int a[12], b[13];
  int c, n;
  bool f;
  map<int, int> m;

  while (cin >> n && n) {
    m.clear();
    for (int i=0; i<n; i++) {
      cin >> a[i];
      m.insert(map<int, int>::value_type(a[i], i+1));
      a[i] = m[a[i]];
    }

    c = -1;
    do {
      f = true;
      for (int i=1; i<=n; i++) b[i]=0;
      for (int i=0; i<n; i++) b[a[i]]++;
      for (int i=0; i<n; i++) {
        if (a[i] != b[a[i]]) f=false;
        a[i] = b[a[i]];
      }
      c++;
    } while (!f);
    cout << c << endl;
    for (int i=0; i<n; i++) cout << a[i] << " ";
    cout << endl;
  }

  return 0;
}

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

using namespace std;

typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vbb;
typedef pair<int, int> pii;
typedef long long ll;
typedef unsigned long long ull;

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair

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

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

int main(){
    int n;
    while(cin >> n, n){
        vi p;
        rep(i, n){int m; cin >> m; p.pb(m); }

        vi v(n, 0);
        int count = 0;
        while(true){
            bool finish = true;
            for(int i=0;i < n; i++){
                if(p[i] != v[i]) finish = false;
            }
            if(finish) break;
            v = p;
            for(int i=0; i < n; i++){
                int c = 0;
                for(int j=0; j < n; j++){
                    if(v[i] == v[j]) c++;
                }
                p[i] = c;
            }
            count++;
        }
        cout << count-1 << endl;
        for(int i=0; i < n; i++){
            if(i == 0) cout << v[i];
            else cout << " " << v[i];
        }
        cout << endl;
    }
}

C++: #define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, m, n) for(int i=(m); i<(n); ++i)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define Cout(x) cout << (x) << endl
#define Cout2(x, y) cout << (x) << " " << (y) << endl
#define dump(x) cout << #x << " = " << (x) << endl;
#define forauto(i, a) for(auto i : a)cout << i << " "; puts("");
typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
const int inf = 1e9;
const double pi = acos(-1.0);

VI convi(int n, VI a) {
	VI ret(n);
	VI memo(101, -1);

	rep(i, n) {
		if (memo[a[i]] == -1) {
			int cnt = count(all(a), a[i]);
			ret[i] = cnt;
			memo[a[i]] = cnt;
		}
		else {
			ret[i] = memo[a[i]];
		}
	}

	return ret;
}

bool endCheck(VI a) {
	return a == convi(sz(a), a);
}

int main() {
	int n;
	while (cin >> n && n) {
		VI a(n); rep(i, n)cin >> a[i];

		int ans = 0;
		while (!endCheck(a)) {
			a = convi(n, a);
			ans++;
		}

		Cout(ans);
		rep(i, n)cout << a[i] << (i == n - 1 ? "\n" : " ");
	}
}

C++: #include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>

#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define repi(i,a,b) for(int i = (a); i < (b); i++)

using namespace std;

typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;

const int INF=1<<29;
const double EPS=1e-9;

const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};

int main(){
	int n;
	while(cin>>n,n){
		map<int,int> data;
		map<string,int> m;
		std::vector<int> v;
		string tmp;
		for(int i =0 ;i < n;i++){
			int x;
			cin>>x;
			stringstream ss;
			ss <<x;
			tmp +=ss.str();
			v.push_back(x);
			data[x]++;
		}
		//cout <<tmp<<endl;
		m[tmp]++;
		std::vector<int> ans;
		int cnt =0;
		map<int,int> t;
		while(1){
			string str ="";
			cnt++;
			ans.clear();
			t.clear();
			for(int i =0;i < v.size();i++){
				stringstream ss;
				ss <<data[v[i]];
				str +=ss.str();
				t[data[v[i]]]++;
				ans.push_back(data[v[i]]);
			}
			if(m[str]){
				break;
			}else{
				m[str]++;
			}
			//cout <<str<<endl;
			v=ans;
			data.clear();
			data =t;
		}
		cout <<cnt-1<<endl;
		for(int i =0;i < ans.size();i++){
			cout <<ans[i];
			if(i!=ans.size()-1)cout <<" ";
		}
		cout <<endl;
	}
	return 0;
}

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

#define for_(i,a,b) for(int i=(a);i<(b);++i)

int main() {
	int n, s[15];
	
	while (cin >> n, n) {
		for_(i,0,n) cin >> s[i];
		
		bool update = 1;
		int ans = 0;
		
		while (update) {
			update = 0;
			
			map< int, int > cnt;
			for_(i,0,n) ++cnt[s[i]];
			
			for_(i,0,n) {
				if (s[i] != cnt[s[i]]) update = 1;
				s[i] = cnt[s[i]];
			}
			
			if (update) ++ans;
		}
		
		cout << ans << endl;
		for_(i,0,n) cout << s[i] << (i < n - 1 ? " " : "\n");
	}
}