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 <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>

using namespace std;

#define rep(i,n) for(int i=0; i<(n); i++)
#define repc(i,s,e) for(int i=(s); i<(e); i++)
#define pb(n) push_back((n))
#define mp(n,m) make_pair((n),(m))
#define all(r) r.begin(),r.end()
#define fi first
#define se second

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;




int main() {
	int n;
	while (cin >> n&&n > 0) {
		vi v(n);
		rep(i, n)cin >> v[i];
		int ans = 0;
		while (1) {
			map<int, int> m;
			rep(i, n)m[v[i]] += 1;
			vi v2;
			rep(i, n) {
				v2.push_back(m[v[i]]);
			}
			if (v == v2) {
				break;
			}
			v = v2;
			ans++;
		}
		cout << ans << endl;
		rep(i, n) {
			if (i != 0)cout << " ";
			cout << v[i];
		}
		cout << endl;
	}
}

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

int main() {
	int n;

	while(cin >> n, n) {
		vector<int> v1, v2;
		int count = 0;

		for(int i = 0; i < n; i++) {
			int tmp;
			cin >> tmp;
			v1.push_back(tmp);
		}

		while(1) {
			count++;
			for(int i = 0; i < n; i++) {
				int tmp = 0;
				for(int j = 0; j < n; j++) {
					if(v1[i] == v1[j])
						tmp++;
				}
				v2.push_back(tmp);
			}

			if(v1 == v2)
				break;
			v1 = v2;
			v2.clear();
		}

		cout << count - 1 << endl;
	}

	return 0;
}

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

int main(){
  int n;
  int s[111];
  while(1){
    cin >> n;
    int ans=0,cou=0;
    if(n == 0) break;
    for(int i=0;i<n;i++){
      cin >> s[i];
    }
    while(1){
      cou = 0;
      int cheak[111]={0};
      for(int i=0;i<n;i++){
	if(cheak[s[i]] == 0){
	  for(int j=0;j<n;j++){
	    if(s[i] == s[j]){
	      cheak[s[i]]++;
	    }
	  }
	}
      }
      for(int i=0;i<n;i++){
	s[i] = cheak[s[i]];
	if(cheak[s[i]] == s[i]){
	  cou++;
	}
      }
      if(cou == n) break;
      ans++;
    }
    cout << ans << endl;
    for(int i=0;i<n;i++){
      cout << s[i];
      if(i == n-1) cout << endl;
      else cout << " ";
    }
  }
}

C++: #include <cstdio>
#include <cstring>
#define buf 10000
using namespace std;

void BubbleSort(int n);
void Search(int n);
void Answer(int n,int ans);
void Copy(int n);
int Log(int n);
int A[300],B[300],C[300]={0},D[300]={0},ans;

int main(void){
  int i,n,m,z,num,ans;
  char str[buf],*line;

  for( ;fgets(str,sizeof(str),stdin)!=NULL; ){
    sscanf(str,"%d",&n);
    if(n==0) break; ans=0;
    fgets(str,sizeof(str),stdin);
    line=strtok(str," ");
    sscanf(line,"%d",&m); A[0]=m;
    for(i=1;i<n;i++){
      line=strtok(NULL," ");
      sscanf(line,"%d",&m);
      A[i]=m;
    }
    for( ; ; ){
      Copy(n);
      BubbleSort(n);
      Search(n);
      z=Log(n);
      if(z) break;    
    }
    Answer(n,ans);
  }
  return 0;
}

int Log(int n){
  int i,num=0;
  for(i=0;i<n;i++){
    if(D[i]==C[i])
      num++;
  }
  if(num==n)
    return 1;
  else{
    for(i=0;i<n;i++){
      C[i]=D[i];
      A[i]=D[i];
    }
    ans+=1;
  }
  return 0;
}

void Copy(int n){
  int i;
  for(i=0;i<n;i++){
    B[i]=A[i];
  }
}

void Answer(int n,int ans){
  int i;
  printf("%d\n",ans);
  for(i=0;i<n;i++){
  if(i) printf(" ");
     printf("%d",D[i]);
  }
  printf("\n");
}

void Search(int n){
  int i,j,tmp=0,cnt=1;
  B[n]=0;
  for(i=0;i<n;i++){
    if(B[i]==B[i+1])
      cnt+=1;
    else{
      for(j=0;j<n;j++){
        if(B[tmp]==A[j])
          D[j]=cnt;
      }
      tmp=i+1; cnt=1;
    }
  }
  Answer(n,1);
}

void BubbleSort(int n){
  int i,j,tmp;
  for(i=0;i<n-1;i++){
    for(j=n-1;j>i;j--){ 
      if(B[j] < B[j-1]){
        tmp = B[j-1];
        B[j-1] = B[j];
        B[j] = tmp;
      }
    }
  }
}

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){
            int cnt[15] = {};
            rep(i,n) cnt[a[i]]++;
            bool up = false;
            rep(i,n){
                if(a[i] != cnt[a[i]]){
                    a[i] = cnt[a[i]];
                    up = true;
                }
            }
            if(!up) break;
            else c++;
        }
        cout << c << endl;
        rep(i,n) cout << a[i] << (i+1==n ? "\n" : " ");
    }
}

C++: #include<stdio.h>
int main(void)
{
	int a,s[1000],d[1000],f,g,h,j,i;
	while(1){
		f=0;
		scanf("%d",&a);
		if(a==0)	break;
		for(i=0;i<a;i++)
			scanf("%d",&s[i]);
		while(1){
			g=0;
			for(i=0;i<a;i++)
				d[i]=1;
			for(i=0;i<a;i++){
				for(j=i+1;j<a;j++){
					if(s[i]==s[j]){
						d[i]++;
						d[j]++;
					}
				}
			}
			for(i=0;i<a;i++){
				if(d[i]==s[i]){
					g++;
				}
			}
			if(g==a)
				break;
			else f++;
			for(i=0;i<a;i++)
				s[i]=d[i];
		}
		printf("%d\n",f);
		for(i=0;i<a;i++){
			if(i!=0)	printf(" ");
			printf("%d",s[i]);
		}
		printf("\n");
	}
	return 0;
}

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

int main(){
	int n;
	vector<int> vi , vi2;
	while(cin >> n){
		if(n == 0) break;
		for(int i = 0; i < n; i++){
			int j;
			cin >> j;
			vi.push_back(j);
		}
		int counter = -1;
		do{
			vi2.clear();
			copy(vi.begin(), vi.end(), back_inserter(vi2));
			for(int i = 0; i < n; i++){
				vi[i] = count(vi2.begin(), vi2.end(), vi[i]);
			}
			counter++;
		}while(!equal(vi.begin(), vi.end(), vi2.begin()));
		cout << counter << endl;
		for(int i = 0; i < vi.size(); i++){
			if(i != 0) cout << " ";
			cout << vi[i];
		}
		cout << endl;
	}
	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];
	int sc[13];
	bool ans=true;
	while(1){
		ans2=0;
		cin >> n;
		for(a=0;a<=12;a++)s[a]=0,sc[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;
}