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>

int main(){
  //nªzñ·³,countªvZñÌÂàè
  int n,count;
  while(std::cin >> n){
    //std::cout << n << std::endl;
    if(!n) {
      break;
    }
    int s[n];
    bool flag;
    int cnt[n];
    int cnt_of[n];
    int new_s[n];
    int old_s[n];
    
    //üÍtF[Y
    for(int i=0;i<n;i++){
      std::cin >> s[i];
    }

    for(int ans=0;;ans++){
      //½Â é©ð¦é
      cnt[0]=s[0];
      cnt_of[0]=1;
      int count=0;
      
      //iÔÚª¡ÜÅÉoÄ«½©mF
      for(int i=1;i<n;i++){
	for(int j=0;;j++){
	  if(cnt[j]==s[i]){
	    cnt_of[j]++;
	    break;
	  }
	  if(j==count){
	    count++;
	    cnt[count]=s[i];
	    cnt_of[count]=1;
	    //	    std::cout << count <<"count+" << i << std::endl;
	    break;
	  }
	}
      }//iÔÚ[v
      
      flag = true;
      //eiÉlðãü
      for(int i=0;i<n;i++){
	for(int j=0;j<=count;j++){
	  if(cnt[j]==s[i]){
	    new_s[i]=cnt_of[j];
	    break;
	  }
	}
	if(new_s[i]!=s[i]){
	  flag = false;
	  s[i]=new_s[i];
	}
      }
      
      //mFpoÍ

      /*      for(int i=0;i<n;i++){
	std::cout << new_s[i] << " ";
      }
      std::cout << std::endl;
      */

      if(flag){
	std::cout << ans << std::endl;
	//mFpoÍ
	for(int i=0;i<n-1;i++){
	  std::cout << new_s[i] << " ";
	}
	std::cout << new_s[n-1];
	std::cout << std::endl;
	break;
      }
    }
  }//while
}

C++: #include <iostream>]
#include <math.h>
#include <algorithm>
#include <cstdio>
#include <map>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
int main()
{
  int n;
  while(true){
    cin>>n;
    if(n==0){break;}
    int *a=new int[n];
    map<int,int>Map;
    rep(i,n){
      cin>>a[i];
    }
    for(int cnt=0;;cnt++)
    {
      rep(i,n){
        Map[a[i]]++;
      }
      int *s=new int[a[i]];
      rep(i,n)
      {
        s[i]=Map[a[i]];
      }
      if(a==s)
      {
        cout<<cnt<<endl;
        rep(i,n){
          if(i!=0){
            cout<<" ";
          }
          cout<<a[i];
        }
        cout<<endl;
        break;
      }
      rep(i,n){
        s[i]=a[i];
      }
    }
  }
  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], exe;
	while(cin >> n,n){
		exe = 0;
		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++){
				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;
			}
			exe++;
			for(i = 0;i < n;i++){
				if(pre[i] != s[i]){
					break;
				}
			}
			if(i == n){
				break;
			}
		}
		cout << exe - 1 << endl;
		for(int i = 0;i < n;i++){
			cout << s[i];
			if(i != n - 1){
				cout << " ";
			}
		}
		cout << endl;
	}
	return 0;
}

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;

	while(1){
		cin >> N;

		if(N==0)break;

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

		c--;

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

		c=0;
	}

	return 0;
}

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

int main() {
  int n;
  while(cin >> n) {
    int s[10000] = {0},c[10000] = {0},c2[10000] = {0},k,check=1;
    if(n==0)break;

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

    for(int i=0;i<n;i++) {
      for(int j=0;j<n;j++) {
        if(c[i] == c[j]) {
          c2[i]++;
        }
      }
    }

    //ok
    k=0;//k=1;
    while(check){
      check = 0;

      int c2[10000] = {0};
      for(int i=0;i<n;i++) {
        for(int j=0;j<n;j++) {
          if(c[i] == c[j]) {
            c2[i]++;
          }
        }
      }
      for(int i=0;i<n;i++) {
        if(c2[i] != c[i]) {
          for(int j=0;j<n;j++) {
            c[j] = c2[j];
          }
          check = 1;
          k++;
        }
      }

    }
    cout << k << endl;
    for(int i=0;i<n;i++) {
      cout << c[i] << " ";
    }
    cout << "\b" << endl;
  }
}

C++: #include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip> 
#include <complex> 
#include <string>
#include <vector> 
#include <list>
#include <deque> 
#include <stack> 
#include <queue> 
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <utility>
#include <algorithm> 
#include <numeric> 
#include <typeinfo> 
#include <cstdio>
#include <cstdlib> 
#include <cstring>
#include <cmath>
#include <climits> 
#include <ctime> 

using namespace std;

int main(void){
	int n;
	int a;
	int s[12];
	int sc[13];
	int ans2=0;
	bool ans=true;
	while(1){
		for(a=0;a<=12;a++)sc[a]=0;
		ans2=0;
		cin >> n;
		if(n==0)break;
		for(a=0;a<n;a++){
			cin >> s[a];
			sc[s[a]]++;
		}
		while(1){
			ans=true;
			for(a=0;a<n;a++){
				if(s[a]!=sc[s[a]])ans=false;
				s[a]=sc[s[a]];
			}
			if(ans==true)break;
			else{
				ans2++;
				for(a=0;a<=12;a++)sc[a]=0;
				for(a=0;a<n;a++)sc[s[a]]++;
			}
		}
		cout << ans2 << endl;
		for(a=0;a<n-1;a++)cout << s[a] << ' ';
		cout << s[n-1] << endl;
	}
}