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

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(A[i]==C[i])
          num++;
      }
      if(num==n)
        break;
      else{
        for(i=0;i<n;i++)
          C[i]=A[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",A[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])
          A[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;

int n;
int s[2][15];

void solve() {
	for (int i = 0; i < n; i++) {
		cin >> s[0][i];
	}
	
	int nw = 0, nx = 1;
	int rep = 0;
	while (1) {
		bool update = false;
		
		for (int i = 0; i < n; i++) {
			int t = s[nw][i];
			int cnt = 0;
			for (int j = 0; j < n; j++) {
				if (s[nw][j] == t) cnt++;
			}
			if (s[nw][i] != cnt) update = true;
			s[nx][i] = cnt;
		}
		
		if (!update) break;
		
		nw++; nw %= 2;
		nx++; nx %= 2;
		rep++;
	}
	
	cout << rep << endl;
	for (int i = 0; i < n - 1; i++) {
		cout << s[rep % 2][i] << " ";
	}
	cout << s[rep % 2][n - 1] << endl;
}

int main() {
	while (1) {
		cin >> n; if (n == 0) break;
		solve();
	}
	
	return 0;
}

C++: #include <stdio.h>
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <fstream>
#include <sstream>
#include <math.h>

using namespace std;



int n;

int main(){
    while(cin>>n){
        int s[12]={0};
        int c[12]={0};
        if(n==0)break;
        for(int i=0; i<n; i++){
            cin>>s[i];
        }
        
        int count=0;
        while(1){
            count++;
            
            
            for(int i=0; i<n; i++){
                for(int j=0; j<n; j++){
                    if(s[i]==s[j]){
                        c[i]++;
                    }
                }
            }
            
            bool flag=true;
            for(int i=0; i<n; i++){
                if(s[i]!=c[i])flag=false;
            }
            if(flag)break;
            
            for(int i=0; i<n; i++){
                s[i]=c[i];
                c[i]=0;
            }
        }
        
        cout<<count-1<<endl;
        cout<<c[0];
        for(int i=1; i<n; i++){
            cout<<" "<<c[i];
        }
        cout<<endl;
    }
}

C++: #include<iostream>
#include<cmath>
using namespace std;
int main(){
long n,a[12],b[12],i,j,k,m=0;
while(cin>>n){
if(n==0)break;
for(i=0;i<n;i++)cin>>a[i];
for(;;){
for(i=0;i<n;i++){
for(k=0,j=0;j<n;j++)if(a[i]==a[j])k++;
b[i]=k;
}
for(i=0;i<n;i++)if(a[i]!=b[i])break;
if(i!=n)m++;else break;
for(i=0;i<n;i++)a[i]=b[i];
}
cout<<m<<endl;
cout<<b[0];
for(i=1;i<n;i++)cout<<" "<<b[i];
cout<<endl;
}
return 0;
}

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

int n;
int x[10000];

int main(){
	while(scanf("%d", &n),n){
		vector<int> tmp(n);
		vector<int> num(n);
		int t = 0;
		for(int i = 0; i < n; i++) scanf("%d", &num[i]);
		while(true){
			for(int i = 0; i < 1000; i++) x[i] = 0;
			for(int i = 0; i < n; i++) x[num[i]]++;
			for(int i = 0; i < n; i++) num[i] = x[num[i]];
			if(tmp == num){
				printf("%d\n%d", t, num[0]);
				for(int i = 1; i < n; i++) printf(" %d", num[i]);
				printf("\n");
				break;
			} else tmp = num;
			t++;
		}
	}
}

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

int main() {
	int n;
	while (cin >> n, n) {
		int suret[12];
		int cpy[12];
		for (int i = 0;i < n;i++)cin >> suret[i];

		int ans = 0;
		while (1) {
			for (int i = 0;i < n;i++) {
				int a = 0;
				for (int j = 0;j < n;j++) {
					if (suret[i] == suret[j])a++;
				}
				cpy[i] = a;
			}
			int flg = 1;
			for (int i = 0;i < n;i++) {
				if (suret[i] != cpy[i])flg = 0;
				suret[i] = cpy[i];
			}
			if (flg == 1)break;
			ans++;
		}
		cout << ans << endl;
		for (int i = 0;i < n;i++){
			cout << suret[i];
			if (i != n - 1)cout << ' ';
		}
		cout << endl;
	}
	return 0;
}

C++: #include <iostream>
using namespace std;
int main(){
    while(true){
        int n,b=0,a[10][12]={0},count=0,sum1=0,sum2=0;
            cin>>n;
        if(n==0)break;
            for(int i=0;i<n;i++){
                cin>>a[1][i];
            }
            while(true){
                b=b+1;
            for(int i=0;i<n;i++){
                count=0;
                for(int j=0;j<n;j++){
                    if(a[b][i]==a[b][j])count=count+1;
                }
                a[b+1][i]=count;
                sum1=sum1+count;
            }
                if(sum1==sum2)break;
                sum2=sum1;
                sum1=0;
        }
        for(int i=0;i<n;i++){
            cout<<a[b][i]<<" ";
        }
        cout<<endl;
    }
}

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

int ans[100][2][12];//二つ目の次元の0の0に数列の長さ、0の1に操作回数、1に答えの数列

int counter=0,flag=0;

void solve(){
	int n;
	cin >> n;
	if(n==0){flag=1;return;}
	ans[counter][0][0]=n;
	
	int S[12];//数列
	for(int i=0;i<n;i++){
		cin >> S[i];
	}
	
	bool check=false;//操作の有無のフラグ
	int time=0;//操作回数
	do{
		map<int,int> marker;
		for(int i=0;i<n;i++){
			marker[S[i]];
			marker[S[i]]++;
		}
		check=false;
		for(int i=0;i<n;i++){
			if(S[i]!=marker[S[i]]){
				check=true;
				S[i]=marker[S[i]];
			}
		}
		if(check) time++;
	}while(check);
	
	ans[counter][0][1]=time;
	for(int i=0;i<n;i++){
		ans[counter][1][i]=S[i];
	}
	counter++;
}

int main(){
	while(flag==0)solve();
	for(int i=0;i<counter;i++){
		cout << ans[i][0][1] << endl;
		for(int j=0;j<ans[i][0][0]-1;j++){
			cout << ans[i][1][j]<<" ";
		}
		cout << ans[i][1][ans[i][0][0]-1] << endl;
	}
}

C++: #include <iostream>
#define MAX_N 15
using namespace std;
int n,m=0,cnt,flag,change=0;
int s[MAX_N],p[MAX_N];

int main(){
	while(1){
		cin >> n;
		if(n==0)break;
		m=0;
		while(m!=n){
			cin >> s[m];
			m++;
		}
		while(1){
			for(int i=0;i<n;i++){
				cnt=0;
				for(int j=0;j<n;j++){
					if(s[i]==s[j])cnt++;
				}
				p[i]=cnt;
			}
			flag=0;
			for(int i=0;i<n;i++){
				if(s[i]==p[i])flag++;
				s[i]=p[i];
			}
			if(flag==n)break;
			change++;
		}
		cout <<change <<endl;
		for(int i=0;i<n-1;i++){
			cout << s[i]<<" ";
		}
		cout <<s[n-1]<<endl;
	}
	return 0;
}