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 <stdio.h>
#include <iostream>

using namespace std;

int main() {
	int n;
	int number[12];
	int hantei;
	int count;

	while (cin >> n) {
		if (n == 0) {
			break;
		}
		int counter[100] = {0};
		for (int i = 0; i < n; i++) {
			cin >> number[i];
			counter[number[i]-1]++;
		}
		hantei = 0;
		count = 0;
		while (1) {
			for (int i = 0; i < n; i++) {
				if (number[i] == counter[number[i]-1]) {
					if (i == n-1) {
						hantei = 1;
						break;
					}
					continue;
				} else {
					break;
				}
			}
			if (hantei == 1) {
				break;
			}
			for (int i = 0; i < n; i++) {
				number[i] = counter[number[i]-1];
			}
			for (int i = 0; i < 100; i++) {
				counter[i] = 0;
			}
			for (int i = 0; i < n; i++) {
				counter[number[i]-1]++;
			}
			count++;
		}
		cout << count << endl;
		for (int i = 0; i < n; i++) {
			cout << number[i] << " ";
		}
		cout << endl;
	}
	return 0;
}

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;
  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;
    }
  }
}

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

vector< int > alterSequence( vector< int >& seq ){
	int size = seq.size();
	vector< int > ret( size, 0 );
	for( int i = 0; i < size; ++i ){
		if( ret[ i ] != 0 ){
			continue;
		}
		int target = seq[ i ];
		int count = 0;
		for( int j = i; j < size; ++j ){
			if( seq[ j ] == target ){
				++count;
			}
		}
		for( int j = i; j < size; ++j ){
			if( seq[ j ] == target ){
				ret[ j ] = count;
			}
		}
	}
	return ret;
}

int main()
{
	int n;

	while( cin >> n && n ){
		vector< int > seq;
		for( int i = 0; i < n; ++i ){
			int d;
			cin >> d;
			seq.push_back( d );
		}
		int alt_count = 0;
		vector< int > alt;
		bool first = true;
		while( alt != seq ){
			if( first ){
				first = false;
			}else{
				seq = alt;
				++alt_count;
			}
			alt = alterSequence( seq );
		}
		cout << alt_count << endl;
		first = true;
		for( int i = 0; i < (int)seq.size(); ++i ){
			if( first ){
				first = false;
			}else{
				cout << " ";
			}
			cout << seq[ i ];
		}
		cout << endl;
	}
	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    while(cin>>n,n){
        int ans[1000]={},kawa[1000];
        for(int i=0;i<n;i++)cin>>kawa[i];
        for(int i=0;;i++){
            int num[10001]={};
            for(int j=0;j<n;j++)num[kawa[j]]++;
            bool rever=1;
            for(int j=0;j<n;j++){
                kawa[j]=num[kawa[j]];
                if(kawa[j]!=ans[j])rever=0;
            }
            if(rever){
                cout<<i<<endl<<kawa[0];
                for(int j=1;j<n;j++)cout<<" "<<kawa[j];
                cout<<endl;
                break;
            }
            else for(int j=0;j<n;j++)ans[j]=kawa[j];
        }
    }
}

C++: #include "bits/stdc++.h"

using namespace std;

typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;

#define dump(x)  cerr << #x << " = " << (x) << endl
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back

int num[14]={};

bool DO(int n){
	int tmp[14]={};
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			if(num[i]==num[j])tmp[i]++;
		}
	}

	bool flag=true;
	for(int i=1;i<=n;i++)if(num[i]!=tmp[i])flag=false;
	if(flag)return true;
	for(int i=1;i<=n;i++)num[i]=tmp[i];
	return false;
}

int main(){
	int n;
	while(cin>>n){
		if(n==0)break;
		int c=0;
		int ans;
		rep(i,n)cin>>num[i+1];

		while(1){
			c++;
			if( DO(n) ){
				ans=c;
				break;
			}
		}
		cout<<ans-1<<endl;
		for(int i=1;i<=n;i++){
			if(i!=1)cout<<" ";
			cout<<num[i];
		}
		cout<<endl;

	}
}

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

using namespace std;


int main() {

  int n;
  vector<int> s;

  vector<int> prev,n_s;
  map<int,int> runlength;
  int count;


  while(cin >> n) {

    if(n==0) break;

    s.clear();

    for(int i=0;i<n;i++) {

      int tmp;

      cin >> tmp;

      s.push_back(tmp);

    }

    n_s=s;

    //for(int i=0;i<temp.size();i++) cout << s[i] << " ";

    count=0;

    do {

      prev=n_s;

      runlength.clear();

      for(int i=0;i<n;i++) runlength[n_s[i]]++;

      for(int i=0;i<n;i++) n_s[i]=runlength[n_s[i]];

      if(prev==n_s) break;
      /*
      for(int i=0;i<n;i++) {

	if(i==0) cout << n_s[0];

	else cout << "  " << n_s[i];

      }
      */
      count++;

    } while(1);

    cout << count << endl;

    for(int i=0;i<n;i++) {

      if(i==0) cout << n_s[0];

      else cout << " " << n_s[i];

    }

    cout << endl;

  }

  return 0;

}

C++: #include <iostream>
#include <cstdio>
#include <cstdlib>
using namespace std;
int main(void){
  char d1[12],d2[12];
  int n1,n2;
  int n,a;
  while(cin>>n,n!=0){
    for(int i=0;i<n;i++){
      scanf("%d",&d2[i]);
      d2[i]+='0';
    }
    a=0;
    n1=0;
    n2=atoi(d2);
    while(n1!=n2){
      n1=n2;
      for(int j=0;j<n;j++){
	d1[j]=d2[j];
	d2[j]=0;
      }
      for(int j=0;j<n;j++){
	for(int k=0;k<n;k++){
	  if(d1[j]==d1[k]){
	    d2[j]++;
	  }
	}
	d2[j]+='0';
      }
      n2=atoi(d2);
      a++;
    }
    cout<<a-1<<endl;
    for(int j=0;j<n-1;j++){
      printf("%d ",d1[j]-'0');
    }
    cout<<d1[n-1]-'0'<<endl;
  }
  return 0;
}