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 <bits/stdc++.h>

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 cnt = 0;
	while (1) {
	    vector<int> next(n);
	    for(int i = 0 ; i < n ; i++){
		next[i] = count(v.begin(),v.end(),v[i]);
	    }
 
	    if(v == next) break;
	    cnt++;
	    v = next;
	}
	cout << cnt << endl;
	for(int i = 0 ; i < n ; i++){
	    if(i) cout << " " << v[i];
	    else cout << v[i];
	}
	cout << endl;
    }
    return 0;
}

C++: #include<iostream>

int main(){
	int n;
	while(std::cin>>n){
		int ans=0,data[12],back[12];
		if(n==0)break;
		for(int i=0;i<n;i++)std::cin>>data[i],back[i]=data[i];
		while(true){
			for(int i=0;i<n;i++){
				int count=0;
				for(int j=0;j<n;j++){
					if(back[i]==back[j])count++;
				}
				data[i]=count;
			}
			bool f=true;
			for(int i=0;i<n;i++){
				if(data[i]!=back[i])f=false;
			}
			if(f)break;
			for(int i=0;i<n;i++)back[i]=data[i];
			ans++;
		}
		std::cout<<ans<<std::endl;
		for(int i=0;i<n;i++){
			if(i!=n-1)std::cout<<data[i]<<" ";
			else std::cout<<data[i];
		}
		std::cout<<std::endl;
	}
	return 0;
}

C++: #include <iostream>
#include <map>
#include <cstring>
using namespace std;
int main(){
	int n, s[12] = {0};
	while(cin >> n,n){
	for(int i = 0;i < n;i++){
		cin >> s[i];
	}

	int turn = 0;
	for(int i=10;i;i--){
		turn++;
		map<int,int> m;
		for(int i = 0;i < n;i++){
			m[s[i]]++;
		}//ツ古つ青板チツェツッツク
		int c[12];
		
		for(int i = 0;i < n;i++){
			c[i] = m[s[i]];
		}
		int j = 0;
		for(int i = 0;i < n;i++){
			j += (s[i] == c[i]);
		}

		if(j == n){
			cout << turn - 1 << endl;
			cout << s[0];
			for(int i = 1;i < n;i++){
				cout << " " << s[i];
			}
			cout << endl;
			break;
		}
		memcpy(s,c,sizeof(s));
	}
	}
}

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

int main() {
	int n ;
	while(1)
	{
		cin >> n ; if(!n) break;
		int cnt=0; map<int,int> m;
		int a[12]; for(int i=0;i<n;i++) cin >> a[i] ;
		while(1)
		{
			for(int i=0;i<n;i++) if(m.find(a[i])!=m.end()) m[a[i]]++; else m[a[i]]=1;
			int b[12];
			for(int i=0;i<n;i++) b[i]=m[a[i]];
			bool same=true;
			for(int i=0;i<n;i++) if(a[i]!=b[i]) {same=false; break;}
			if(same) break;
			cnt++; memcpy(a,b,sizeof(b)); m.clear();
		}
		cout << cnt << '\n' ;
		for(int i=0;i<n;i++) {if(i) cout << ' ' ; cout << a[i];}
		cout << '\n' ;
	}
}

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

void operate(int *s, int size) {
    map<int, int> ns;
    for (int i = 0; i < size; i++) {
        ns[s[i]]++;
    }
    for (int i = 0; i < size; i++) {
        s[i] = ns[s[i]];
    }
}

bool finish(int *s, int size) {
    int ns[size];
    for (int i = 0; i < size; i++) {
        ns[i] = s[i];
    }
    operate(ns, size);
    for (int i = 0; i < size; i++) {
        if (ns[i] != s[i]) {
            return false;
        }
    }
    return true;
}

int main() {
    int n;
    while (cin >> n, n != 0) {
        int s[n];
        for (int i = 0; i < n; i++) {
            cin >> s[i];
        }
        int count = 0;
        while (!finish(s, n)) {
            operate(s, n);
            count++;
        }
        cout << count << endl;
        cout << s[0];
        for (int i = 1; i < n; i++) {
            cout << ' ' << s[i];
        }
        cout << endl;
    }
    return 0;
}

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]; 
			if(s[0][i]>12) return 0;
		}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 <cstdio>
#include <map>
using namespace std;

int n;
int as[10000];
map<int, int> freq;

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

    for (int i=0; i<n; i++) {
      scanf("%d", &as[i]);
    }

    int times = 0;
    while (1) {
      freq.clear();
      for (int i=0; i<n; i++) {
        freq[as[i]]++;
      }

      int cnt = 0;
      for (int i=0; i<n; i++) {
        if (as[i] == freq[as[i]]) cnt++;
        as[i] = freq[as[i]];
      }

      if (cnt == n) break;
      times++;
    }

    printf("%d\n", times);
    printf("%d", as[0]);
    for (int i=1; i<n; i++) {
      printf(" %d", as[i]);
    }
    puts("");
  }
}

C++: #include <iostream>
using namespace std;
int main(){
	int n,data[12],tmp[12];
	bool f[12];
	while(1){
		cin>>n;
		if(n==0)break;
		for(int i=0;i<n;i++){
			cin>>data[i];
		}
		int ans=0;
		while(1){
			bool f=false;
			for(int i=0;i<n;i++){
				int cnt=0;
				for(int j=0;j<n;j++){
					if(data[i]==data[j])cnt++;
				}
				if(data[i]!=cnt)f=true;
				tmp[i]=cnt;
			}
			for(int i=0;i<n;i++){
				data[i]=tmp[i];
			}
			if(!f)break;
			ans++;
		}
		cout<<ans<<endl;
		for(int i=0;i<n-1;i++){
			cout<<data[i]<<" ";
		}
		cout<<data[n-1]<<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 <stdio.h>
#include <string.h>
void cpy(int src[],int dst[],int n){
	for(int i=0;i<n;i++) dst[i]=src[i];
}
void OFA(int S[],int n){
	int num[100];
	memset(num,0,sizeof(num));
	for(int i=0;i<n;i++) num[S[i]]++;
	for(int i=0;i<n;i++) S[i]=num[S[i]];
}

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

int main(){
	int S[12],tmp[12],n,count;
	while(1){
		scanf("%d",&n);
		if(!n) break;
		count=-1;
		for(int i=0;i<n;i++) scanf("%d",&S[i]);
		cpy(S,tmp,n);
		do{
			cpy(tmp,S,n);
			OFA(tmp,n);
			//for(int i=0;i<n;i++) printf("%d ",tmp[i]);
			count++;
		}while(!check(S,tmp,n));
		printf("%d\n",count);
		for(int i=0;i<n-1;i++) printf("%d ",S[i]);
		printf("%d\n",S[i]);
	}
	return 0;
}