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

bool isEqualArray(int n, int* s1, int* s2) {
    for (int i = 0; i < n; i++) {
        if (s1[i] != s2[i]) {
            return false;
        }
    }
    return true;
}

int main() {
    while (true) {
        int n;
        cin >> n;
        if (n == 0) {
            break;
        }
        int* s1 = new int [n];
        for (int i = 0; i < n; i++) {
            cin >> s1[i];
        }
        int count = 0;
        int* s2 = new int [n];
        while (!isEqualArray(n, s1, s2)) {
            for (int i = 0; i < n; i++) {
                s2[i] = s1[i];
            }
            for (int i = 0; i < n; i++) {
                int exist = 0;
                for (int j = 0; j < n; j++) {
                    if (s2[i] == s2[j]) {
                        exist++;
                    }
                }
                s1[i] = exist++;
            }
            count++;
        }
        cout << count - 1 << endl;
        for (int i = 0; i < n - 1; i++) {
            cout << s1[i] << " ";
        }
        cout << s1[n - 1] << endl;
        delete[] s1;
        delete[] s2;
    }
}

C++: #include <iostream>
using namespace std;
int main(){
	int i,n;
	while(cin >> n, n){
		int p,s[3][14]={0};
		for(i=1;i<=n;i++) cin >> s[0][i]; 
		for(p=0;;p++){
			for(i=1;i<=n;i++) s[2][s[0][i]] ++;
			for(i=1;i<=n;i++) s[1][i] = s[2][s[0][i]];			
			for(i=1;i<=n;i++) if(s[0][i] != s[1][i]) break;
			if(i>n) break;
			for(i=1;i<=n;i++){
				s[0][i] = s[1][i];
				s[2][i] = 0;
			}
		}
		cout << p << endl;
		for(i=1;i<=n;i++) cout << s[1][i] << ' ';
		cout << endl;
	}
}

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

int ans[114][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>
#include<map>
using namespace std;
int main(void){

    int n;

    while(cin>>n){
        if(n==0)break;
        int a[13];
        map<int,int> b;
        int c[13];
        for(int i=0;i<n;i++){
            cin>>a[i];
            b[a[i]]++;
        }
        int j=0;
        while(1){

            bool flg = false;
            for(int i=0;i<n;i++){
                c[i] = b[a[i]];
                if(c[i]!=a[i])flg = true;
                //cout<<c[i]<<" ";
            }
            //cout<<endl;
            if(!flg)break;
            b.clear();
            for(int k=0;k<n;k++){
                a[k] = c[k];
                b[a[k]]++;
            }
            j++;
        }
        cout<<j<<endl;
        for(int i=0;i<n;i++){
            cout<<c[i]<<" ";
        }
        cout<<endl;

    }

    return 0;
}

C++: #include <iostream>
using namespace std;
int n,t,s[100],sa[100];
void angel(int turn){
    int cnt=0;
    for(int i=0;i<n;i++){
        for(int o=0;o<n;o++){
            if(sa[i]==sa[o]){
                cnt++;
            }
        }
        s[i]=cnt;
        cnt=0;
    }
    int check=0;
    for(int i=0;i<n;i++){
        if(s[i]!=sa[i]){
            check=1;
        }
    }
    if(check==0){
        t=turn;
    }
    else{
        for(int i=0;i<n;i++){
            sa[i]=s[i];
        }
        angel(turn+1);
    }
}
int main(void){
    cin>>n;
    while(n!=0){
        for(int i=0;i<n;i++){
            cin>>s[i];
            sa[i]=s[i];
        }
        angel(0);
        cout<<t<<endl;
        for(int i=0;i<n;i++){
            if(i<n-1){
                cout<<s[i]<<' ';
            }
            else{cout<<s[i];}
        }
        cout<<endl;
        cin>>n;
    }
    return 0;
}

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

int a,c[20],d[20];
int main(){
  while(true){
    for(int i=0;i<20;i++) 
      {c[i]=0;d[i]=0;}
    cin>>a;
    if(a==0){break;}
    for (int i=0;i<a;i++){
      cin>>c[i];}
    int meta=0;
    while(true){
      for(int i=0;i<a;i++){
	for(int j=0;j<a;j++){ 
	  if(c[i]==c[j]){d[i]++;}
	}
      }
      int k=0;
      for(int i=0;i<a;i++)
	{ if(c[i]==d[i]){k++;}
	  c[i]=d[i];
	  d[i]=0;}
 
      if(k>a-2){break;}
      meta++;
    }
    printf("%d\n",meta);
    for(int i=0;i<a;i++){
      printf("%d",c[i]);
      if(i!=a-1){printf(" ");}
    }
    
    
  }
}

C++: #include<iostream>
#include<map>
using namespace std;
typedef map<int, int> mii;

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

void printline(int *line, int n){
  std::cout << "printline:" << std::endl;
  for (int i = 0; i < n; i++) {
    std::cout << line[i] << " ";
  }
  std::cout << std::endl;
}

int main(){
  int n;
  while(cin >> n, n){
    int numl[n], newl[n], ans = 0;
    mii counter;

    for (int i = 0; i < n; i++) {
      cin >> numl[i];
      
      if(counter.find(numl[i]) == counter.end()){
        counter[numl[i]] = 1;
      }else{
        counter[numl[i]]++; 
      }
    }
    
    while(!check(newl, numl, n)){
      ans++;
      for (int i = 0; i < n; i++) {
        newl[i] = numl[i];
        numl[i] = counter[numl[i]];
      }
      
      counter.clear();

      for (int i = 0; i < n; i++) {
        if(counter.find(numl[i]) == counter.end()){
          counter[numl[i]] = 1;
        }else{
          counter[numl[i]]++; 
        }        
      }

      //printline(numl, n);
    }
    std::cout << ans - 1 << std::endl;
    for (int i = 0; i < n; i++) {
      std::cout << newl[i] << " ";
    }
    std::cout << std::endl;
  }
  return 0;
}

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

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

    vector<int> S(n);
    for (int i = 0; i < n; ++i)
      scanf("%d", &S[i]);

    int cnt = 0;
    for ( ; ; ) {
      vector<int> C(n);
      map<int, int> freq;

      for (int i = 0; i < n; ++i)
	++freq[S[i]];
      for (int i = 0; i < n; ++i)
	C[i] = freq.find(S[i])->second;

      bool same = true;
      for (int i = 0; i < n; ++i) {
	if (S[i] != C[i])
	  same = false;
      }
      
      if (same)
	break;
      ++cnt;
      swap(C, S);
    }
    printf("%d\n", cnt);
    for (int i = 0; i < n-1; ++i)
      printf("%d ", S[i]);
    printf("%d\n", S[n-1]);
  }
  return 0;
}