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<stdio.h>
int a[12];
int b[12];
int d[12];
int p[30];
int main(){
	int c;
	while(scanf("%d",&c),c){
		for(int i=0;i<c;i++){
			scanf("%d",a+i);
			b[i]=a[i];
		}
		int count=0;
		while(1){
			for(int i=0;i<30;i++)p[i]=0;
			for(int i=0;i<c;i++)p[b[i]]++;
			for(int i=0;i<c;i++)d[i]=p[b[i]];
			bool ok=true;
			for(int i=0;i<c;i++)if(d[i]-b[i])ok=false;
			if(ok)break;
			for(int i=0;i<c;i++)b[i]=d[i];
			count++;
		}
		printf("%d\n",count);
		for(int i=0;i<c;i++)printf("%d ",d[i]);
		printf("\n");
	}
}

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<cstdio>
#include<cmath>
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<cstdlib>
#include<iomanip>
#include<queue>
#include<set>


using namespace std;

void Solution()
{
    int n;
    
    while (cin>>n, n)
    {
        vector<int> s(n), nextSequence(n);
        int count = 0;
        
        for (int i = 0; i < n; i++)
        {
            cin>>s[i];
        }
        
        while (1)
        {
            for (int i = 0; i < n; i++)
            {
                nextSequence[i] = 0;
                
                for (int j = 0; j < n; j++) //repeat this step for every element, so start from 0, everytime.
                {
                    if (s[i] == s[j])
                    {
                        nextSequence[i]++;
                    }
                }
            }
            
            if ( s == nextSequence)
            {
                cout<<count<<endl;
                
                for (int i = 0; i < n; i++)
                {
                    if (i != 0)
                    {
                        cout<<" ";
                    }
                    
                    cout<<s[i];
                }
                
                cout<<endl;
                break;
            }
            else
            {
                s = nextSequence;
                count++;
            }
        }
    }

}

int main()
{
    Solution();
    return 0;
}

C++: #include<iostream>
#include<string>
using namespace std;
int main(){
	int s[20],c[20];
	int n;
	while(true){
	    cin>>n;
		if(n==0)
			break;
	for(int i=0;i<n;i++)
		cin>>s[i];
	int d=0;
	while(true){
		for(int i=0;i<n;i++){
			int count=0;
			for(int j=0;j<n;j++){
				if(s[i]==s[j])
					count++;
			}
			c[i]=count;
		}
		bool t=true;
		for(int i=0;i<n;i++){
			if(s[i]!=c[i]){
				t=false;
				s[i]=c[i];
			}
		}
		if(t==true)
			break;
		d++;
	}
	cout<<d<<endl;
	for(int i=0;i<n;i++)
		cout<<s[i]<<" ";
	cout<<endl;
	}
    return 0;
}

C++: #include<iostream>
#include<vector>
#include<queue>
#include<algorithm>
#include<string>
#include<map>
using namespace std;
#define rep(i,n) for(int i = 0 ; i < n ; i++ )

int main(){
  int N;
  cin >> N;
  int cnt = 0;
  vector<int> data(N);
  rep(i,N) cin >> data[i];
  while("homo",++cnt){
    vector<int> now = data;
    rep(i,N) now[i] = count(data.begin(),data.end(),data[i]);
    if(now == data) break;
    data = now;
  }

  cout << cnt << endl;
  rep(i,N) cout << (i?" ":"") << data[i];
  cout << endl;
}

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

int main(){
	while(1){	
		int n, count=0;
		int before[13], after[13], c[1000];
	
		scanf(" %d", &n);
		if(n==0) break;
		for(int i=0; i<n; ++i)scanf(" %d", &before[i]);
				
		//roop
		bool flag=false;
		while(!flag){
			
			for(int i=0; i<=1000; ++i) c[i]=0;
			for(int i=0; i<n; ++i) c[before[i]]++;
			
			for(int i=0; i<n; ++i)
				after[i]=c[ before[i] ];	
			
			flag=true;
			for(int i=0; i<n; ++i){
				if(before[i]!=after[i]){
					flag=false;
					break;	
				}
			}
		
			/*for(int i=0; i<n; ++i)
				printf(" %d", after[i]);
			printf("\n");
			*/
			
			count++;
			for(int i=0; i<n; ++i) before[i]=after[i];
		}
		
		printf("%d\n", count-1);
		for(int i=0; i<n; ++i){
			printf("%d", after[i]);
			if(i<n-1) printf(" ");
		}
		printf("\n");
	}
	return 0;
}

C++: #include<stdio.h>
#include<iostream>
#include<list>
#include<map>
#include<math.h>
#include<vector>
#include<algorithm>
#include<string.h>
#include<iomanip>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) range(i,0,b)
#define debug(x) cout << "debug" << x << endl;
using namespace std;

int n, ans = 0;

void solve(int l1[], int count[]){
    int l2[12], sum = 0;
    int subcount[13] = {0};
    rep(i, n){
        l2[i] = count[ l1[i] ];
        subcount[ l2[i] ]++;
    }
    rep(i, n){
        sum+= l1[i] - l2[i];
    }
    if(sum != 0){
        ans++;
        solve(l2, subcount);
    }else{
        cout << ans << endl;
        rep(i, n){
            if(i == 0);
            else if(i == 1) cout << l1[i];
            else cout << ' ' << l1[i];
        }cout << endl;
    }
}

int main(){
    int l1[13], l2[13];
    while(cin >> n, n){
        int count[13] = {0};
        rep(i, n){
            cin >> l1[i];
            count[l1[i]]++;
        }
        ans = 0;
        solve(l1, count);
    }
}

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]];
      }
      
      for (int i = 0; i < n; i++) {
        counter[i] = 0;
      }
      
      for (int i = 0; i < n; i++) {
        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;
}