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<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<cctype>
#include<complex>
#include<iostream>
#include<sstream>
#include<algorithm>
#include<functional>
#include<utility>
#include<vector>
#include<string>
#include<stack>
#include<queue>
#include<map>
 
using namespace std;
const int dx[] = {1,0,-1,0},dy[] = {0,1,0,-1};
#define INF 1e+9
#define EPS 1e-9
#define rep(i,j) for(int i = 0; i < (j); i++)
#define reps(i,j,k) for(int i = j; i < (k); i++)
typedef long long ll;
bool check(int data[],int bef[],int n){
    rep(i,n){
        if(data[i] != bef[i])return false;
    }
    return true;
}
int main(){
    int n;
    while(scanf("%d",&n),n){
        int data[12800]={0};
        int bef[12800]={0};
        rep(i,n){
            scanf("%d",&data[i]);
        }
        int ans=0;
        while(true){
            if(check(data,bef,n)){
                printf("%d\n",--ans);
                rep(i,n-1){
                    printf("%d ",data[i]);
                }
                printf("%d\n",data[n-1]);
                break;
            }
            ans++;
            rep(i,n)bef[i] = data[i];
            int memo[12800]={0};
            rep(i,n){
                if(memo[bef[i]])data[i] = memo[bef[i]];
                else{
                    int cnt = 0;
                    rep(j,n)if(data[i] == bef[j])cnt++;
                    memo[data[i]] = cnt;
                    data[i] = cnt;
                }
            }
        }
    }
    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 A[300],B[300],C[300]={0},D[300]={0};

int main(void){
  int i,n,m,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);
      num=0;
      for(i=0;i<n;i++){
        if(D[i]==C[i])
          num++;
      }
      if(num==n)
        break;
      else{
        for(i=0;i<n;i++){
          C[i]=D[i];
          A[i]=D[i];
        }
        ans+=1;
      }
    }
    Answer(n,ans);
  }
  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;
  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 <bits/stdc++.h>

#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)

using namespace std;


int main()
{
	int n;
	while(cin >>n){
		if(n ==0) break;
		vector<int> p(n);
		rep(i,n){ cin >> p[i];}
		int ans =0;
		vector<int> q(105), np(n, -1);
		while(np != p){
			ans++;
			fill(q.begin(), q.end(),0);
			rep(i,n) q[p[i]]++;
			rep(i,n) np[i] = q[p[i]];
			//for(auto x :np) printf("%d, ",x); puts("");
			swap(p, np);
		}
		cout << ans -1 <<"\n";
		rep(i,n)  printf("%s%d",(i? " ":""),p[i]);
		printf("\n");
		
		
	}
	return 0;

}

C++: #include<iostream>
#include<map>
#include<string>
#include<stdlib.h>

int OFA();//Operation of Frequency of Appearance

void listen_nums(int nums[],const int count_nums);
void calc_appearance(int nums[],int appearance[],const int count_nums);
void write_calcedArray(int nums[],int appearance[],const int count_nums);
bool is_notMoved(int nums[],int appearance[],const int count_nums);
void echo_intArray(int array[],const int length);

//-------------------------main-------------------------------
int main()
{
	while(OFA());
	return 0;
}

int OFA()
{
	using namespace std;
	int count_nums;
	cin>>count_nums;
	if(!count_nums)
	{
		return 0;
	}
	int nums[count_nums];
	listen_nums(nums,count_nums);
	int appearance[count_nums];
	
	int calcCount=0;
	for(;1;)
	{
		calc_appearance(nums,appearance,count_nums);
		if(is_notMoved(nums,appearance,count_nums))
		{
			cout<<calcCount<<endl;
			echo_intArray(appearance,count_nums);
			return 1;
		}
		else
		{
			calcCount++;
			write_calcedArray(nums,appearance,count_nums);//numsの先頭ポインタを操作後文字列に置き換え
		}
	}
	
}
//-----------------------------------------------------------

void listen_nums(int nums[],const int count_nums)
{
	using namespace std;
	int i=0;
	string str;
	while(i<count_nums-1)
	{
		getline(cin,str,' ');
		nums[i]=atoi(str.c_str());
		i++;
	}
	cin>>nums[i];
}

void calc_appearance(int nums[],int appearance[],const int count_nums)
{
	using namespace std;
	
	map<int,int> count_eachNums;
	
	int i;
	for(i=0;i<count_nums;i++)
	{
		if(count_eachNums.find(nums[i])==count_eachNums.end())
		{
			count_eachNums.insert(map<int,int>::value_type(nums[i],1));
		}
		else
		{
			count_eachNums[nums[i]]++;
		}
	}
	for(i=0;i<count_nums;i++)
	{
		appearance[i]=count_eachNums[nums[i]];
	}
}

void write_calcedArray(int nums[],int appearance[],const int count_nums)
{
	for(int i=0;i<count_nums;i++)
	{
		nums[i]=appearance[i];
	}
}

bool is_notMoved(int nums[],int appearance[],const int count_nums)
{
	for(int i=0;i<count_nums;i++)
	{
		if(nums[i]!=appearance[i])
		{
			return false;
		}
	}
	return true;
}
void echo_intArray(int array[],const int length)
{
	using namespace std;
	
	cout<<array[0];
	for(int i=1;i<length;i++)
	{
		cout<<" "<<array[i];
	}
	cout<<endl;
}

C++: #include <math.h>
#include <algorithm>
#include <string>
#include <iostream>
using namespace std;


bool mani(int a[12], int n)
{
	int b[12];
	fill(b, b + 12, 0);
	for (int i = 0; i < n; i++)
		for (int j = 0; j < n; j++)
			if (a[i] == a[j])
				b[i]++;
	bool f = true;
	for (int i = 0; i < n; i++)
	{
		if (a[i] != b[i])
		{
			f = false;
			break;
		}
	}
	for (int i = 0; i < n; i++)
		a[i] = b[i];
	return f;
}


int main()
{
	int n, a[12];
	while (cin >> n && n != 0)
	{
		int c = 0;
		for (int i = 0; i < n; i++)
			cin >> a[i];
		while (true)
		{
			if (mani(a, n))
				break;
			c++;
		}
		cout << c << endl;
		cout << a[0];
		for (int i = 1; i < n; i++)
			cout << " " << a[i];
		cout << endl;
	}
	return 0;
}