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*****/
#include <iostream>
#include <fstream>

/*****デバッグ定義*****/
//#define DEBUG
/*****マクロ定義*****/

/*****名前空間*****/
using namespace std;

/*****グローバル変数置き場*****/
int *array;
int *appearance;
int ope_num;
int n;
int count;
/*****その他関数置き場*****/
int Operation(){
	static int *app_old = new int [n];
	int num;
	int appear;
	int check;
	for(int i=0;i<n;i++){
		num = array[i];
		appear = 0;
		for(int j=0;j<n;j++)
			if(array[j] == num)
				appear ++;
		appearance[i] = appear;
	}
	for(check=0;check<n;check++)
		if(appearance[check] != array[check])
			break;
	for(int i=0;i<n;i++)
		array[i] = appearance[i];
	if(check == n)	return 1;
	count++;
	return 0;
}
/*****main関数*****/
int main(){
	/*****ファイルオープン*****/
#ifdef DEBUG
	ofstream fout("output.txt");
	ifstream fin("input.txt");
	if(!fout || !fin){
		cout << "Can't open the file.\n";
		return 0;
	}
#endif
	/*****変数置き場*****/
	/*****処理部*****/
	while(1){
		cin >> n;
		if(n==0)	break;
		array = new int [n];
		appearance = new int [n];
		for(int i=0;i<n;i++){
			cin >> array[i];
			appearance[i] = array[i];
		}
		count = 0;
		while(!Operation());
		cout << count << endl;
		for(int i=0;i<n;i++){
			if(i!=0)	cout << " ";
			cout << appearance[i];
		}
		cout << endl;
	}
	/*****処理終了後*****/
#ifdef DEBUG
	fout.close();
	fin.close();
#endif
	return 0;
}

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

int main() {
  int n;
  while(cin >> n) {
    int s[12] = {0},c[12] = {0},c2[12] = {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-1;i++) {
      cout << c[i] << " ";
    }
    cout << c[n-1] << endl;
  }
}

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[n-1]);
	}
	return 0;
}

C++: #include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<time.h>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double EPS=1e-10;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
int main(){
	int n;
	while(cin>>n,n){
		vector<int>in(n);
		rep(i,n)cin>>in[i];
		int co=0;
		while(1){
			co++;
			map<int,int>a;
			rep(i,n)a[in[i]]++;
			bool h=true;
			rep(i,n){
				if(in[i]!=a[in[i]])h=false;
				in[i]=a[in[i]];
			}
			if(h)break;
		}
		cout<<co-1<<endl;
		rep(i,n-1)cout<<in[i]<<" ";
		cout<<in[n-1]<<endl;
	}
}

C++: //include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//typedef
//------------------------------------------
typedef vector<int> vint;
typedef vector<vint> vvint;
typedef vector<string> vstring;
typedef pair<int, int> pint;
typedef pair<pint, int> ppint;
typedef pair<int, pint> pintp;
typedef unsigned int uint;
typedef long long llint;
typedef unsigned long long int ullint;

//container util
//------------------------------------------
#define all(a) (a).begin(),(a).end()
#define pb push_back
#define mp make_pair
#define EXIST(v,i) (find((v).begin(), (v).end(), i) != (v).end())
#define ERASE(v,i) (v).erase(remove((v).begin(),(v).end(),i),(v).end())
#define me (*this)

//repetition
//------------------------------------------
#define rep(i,s) for(int i=0; i<(int)(s); i++)

//constant
//--------------------------------------------
const int INF = 100000000;
const double EPS = 1e-10;
const double PI  = acos(-1.0);

//clear memory
#define CLEAR(a) memset((a), 0 ,sizeof(a))

//debug
#define debug(x)  cerr << #x << " = " << (x) << endl

struct POS {
	int x, y;
};

POS vec[4] = {
	{1, 0}, // ツ右
	{0, -1}, // ツ湘」
	{-1, 0}, // ツ債カ
	{0, 1} // ツ可コ
};

vint nextAry(vint prev) {
	vint ret;
	rep(i,prev.size()) {
		ret.push_back(count(all(prev), prev[i]));
	}
	return ret;
}

int main() {
	while(1) {
		static int n;
		cin >> n;
		if(!n)
			break;
		vint ary(n);
		rep(i,n) {
			cin >> ary[i];
		}
		int ans = 0;
		bool f = true;
		while(f) {
			ans++;
			vint next = nextAry(ary);
			if(next == ary) {
				f = false;
			}
			ary = next;
		}
		cout << ans - 1 << endl;
		rep(i,ary.size()) {
			printf("%d", ary[i]);
			if(i < ary.size() - 1)
				printf(" ");
		}
		cout << endl;
	}
	return 0;
}

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