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<fstream>
#include<sstream>
#include<cstdio>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<deque>
#include<map>
#include<set>
#include<algorithm>
#include<cmath>
#include<string>
#include<cstring>
#include<cstdlib>
#include<climits>
#include<utility>
#include<cctype>
using namespace std;

#define ull unsigned long long
#define stt(it,order) sort(it.begin(),it.end(),order)
#define st(it) sort(it.begin(),it.end())
#define ll long long
#define rep(i,j) for(int i=0;i<j;++i)
#define loop(i,a,j) for(int i=a;i<j;++i)
#define mpi(it,table,T,E) for(map<T,E>::iterator it = table.begin();it!=table.end();++it)
#define PI 3.141592654
#define pb(v,e) v.push_back(e)
#define ms(a,v) memset(a,v,sizeof(a))
#define cp(a,b,n) rep(i,n)a[i] = b[i]
#define print_array_int(a,n) rep(i,n-1){printf("%d ",a[i]);}printf("%d\n",a[n-1])

string sint(int i){
   stringstream buf;
   buf<<i;
   return buf.str();
}

/*
ifstream fin("input.txt");
ofstream fout("output.txt");
#define cin fin
#define cout fout
*/

int n;
int ant[15],ata[15];

bool check(){
   rep(i,n){
      if(ant[i] != ata[i])return false;
   }
   return true;
}

int main(){
   while(scanf("%d",&n) != EOF, n){
      rep(i,n){
         scanf("%d",&ant[i]);
      }
      int times = 0;
      ms(ata,0);
      map<int,int> tt;
      while( times<5 ){
         tt.clear();
         times++;
         rep(i,n){
            tt[ant[i]]++;
         }

         rep(i,n){
            ata[i] = tt[ant[i]];
         }

         if( check()){
            break;
         }
         cp(ant,ata,n);
      }

      printf("%d\n",times-1);
      print_array_int(ant,n);
   }
   return 0;
}

C++: #include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip> 
#include <complex> 
#include <string>
#include <vector> 
#include <list>
#include <deque> 
#include <stack> 
#include <queue> 
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <utility>
#include <algorithm> 
#include <numeric> 
#include <typeinfo> 
#include <cstdio>
#include <cstdlib> 
#include <cstring>
#include <cmath>
#include <climits> 
#include <ctime> 

using namespace std;

int main(void){
	int n;
	int a;
	int s[12];
	int sc[13];
	int ans2=0;
	bool ans=true;
	while(1){
		for(a=0;a<=12;a++)sc[a]=0;
		ans2=0;
		cin >> n;
		if(n==0)break;
		for(a=0;a<n;a++){
			cin >> s[a];
			sc[s[a]]++;
		}
		while(1){
			ans=true;
			for(a=0;a<n;a++){
				if(s[a]!=sc[s[a]])ans=false;
				s[a]=sc[s[a]];
			}
			if(ans==true)break;
			else{
				ans2++;
				for(a=0;a<=12;a++)sc[a]=0;
				for(a=0;a<n;a++)sc[s[a]]++;
			}
		}
		cout << ans2 << endl;
		for(a=0;a<n;a++)cout << s[a] << ' ';
		cout << endl;
	}
}

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

int ans[500][2][12];//二つ目の次元の0の0に数列の長さ、0の1に操作回数、1に答えの数列

int counter=0,flag=0;

void solve(){
	int n;
	cin >> n;
	if(n==0){flag=1;return;}
	ans[counter][0][0]=n;
	
	int S[12];//数列
	for(int i=0;i<n;i++){
		cin >> S[i];
	}
	
	bool check=false;//操作の有無のフラグ
	int time=0;//操作回数
	do{
		map<int,int> marker;
		for(int i=0;i<n;i++){
			marker[S[i]];
			marker[S[i]]++;
		}
		check=false;
		for(int i=0;i<n;i++){
			if(S[i]!=marker[S[i]]){
				check=true;
				S[i]=marker[S[i]];
			}
		}
		if(check) time++;
	}while(check);
	
	ans[counter][0][1]=time;
	for(int i=0;i<n;i++){
		ans[counter][1][i]=S[i];
	}
	counter++;
}

int main(){
	while(flag==0)solve();
	for(int i=0;i<counter;i++){
		cout << ans[i][0][1] << endl;
		for(int j=0;j<ans[i][0][0]-1;j++){
			cout << ans[i][1][j]<<" ";
		}
		cout << ans[i][1][ans[i][0][0]-1] << endl;
	}
}

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

int main()
{
    int N;
    while (cin >> N, N) {
        int n[MAX], t[MAX];
        for (int i = 0; i < N; i++) {cin >> n[i]; t[i] = n[i];}
        bool flag = true;
        int count = 0;
        while (flag) {
            map<int,int> m;
            for (int i = 0; i < N; i++) {
                m[n[i]]++;
            }
            for (int i = 0; i < N; i++)
                t[i] = m[n[i]];
            bool f = true;
            for (int i = 0; i < N; i++)
                if (t[i] != n[i]) f = false;
            if (f) flag = false;
            count++;
            for (int i = 0; i < N; i++) n[i] = t[i];
        }
        count--;
        cout << count << endl << t[0];
        for (int i = 1; i < N; i++) cout << " " << t[i];
        cout << endl;
    }

    return 0;
}

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

int main(){
  int n;
  while(1){
    cin >> n;
    if(n==0) break;

    int s[15]={};
    for(int i = 0; i < n; i++) cin >> s[i];
    
   
    int ans = 0;
    int c[15];
    while(1){
      bool issame = true;
      for(int i = 0; i < n; i++){
	int sum = 0;	
	for(int j = 0; j < n; j++){
	  if(s[i] == s[j] ) sum++;
	}
	if(s[i] != sum ) issame = false;
	c[i] = sum;
      }
      if(issame){
	cout << ans << endl;
      	for(int j = 0; j < n; j++){
	  if(j == n-1) cout << s[j] << "\n";
	  else cout << s[j] << " ";
	}
	break;
      }
      for(int j = 0; j < n; j++){
	s[j] = c[j];
      }
      ans++;
    }
  }
  
  return 0;
}

C++: //============================================================================
// Name        : aoj0108.cpp
// Author      : afterCmidday
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <cstring>
using namespace std;

int main() {
	int n, s[12], tmp[12], pre[12];
	while(cin >> n){
		for(int i = 0 ;i < n;i++){
			cin >> s[i];
		}
		memset(pre,-1,sizeof(pre));
		while(true){
			int i;
			for(i = 0;i < n;i++){
				pre[i] = s[i];
				tmp[i] = s[i];
			}
			for(i = 0;i < n;i++){
				int cnt = 0;
				for(int j = 0;j < n;j++){
					if(tmp[i] == tmp[j]){
						cnt++;
					}
				}
				s[i] = cnt;
			}
			for(i = 0;i < n;i++){
				if(pre[i] != s[i]){
					break;
				}
			}
			if(i == n){
				break;
			}
		}
		for(int i = 0;i < n;i++){
			cout << s[i];
			if(i != n - 1){
				cout << " ";
			}
		}
		cout << endl;
	}
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for( int i = 0; i < n; i++ )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    /*
    cin.tie(0);
    ios::sync_with_stdio(false);
    //*/
    int n; cin >> n;
    while (n != 0) {
        int flag = 1;
        int p[n];
        rep(i, n) {
            cin >> p[i];
        }
        int count = 0;
        int q[101] = {0};
        fill(q, q+101, 0);
        while (flag == 1){
            flag = 0;
            fill(q, q+101, 0);
            rep(i, n) q[p[i]]++;
            //rep(i, n) cout << q[p[i]] << " ";
            for (int i = 0; i < n-1; i++) {
                if (p[i] != q[p[i]]) flag = 1;
            }
            rep(i ,n) p[i] = q[p[i]];
            count++;
        }
        rep(i, n-1) cout << q[p[i]] << " ";
        cout << count-1 << endl;
        cout << q[p[n-1]] << endl;
        cin >> n;
    }

    return 0;
}