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>

using namespace std;

bool func(int *a, int *b, int n)
{
	for(int i = 0; i < n; i++){
		if(a[i] != b[i]){
			return true;
		}
	}
	
	return false;
}

int main(int argc, char **argv)
{
	int n, a[13], b[13], c[13], s;
	
	while(1){
		cin >> n;
		if(n == 0){
			break;
		}
		for(int i = 0; i <= 12; i++){
			a[i] = b[i] = c[i] = 0;
		}
		for(int i = 0; i < n; i++){
			cin >> a[i];
			c[a[i]]++;
		}
		for(int i = 0; i < n; i++){
			b[i] = a[i];
			a[i] = c[a[i]];
		}
		s = 0;
		while(func(a, b, n)){
			for(int i = 0; i < n; i++){
				b[i] = a[i];
				a[i] = c[a[i]];
			}
			for(int i = 0; i < n; i++){
				c[i] = 0;
			}
			for(int i = 0; i < n; i++){
				c[a[i]]++;
			}
			s++;
		}
		s--;
		cout << s << endl;
		for(int i = 0; i < n-1; i++){
			cout << a[i] << " ";
		}
		cout << a[n-1] << endl;
	}
	
	return 0;
}

C++: #include <iostream>
using namespace std;
int main(){
	int n,s[12],o[12];
	while(cin>>n){
		if(!n)break;
		int step=-1;
		for(int i=0;i<n;++i) cin>>s[i];
		for(int f=1;f;++step){
			for(int i=0;i<n;++i) o[i]=s[i];
			for(int i=0,count=0;i<n;++i){
				count=0;
				for(int j=0;j<n;++j){
					if(o[i]==o[j])++count;
				}
				s[i]=count;
			}
			f=0;
			for(int i=0;i<n;++i) if(s[i]!=o[i])f=1;
		}
		cout<<step<<"\n";
		for(int i=0;i<n;++i) cout<<s[i]<<((i!=n-1)?" ":"\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 ans2=0;
	int s[13];
	bool ans=true;
	while(1){
		ans2=0;
		cin >> n;
		map<int,int> sc;
		for(a=0;a<=12;a++)s[a]=0;
		if(n==0)break;
		for(a=0;a<n;a++){
			cin >> s[a];
		}
		for(a=0;a<n;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<n;a++)sc[a]=0;
				for(a=0;a<n;a++)sc[s[a]]++;
			}
		}
		cout << ans2 << endl;
		for(a=0;a<n-1;a++)cout << s[a] << ' ';
		cout << s[n-1] << endl;
	}
	return 0;
}

C++: #include<iostream>
#include<map>
using namespace std;
int main(void){

    int n;

    while(cin>>n){
        if(n==0)break;
        int a[13];
        map<int,int> b;
        int c[13];
        for(int i=0;i<n;i++){
            cin>>a[i];
            b[a[i]]++;
        }
        int j=0;
        while(1){

            bool flg = false;
            for(int i=0;i<n;i++){
                c[i] = b[a[i]];
                if(c[i]!=a[i])flg = true;
                //cout<<c[i]<<" ";
            }
            //cout<<endl;
            if(!flg)break;
            for(int k=0;k<n;k++)b[k]=0;
            for(int k=0;k<n;k++){
                a[k] = c[k];
                b[a[k]]++;
            }
            j++;
        }
        cout<<j<<endl;
        for(int i=0;i<n;i++){
            cout<<c[i]<<" ";
        }
        cout<<endl;

    }

    return 0;
}

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

int main(){
 int n;
 int a[2][12];
 int flg,work,i,j,cnt;
 
 while(1){
	cin>>n;
	if(n==0){break;}
	flg=0;
	for(i=0;i<n;i++){cin>>a[flg][i];}
	cnt=-1;
	
	do{
	 work=0;
	 for(i=0;i<n;i++){
	  a[1-flg][i]=0;
	  for(j=0;j<n;j++){
		 if(a[flg][i]==a[flg][j]){a[1-flg][i]++;}
	  }
	  if(a[flg][i]==a[1-flg][i]){work++;}
	 }
	  
	 flg=1-flg;cnt++;
	}while(work!=n);
	
	cout<<cnt<<endl;
	for(i=0;i<n;i++){
	 if(i){cout<<" ";}
	 cout<<a[flg][i];
	}
	cout<<endl;
 }
 
 return 0;
}

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

using namespace std;

int main()
{
	int n,i,j,num[100],array[100];
	
	for(;;)
	{
		cin >> n;
		if(n==0)
			break;
		
		
		for(i=0;i<n;i++)
			cin >> array[i];
		
		int ans=0;
		for(;;)
		{
			for(i=0;i<=12;i++)
				num[i]=0;
			int flag=1;
			for(i=0;i<n;i++)
				num[array[i]]++;
			
			for(i=0;i<n;i++)
			{
				if(array[i]!=num[array[i]])
					flag=0;
				array[i]=num[array[i]];
			}
			if(flag==1)
				break;
			ans++;
		}
		
		cout << ans << endl;
		for(i=0;i<n;i++)
		{
			if(i<n-1)
				cout << array[i] << " ";
			else
				cout << array[i] << endl;
		}
	}
}

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=0;;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>
using namespace std;

int main(){
	int n;
	while(cin >> n,n){
		int s[12],cnt[101];
		for(int i = 0;i < n;i++) cin >> s[i];
		int num;
		for(num = 0;;num++){
			bool flag = true;
			for(int i = 0;i <= 100;i++) cnt[i] = 0;
			for(int i = 0;i < n;i++) cnt[s[i]]++;
			for(int i = 0;i <= 100;i++){
				if(cnt[i] != 0 && cnt[i] != i) flag = false;
			}
			if(flag) break;
			for(int i = 0;i < n;i++) s[i] = cnt[s[i]];
		}
		cout << num << endl;
		for(int i = 0;i < n - 1;i++) cout << s[i] << " ";
		cout << s[n - 1] << endl;
	}
	return 0;
}

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

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(n) rep(i,n)
#define all(n) n.begin(),n.end()

//typedef pair<int,int> pp;
const int MAXN = 13;

vector<int> hindo(vector<int> s)
{
    map<int, int> m;
    REP(s.size()) m[s[i]]++;

    vector<int> ans;
    REP(s.size()) ans.push_back(m[s[i]]);
    
    return ans;
}
void os(vector<int> s)
{
    REP(s.size())
    {
        cout << s[i];
        if(i == s.size() -1){ cout << endl; return;}
        cout << " ";
    }
    return ;
}

int main()
{
    int n;
    while(cin >> n && n)
    {
        int num;
        vector<int> s[MAXN + 1];

        REP(n) {cin >> num; s[0].push_back(num);}

        REP(MAXN) s[i+1] = hindo(s[i]);

        REP(MAXN)if(s[i+1] == s[i] ){cout << i << endl; break;}
        os( s[MAXN -1]);
    }
    return 0;
}

C++: #include<iostream>
#include<vector>
using namespace std;
int main()
{
	int n;
	while(cin>>n,n) 
	{
		vector<int> a(n),b(n);
		for(int i = 0; i < n; ++i)
		{
			cin>>a[i];
		}
		int ans=0;

		while(1) 
		{
			for(int i = 0; i < n; ++i)
			{
				b[i]=0;
				for(int j = 0; j < n; ++j)
				{
					if(a[i]==a[j]) b[i]++; 
				}
			}

			if(a==b)
			{
				cout<<ans<<endl;
				for(int i = 0; i < n; ++i)
				{
					if(i!=0) cout<<" ";
					cout<<a[i];
				}
				cout<<endl;
				break;
			}
			else
			{
				a=b;
				ans++;
			}
		}
	}
  return 0;
}