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

using namespace std;

int main(){
	int n[12],N,p[12],pc[12],pp[12],t,c=0,flg;

	cin >> N;
	for(int i=0;i<N;i++){
		cin >> n[i];
	}

	while(1){
		c++;
		flg=0;

		//initialize counter
		for(int j=0;j<N;j++){
			pc[j] = 0;
		}

		//count
		for(int i=0;i<N;i++){
			//pick up
			t = n[i];

			for(int j=0;j<N;j++){
				if(t==n[j]){
					pc[i]++;
				}
			}
		}

		//make p[]
		for(int i=0;i<N;i++){
			n[i] = pc[i];
		}

		//judge
		for(int i=0;i<N;i++){
			if(n[i]!=pp[i]){
				flg=1;
			}
		}

		//make pp[]
		for(int i=0;i<N;i++){
			pp[i] = n[i];
		}

		//if made p[]
		if(flg==0){
			break;
		}
	}

	cin >> t;

	cout << c-1 << endl;
	for(int i=0;i<N;i++){
		cout << pp[i] << " ";
	}

	return 0;
}

C++: #include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;i++)
#define EPS 1e-9
using namespace std;
typedef long long ll;
typedef pair<string, int>P;

int main() {
	int n;
	while (cin >> n, n) {
		vector<int>S, P;
		rep(i, n) {
			int a; scanf("%d", &a);
			S.push_back(a);
		}
		int cnt = 0;
		while (1) {
			rep(i, n) {
				P.push_back(count(S.begin(), S.end(), S[i]));
			}
			if (P == S)break;
			S = P;
			P.clear();
			cnt++;
		}
		cout << cnt << endl;
		rep(i, P.size()) {
			cout << P[i] << (i == P.size() - 1 ? '\n' : ' ');
		}
	}
}

C++: #include<iostream>
using namespace std;
int main(void){

    int n;

    while(cin>>n){
        if(n==0)break;
        int a[13];
        int b[13]={0};
        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;
            for(int k=0;k<n;k++)b[k]=0;
            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 <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>
#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++){
			memset(ans,0,sizeof(ans));
			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 <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;

}

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;

}