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;

int main()
{
    int n;
    while(cin >> n){
        if(n==0)
            break;
         int s[2][12];
         for(int i=0;i<n;i++){
             cin >> s[0][i];
         }
         int dif,cycle=0;
         do{
             dif = 0;
             for(int i=0;i<n;i++){
                 int a = 0;
                 for(int k=0;k<n;k++){
                     if(s[0][i]==s[0][k])
                         a++;
                 }
                 s[1][i] = a;
             }
             
             for(int i=0;i<n;i++){
                 if(s[0][i]!=s[1][i])
                     dif++;
                 s[0][i] = s[1][i];
             }
             cycle++;
         }while(dif != 0);
         
         cout << --cycle << endl;
         for(int i=0;i<n;i++){
             if(i!=0)
                 cout << " ";
             cout << s[0][i];
         }
         cout << endl;
     }
     return 0;
 }

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

int main(){
	int n;
	while(cin>>n,n){
		vector<int> v(n);
		for(int i=0;i<n;i++){
			cin>>v[i];
		}
		int ans=0;
		while(1){
			map<int,int> ma;
			for(int i=0;i<n;i++){
				ma[v[i]]++;
			}
			vector<int> tmp(n);
			for(int i=0;i<n;i++){
				tmp[i]=ma[v[i]];
			}
			bool f=true;
			for(int i=0;i<n;i++){
				if(tmp[i]!=v[i]){
					f=false;
					ans++;
					break;
				}
			}
			if(f){
				cout<<ans<<endl;
				for(int i=0;i<n;i++){
					if(i) cout<<" ";
					cout<<v[i];
				}
				cout<<endl;
				break;
			}
			v=tmp;
		}
	}
}

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-1){break;}
      meta++;
    }
    printf("%d\n",meta);
    for(int i=0;i<a;i++){
      printf("%d",c[i]);
      if(i!=a-1){printf(" ");}
    }
    printf("\n");
    
  }
}

C++: #include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <algorithm>
#include <map>
#include <set>
#include <cstdio>
#include <cmath>
#define rep(i,l,n) for(lint i=l;i<n;i++)
#define rer(i,l,n) for(lint i=l;i<=n;i++)
#define all(a) a.begin(),a.end()
#define o(a) cout<<a<<endl
#define pb(a) push_back(a)
#define mk(a,b) make_pair(a,b)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef vector<int> vi;
typedef vector<lint> vli;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

int main(){
	int n;
	string s;
	while(cin>>n){
		if(n==0) break;
		int ct=0;
		int s[13]={};
		rep(i,0,n){
			cin>>s[i];
		}
		int ans[13]={};
		for(ct=0;;ct++){
			rep(i,0,n){
				ans[i]=0;
			}
			int d[13]={};
			rep(i,0,n){
				d[s[i]]++;
			}
			rep(i,0,n){
				ans[i]=d[s[i]];
			}
			int c=0;
			rep(i,0,n){
				if(ans[i]==s[i]) c++;
			}
			if(c==n) break;
			rep(i,0,n){
				s[i]=ans[i];
			}
		}
		o(ct);
		rep(i,0,n){
			if(i==0) cout<<ans[i];
			else cout<<" "<<ans[i];
		}
		cout<<endl;
	}
}

C++: #include <bits/stdc++.h>
using namespace std;

int main(){
	int n;
	while(cin>>n , n){
		vector<int> a(n);
		int cnt=0;
		for(int i=0;i<n;++i){
			cin >> a[i];
		}
		while(1){
			vector<int> b(n,0);
			for(int i=0;i<n;++i){
				for(int j=0;j<n;++j){
					if(a[i]==a[j]) b[i]++;
				}
			}
			if (a==b) break;
			for(int i=0;i<n;++i){
				a[i]=b[i];
			}
			++cnt;
		}
		cout << cnt << endl;
		for(int i=0;i<n-1;++i){
			cout << a[i] << " ";
		}
		cout << a[n-1] << endl;
	}
	return 0;
}

C++: //============================================================================
// Name        : aoj0108.cpp
// Author      : afterCmidday
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <cstring>
using namespace std;

int main() {
	int n, s[12], tmp[12], pre[12];
	while(cin >> n){
		for(int i = 0 ;i < n;i++){
			cin >> s[i];
		}
		memset(pre,-1,sizeof(pre));
		while(true){
			int i;
			for(i = 0;i < n;i++){
				if(pre[i] != s[i]){
					break;
				}
			}
			if(i == n){
				break;
			}
			for(i = 0;i < n;i++){
				pre[i] = s[i];
				tmp[i] = s[i];
			}
			for(i = 0;i < n;i++){
				int cnt = 0;
				for(int j = 0;j < n;j++){
					if(tmp[i] == tmp[j]){
						cnt++;
					}
				}
				s[i] = cnt;
			}
		}
		for(int i = 0;i < n;i++){
			cout << s[i];
			if(i != n - 1){
				cout << " ";
			}
		}
		cout << endl;
	}
	return 0;
}

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

    }

  }

  return 0;

}

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

int main(void){

  int S[12] , P[12] ,n ,c = 0,kaisu = 0,stop = 0;

  

  while(1){


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

    
    S[i] = 0;
    P[i] = 0;



  }


  kaisu = 0;
  stop = 0;
  c = 0;


  cin >> n ;

  if( n == 0 )break;



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


    cin >> S[i] ;
    
    P[i] = S[i] ;

  }



  while(1){

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

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

      if( S[i] == S[j]) c++  ;
         
          
    }

    P[i] = c ;
    
    c = 0;
  }




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





    if(  S[j] == P[j] ) stop++  ;
    else continue ; 

   
  
  }

  
   

  if( stop == n  )break;

  stop = 0;

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

      S[j] = P[j] ;
     
  
  }

 
 
   kaisu++;

 




  }

  cout << kaisu << endl;

  kaisu = 0 ;
  

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


    cout << P[i] << ' ';


  }

  cout << endl;


  }
  

  return 0;

}