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<algorithm>
#include<string>
#include<vector>
#include<bitset>
using namespace std;
int main(){
    int n;
    while(cin>>n,n){
        int s[12];
        for(int i=0;i<n;i++)cin>>s[i];
        bool endFlag=false;
        while(!endFlag){
            endFlag=true;
            int cnt[15]={0};
            for(int i=0;i<n;i++)cnt[s[i]]++;
            for(int i=0;i<n;i++){
                if(s[i]!=cnt[s[i]]){
                    s[i]=cnt[s[i]];
                    endFlag=false;
                }
            }
        }
        for(int i=0;i<n;i++){
            if(i!=0)cout<<" ";
            cout<<s[i];
        }
        cout<<endl;
    }
}

C++: #include<iostream>
#include<string>
using namespace std;
int main(){
	int s[20],c[20];
	int n;
	while(true){
	    cin>>n;
		if(n==0)
			break;
	for(int i=0;i<n;i++)
		cin>>s[i];
	int d=0;
	while(true){
		for(int i=0;i<n;i++){
			int count=0;
			for(int j=0;j<n;j++){
				if(s[i]==s[j])
					count++;
			}
			c[i]=count;
		}
		bool t=true;
		for(int i=0;i<n;i++){
			if(s[i]!=c[i]){
				t=false;
				s[i]=c[i];
			}
		}
		if(t==true)
			break;
		d++;
	}
	cout<<d<<endl;
	for(int i=0;i<n-1;i++)
		cout<<s[i]<<" ";
	cout<<s[n-1]<<endl;
	}
    return 0;
}

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

bool all_same(vector<int> v){
    int t = v[0];
    for(int i = 1; i < v.size(); i++){
        if(v[i]-t) return false;
    }
    return true;
}

int main(){
    int n;
    while(cin>>n,n){
        vector<int> v(n);
        for(int i = 0; i < n; i++){
            cin >> v[i];
        }
        int count = 0;
        while( true ){
            vector<int> freq(n, 0);
            for(int i = 0; i < v.size();i++){
                if( freq[i] ) continue;
                int f = 0;
                vector<int> ot;
                for(int j = 0; j < v.size(); j++){
                    if( v[i]==v[j] ){
                        f++;
                        ot.push_back(j);
                    }
                }
                for(int j = 0; j < ot.size(); j++){
                    freq[ ot[j] ] = f;
                }
            }
            if(v == freq) break;
            count++;
            v = freq;
        }
        cout << count << endl;
        cout << v[0];
        for(int i = 1; i < v.size(); i++){
            cout << ' ' << v[i];
        }
        cout << endl;
    }
    return 0;
}

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

using namespace std;

int main()
{
    int n;
    
    while (cin >> n, n) {
        vector<vector<int> > a(2, vector<int>(n));
        int cnt = 0;
        int f, t;

        f = 0;
        t = 1;
        for (int i = 0; i < n; i++)
            cin >> a[0][i];

        while (a[t] != a[f]) {
            for (int i = 0; i < n; i++) {
                int tmp = 0;
                for (int j = 0; j < n; j++)
                    if (a[f][i] == a[f][j])
                        tmp++;
                a[t][i] = tmp;
            }

            cnt++;
            f = 1 - f;
            t = 1 - t;
        }

        cout << cnt - 1 << endl;
        for (int i = 0; i < n - 1; i++)
            cout << a[t][i] << " ";
        cout << a[t][n - 1] << endl;
    }

    return 0;
}

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

int main(){
	int n;
	while(1){
		cin >> n;
		if(n==0) break;
		int a[n];
		int e = 0;
		for(int i=0;i<n;i++) cin >> a[i];
		while(1){
			int b[n],c[n];
			for(int i=0;i<n;i++) b[i] = 0;
			for(int i=0;i<n;i++) b[a[i]-1]++;
			for(int i=0;i<n;i++) c[i] = b[a[i]-1];
			int d = 0;
			for(int i=0;i<n;i++) if(a[i]==c[i]) d++;
			if(d==n) break;
			e++;
			for(int i=0;i<n;i++) a[i] = c[i];
		}
		cout << e << endl;
		cout << a[0];
		for(int i=1;i<n;i++) cout << " " << a[i];
		cout << endl;
	}
return 0;
}

C++: #define	_USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <vector>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cfloat>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <string>
#include <set>
#include <complex>
#include <utility>
#define  rep(i,n) for(int i=0;i<(n);i++)
#define  REP(i,n) for(int i=1;i<(n);i++)
#define  rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define  VI	vector<int>
#define	 VS vector<string>
#define  all(a) (a).begin(),(a).end()
#define  debug(x) cout<<#x<<": "<<x<<endl
using namespace std;
typedef pair<int,int> P;
int main(){
	
	int n;
	while(cin>>n,n!=0){
		vector<int> s(n,0);
		vector<int> p(n,0);
		int count=0;
		rep(i,n)
			cin>>s[i];
		
		bool f=false;
		while(!f){
			f=true;
			map<int,int> m;
			
			rep(i,n){
				if(m.count(s[i])==0){
					m[s[i]]=1;
				}
				else
					m[s[i]]++;
			}
			rep(i,n)
				p[i]=m[s[i]];
			
			rep(i,n){
				if(p[i]!=s[i])
					f=false;
				
			}
			if(!f){
				rep(i,n)
					s[i]=p[i];
			count++;}
		}
		cout<<count<<endl;
		cout<<s[0];
		REP(i,n)
			cout<<" "<<s[i];
		cout<<endl;
		
	}
	
}

C++: #include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<bitset>
using namespace std;
int main(){
    int n;
    while(cin>>n,n){
        int s[1000];
        for(int i=0;i<n;i++)cin>>s[i];
        bool endFlag=false;
        int c=0;
        while(!endFlag){
            endFlag=true;
            int cnt[1000]={0};
            for(int i=0;i<n;i++)cnt[s[i]]++;
            for(int i=0;i<n;i++){
                if(s[i]!=cnt[s[i]]){
                    s[i]=cnt[s[i]];
                    endFlag=false;
                }
            }
            if(!endFlag)c++;
        }
        cout<<c<<endl;
        for(int i=0;i<n;i++){
            if(i!=0)cout<<" ";
            cout<<s[i];
        }
        cout<<endl;
    }
}

C++: #include <stdio.h>
#include<math.h>
#include <algorithm>

using namespace std;


int main(){

	int n,table[101],count;
	bool FLG;

	while(true){
		scanf("%d",&n);
		if(n == 0)break;

		for(int i=0; i< 101; i++)table[i] = 0;
		int array[n],pre[n];
		count = 0;

		for(int i=0; i< n; i++){
			scanf("%d",&array[i]);
			table[array[i]]++;
		}

		while(true){
			FLG = true;

			if(count == 0){
				for(int i=1;i < n; i++){
					if(table[array[i]] != table[array[i-1]]){
						FLG = false;
						break;
					}
				}
			}else{
				for(int i=0; i < n; i++){
					if(array[i] != pre[i]){
						FLG = false;
						break;
					}
				}
			}
			if(FLG)break;

			for(int i=0; i< n; i++){
				pre[i] = array[i];
				array[i] = table[array[i]];
			}

			for(int i=0; i< 101; i++)table[i] = 0;

			for(int i=0; i < n; i++)table[array[i]]++;
			count++;
		}

		printf("%d\n",count-1);

		printf("%d",array[0]);
		for(int i=1; i<n; i++)printf(" %d",array[i]);
		printf("\n");

	}

    return 0;
}