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<map>
#include<list>
using namespace std;

void requestAns(int num,map<int,int> dataMap,list<int> dataList){
	int count=0;
	for(;;count++){
		map<int,int> tmpMap;
		list<int> tmpList;
		list<int>::iterator it=dataList.begin();
		for(;it!=dataList.end();it++){
			int tmp=dataMap[*it];

			if(tmpMap[tmp]==0){
				tmpMap[tmp]++;
			}
			else tmpMap[tmp]++;
			tmpList.push_back(tmp);
		}

		if(tmpList==dataList)break;
		dataMap=tmpMap;
		dataList=tmpList;
	}
	cout<<count<<endl;
	list<int>::iterator it=dataList.begin();
	for(int i=0;it!=dataList.end();it++,i++){
		if(i)cout<<" ";
		cout<<dataMap[*it];
	}
	cout<<endl;

}


int
main(){
	int num;
	while(cin>>num&&num){
		map<int ,int> dataMap;
		list<int> dataList;

		for(int i=0;i<num;i++){
			int tmp;
			cin>>tmp;
			if(dataMap[tmp]==0){
				dataMap[tmp]++;
			}
			else dataMap[tmp]++;
			dataList.push_back(tmp);
			list<int>::iterator it=dataList.begin();
		}

		requestAns(num,dataMap,dataList);
	}


	return 0;
}

C++: #include <iostream>
#include <vector>
#include <map>

using namespace std;

int main() {
  int n;
  cin >> n;
  int s[2][n];
  while((cin >> s[0][0]), s[0][0] != 0){
    for(int i = 1; i < n ; i ++)
    {
      cin >> s[0][i];
    }
    bool fixed = false;
    int src_index = 0;
    int operation_count = 0;
    while(!fixed)
    {
      map<int, int> appearance_map;
      for(int i = 0; i < n ; i ++)
      {
        ++appearance_map[s[src_index][i]];
      }
      fixed = true;
      for(int i = 0; i < n; i++) {
        s[1-src_index][i] = appearance_map[s[src_index][i]];
        if(s[0][i] != s[1][i]){
          fixed = false;
        }
      }
      if(fixed)break;
      src_index = 1 - src_index;
      ++operation_count;
    }
    cout << operation_count << endl;
    for(int i = 0; i < n; i++) {
      cout << s[0][i] << " ";
    }
    cout << endl;
  }
}

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

int main ( void )
{
	int n; // ツ青板療アツづ個陳キツつウ
	while ( cin >> n && n != 0 )
	{
		vector <int> S(n);
		for ( int i = 0; i < n; i++ )
			cin >> S[i];

		vector <int> V(n);
		vector <int> V_next(n);
		V = S;

		int cnt = 0;
		while ( 1 )
		{
			for ( int i = 0; i < n; i++ )
			{
				V_next[i] = count( V.begin(), V.end(), V[i] );
			}
			cnt++;

			if ( V == V_next )
			{
				cnt--;
				break;
			}

			V = V_next;

		}

		cout << cnt << endl;
		for ( int i = 0; i < n; i++ )
		{
			cout << V[i];
			if ( i < n-1 )
				cout << " ";
		}
		cout << endl;

	}

	return 0;
}

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

#define rep(i,n) for(int i=0;i<n;i++)

int main(void){
	int i,j,n,count,flg;
	int p[12],tmp[12];

	while(cin>>n && n){
		rep(i,n) cin>>p[i];
		for(count=0;;count++){
			flg = 1;
			memset(tmp,0,sizeof(tmp));
			rep(i,n)rep(j,n)if(p[i]==p[j])tmp[j]++;
			rep(i,n)if(p[i]!=tmp[i]){flg=0;break;}
			if(flg) break;
			rep(i,n)p[i]=tmp[i];
		}
		cout<<count<<endl;
		rep(i,n-1)cout<<p[i]<<" ";
		cout<<p[n-1]<<endl;
	}

	return 0;
}

C++: #include <bits/stdc++.h>

using namespace std;

int SData[12], CData[12];
int CountOfData[101];

int solve(int n) {
	int count;
	bool flag;
	
	count = 0;
	while (1) {
		flag = false;
		for (int i = 0; i < n; i++) {
			CData[i] = CountOfData[SData[i]];
		}

		for (int i = 0; i < n; i++) {
			if (CData[i] != SData[i]) {
				flag = true;
				break;
			}
		}
		if (flag) {
			count++;
		}
		else
		{
			return count;
		}

		memset(CountOfData, 0, sizeof(CountOfData));
		for (int i = 0; i < n; i++) {
			SData[i] = CData[i];
			CountOfData[CData[i]]++;
		}
	}
	
}

int main() {
	int n, sum;

	while (cin >> n, n) {
		memset(CountOfData, 0, sizeof(CountOfData));
		for (int i = 0; i < n; i++) {
			cin >> SData[i];
			CountOfData[SData[i]]++;
		}

		sum = solve(n);
		cout << sum << endl;
		for (int i = 0; i < n; i++) {
			cout << SData[i];
			if (i != n - 1) {
				cout << " ";
			}
		}
		cout << endl;
	}


	return 0;
}

C++: #include <iostream>
#include <map>
using namespace std;
int num[12];
int n,cnt;
int solve(){ 

  map<int,int > mp;
  mp.clear();
  int f = 0;
  for(int i = 0 ; i < n ; i++ ){
    mp[num[i]]++; 
  }
  for(int i = 0 ; i < n ; i++ ){
    if(num[i] != mp[num[i]] )f = 1;
    num[i] = mp[num[i]];
  }

  if(f == 1){
    cnt++;
    solve();
  }
}

int main(){

  while( cin >> n,n ){

    for(int i = 0 ; i < n ; i++ ){
      cin >> num[i];
    }
    cnt = 0;
    solve();
    cout << cnt << endl;
    for(int i = 0 ; i < n ; i++ ){
      if(i == 0)cout << num[i];
      else cout <<" "<< num[i]; 
    }
    cout << endl;
  }
}

C++: /*
	AOJ_0108: Operation of Frequency of Appearance
*/
#include	<iostream>
#include	<cstring>
#include	<queue>

using namespace std;

class Sequence {
private:
	int elements[12];	//数列の要素
	int length;			//数列の長さ
	const int _EMPTY;	//空欄を表す定数
public:
	/*コンストラクタ*/
	Sequence() : _EMPTY(-65536){
		for (int i = 0; i < 12; i++) {
			elements[i] = _EMPTY;
		}
	}
	/*メンバ関数*/
	void Insert(int ln, int *elm) {
		length = ln;
		for (int i = 0; i < ln; i++) {
			elements[i] = elm[i];
		}
	}
	int Operation(void) {
		int Order[12], Result[12], target_number, target_count;

		for (int i = 0; i < length; i++) {
			Order[i] = elements[i];
		}
		for (int i = 0; i < length; i++) {
			queue<int> listChange;
			target_count = 0;
			if (Order[i] == _EMPTY) { continue; }
			target_number = Order[i];
			for (int j = i; j < length; j++) {
				if (Order[j] == _EMPTY) { continue; }
				if (Order[j] == target_number) {
					Order[j] = _EMPTY;
					listChange.push(j);
					target_count++;
				}
			}
			while (!listChange.empty()) {
				Result[listChange.front()] = target_count;
				listChange.pop();
			}
		}
		if (memcmp(Result, elements, sizeof(int) * length) == 0) {
			return 1;
		} else {
			for (int i = 0; i < length; i++) {
				elements[i] = Result[i];
			}
			return -1;
		}
	}
	void ShowSequence() {
		for (int i = 0; i < length; i++) {
			if (i != 0) { cout << ' '; }
			cout << elements[i];
		}
		cout << endl;
	}
};

int main(void) {
	int length, s[12], t;
	
	while (1) {
		Sequence SEQ;
		t = 0;

		cin >> length;
		if (length == 0) { break; }

		for (int i = 0; i < length; i++) {
			cin >> s[i];
		}
		SEQ.Insert(length, s);
		while (SEQ.Operation() == -1) { t++; }
		cout << t << endl;
		SEQ.ShowSequence();
	}

	return 0;
}

C++: #include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<map>

using namespace std;

bool judge(int lineA[], int lineB[], int num)
{
	for(int i = 0; i < num; i++)
	{
		if(lineA[i] != lineB[i])
		{
			return false;
		}
	}
	return true;
}

int main()
{
	int num, lineA[16], lineB[16];
	
	while(cin >> num)
	{
		if(!num) break;
		int amo = 0;
		for(int i = 0; i < num; i++)
		{
			cin >> lineA[i];
		}
		while(1)
		{
			for(int i = 0; i < num; i++)
			{
				lineB[i] = 0;
				for(int j = 0; j < num; j++)
				{
					if(lineA[i] == lineA[j])
					{
						++lineB[i];
					}
				}
			}

			if( judge(lineA, lineB, num) ) break;
			else amo++;

			for(int i = 0; i < num; i++)
			{
				lineA[i] = 0;
				for(int j = 0; j < num; j++)
				{
					if(lineB[i] == lineB[j])
					{
						++lineA[i];
					}
				}
			}
			if( judge(lineA, lineB, num) ) break;
			else amo++;
		}
		
		cout << amo << endl;
		for(int i = 0; i < num; i++)
		{
			cout << lineA[i];
			if(i != num -1) cout << ' ';
		}
		cout << endl;
	}
}