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 <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<n;a++)sc[a]=0;
		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<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() {
  int n;
  int a[12], b[12];
  map<int, int> mp;

  while(cin >> n, n) {
    for(int i=0; i<n; i++) cin>>a[i];
    int cnt = 0;
    while(1) {
      mp.clear();
      for(int i=0; i<n; i++) mp[a[i]] ++;
      for(int i=0; i<n; i++) b[i] = mp[a[i]];

      bool fin = true;
      for(int i=0; i<n; i++) if( a[i] != b[i] ) fin = false;
      if( fin ) break;
      cnt ++;
      for(int i=0; i<n; i++) a[i] = b[i];
    }

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

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

int main ( void )
{
	int n; // ツ青板療アツづ個陳キツつウ
	while ( cin >> n && n != 0 )
	{
		vector <int> S(n);
		for ( int i = 0; i < n; i++ )
			cin >> S[i];

		vector <int> V(n);
		vector <int> V_next(n);
		V = S;

		int cnt = 0;
		while ( 1 )
		{
			for ( int i = 0; i < n; i++ )
			{
				V_next[i] = count( V.begin(), V.end(), V[i] );
			}
			cnt++;

			if ( V == V_next )
			{
				cnt--;
				break;
			}

			V = V_next;

		}

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

	}

	return 0;
}

C++: #include <stdio.h>
#include <string.h>
void cpy(int src[],int dst[],int n){
	for(int i=0;i<n;i++) dst[i]=src[i];
}
void OFA(int S[],int n){
	int num[100];
	memset(num,0,sizeof(num));
	for(int i=0;i<n;i++) num[S[i]]++;
	for(int i=0;i<n;i++) S[i]=num[S[i]];
}

bool check(int S[],int tmp[],int n){
	for(int i=0;i<n;i++) if(S[i]!=tmp[i]) return false;
	return true;
}

int main(){
	int S[12],tmp[12],n,count;
	while(1){
		scanf("%d",&n);
		if(!n) break;
		count=-1;
		for(int i=0;i<n;i++) scanf("%d",&S[i]);
		cpy(S,tmp,n);
		do{
			cpy(tmp,S,n);
			OFA(tmp,n);
			//for(int i=0;i<n;i++) printf("%d ",tmp[i]);
			count++;
		}while(!check(S,tmp,n));
		printf("%d\n",count);
		for(int i=0;i<n-1;i++) printf("%d ",S[i]);
		printf("%d\n",S[n]);
	}
	return 0;
}

C++: #include <iostream>
#include <cstring>
using namespace std;
int main(){
  int n;
  while(cin >> n, n){
    int S[n], P[n], cnt = 0;
    memset(P, 0, sizeof(P));
    for(int i = 0 ; i < n ; i++){
      cin >> S[i];
    }
    
    while(1){
      for(int i = 0 ; i < n ; i++){
	for(int j = 0 ; j < n ; j++){
	  if(S[i] == S[j]) P[i]++;
	}
      }
      
      if(memcmp(P, S, sizeof(S)) == 0) break;

      memcpy(S, P, sizeof(P));
      memset(P, 0, sizeof(P));

      cnt++;
    }
    
    cout << cnt << endl;
    for(int i = 0 ; i < n ; i++){
      if(i == n-1) cout << P[i] << endl;
      else cout << P[i] << ' ';
    }
  }
  return 0;
}

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

int main(){
	int size;
	while(1){
		cin>>size;
		if(size==0)break;
		int s[size];
		int c[size];
		for(int i=0;i<size;i++){
			cin>>s[i];
			c[i]=0;
		}
		int watch=0;
		while(1){
			for(int i=0;i<size;i++){
				for(int j=0;j<size;j++){
					if(s[i]==s[j])c[i]++;
				}
			}
			watch++;
			int cnt=0;
			for(int i=0;i<size;i++){
				if(s[i]==c[i])cnt++;
			}
			if(cnt==size)break;
			for(int i=0;i<size;i++){
				s[i]=c[i];
				c[i]=0;
			}
		}
		cout<<watch-1<<endl;
		for(int i=0;i<size-1;i++){
			cout<<c[i]<<" ";
		}
		cout<<c[size-1]<<endl;
	}
	return 0;
}

C++: #include <stdio.h>
#include <map>

using namespace std;

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

    int s[n];
    for(int i=0;i<n;i++) scanf("%d", s+i);

    int c = 0;

    int t;
    for(;;c++){
      map<int,int> m;
      for(int i=0;i<n;i++){
        if(m.find(s[i]) == m.end()){
          m.insert(pair<int,int>(s[i], 1));
        }else{
          m[s[i]]++;
        }
      }

      int k = 0;
      for(int i=0;i<n;i++){
        if(s[i] != m[s[i]]) k++;
        s[i] = m[s[i]];
      }
      
      if(k==0) break;
    }
    printf("%d\n", c);
    for(int i=0;i<n;i++){
      printf("%d", s[i]);
      if(i==n-1) printf("\n");
      else printf(" ");
    }
  }
}

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

bool isSame(vector<int> A, vector<int> B){
	for(int i=0;i<A.size();i++)
		if(A[i] != B[i])
			return false;
	return true;
}

int main(){
	while(1){
		int n, num, count = 0;
		vector<int> A, B;

		cin>>n;
		if(n == 0)
			break;

		for(int i=0;i<n;i++){
			cin>>num;
			A.push_back(num);
			B.push_back(0);
		}

		for(int i=0;i<n;i++){
			int c = 0;
			for(int j=0;j<n;j++)
				if(A[i] == A[j])
					c++;
			B[i] = c;
		}

		while(1){
			int cnt[13] = {0};
			for(int i=0;i<n;i++){
				B[i] = A[i];
				cnt[A[i]]++;
			}

			for(int i=0;i<n;i++)
				A[i] = cnt[B[i]];

			if(isSame(A, B))
				break;
			else
				count++;
		}

		cout<<count<<endl;
		for(int i=0;i<n;i++){
			if(i != 0)
				cout<<" ";
			cout<<A[i];
		}
		cout<<endl;

	}
	return 0;
}