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<string.h>
#include<stdio.h>
#include<stdlib.h>

int OFA();//Operation of Frequency of Appearance

void listen_nums(int nums[],const int count_nums);
void calc_appearance(int nums[],int appearance[],const int count_nums);
void write_calcedArray(int nums[],int appearance[],const int count_nums);
bool is_notMoved(int nums[],int appearance[],const int count_nums);
void echo_intArray(int array[],const int length);

//-------------------------main-------------------------------
int main()
{
	while(OFA());
	return 0;
}

int OFA()
{
	using namespace std;
	int count_nums;
	cin>>count_nums;
	if(!count_nums)
	{
		return 0;
	}
	int nums[count_nums];
	listen_nums(nums,count_nums);
	int appearance[count_nums];
	
	int calcCount=0;
	for(;1;)
	{
		calc_appearance(nums,appearance,count_nums);
		if(is_notMoved(nums,appearance,count_nums))
		{
			cout<<calcCount<<endl;
			echo_intArray(appearance,count_nums);
			return 1;
		}
		else
		{
			calcCount++;
			write_calcedArray(nums,appearance,count_nums);//numsの先頭ポインタを操作後文字列に置き換え
		}
	}
	
}
//-----------------------------------------------------------

void listen_nums(int nums[],const int count_nums)
{
	char stringBuff[1024];
	
	for(;1;)
	{
		fgets(stringBuff,sizeof(stringBuff),stdin);
		if(strcmp(stringBuff,"\r\n")!=0)
		{
			break;
		}
	}
	nums[0]=atoi(strtok(stringBuff," "));
	for(int i=1;i<count_nums-1;i++)
	{
		nums[i]=atoi(strtok(NULL," "));
	}
	nums[count_nums-1]=atoi(strtok(NULL,"\r\n"));
}

void calc_appearance(int nums[],int appearance[],const int count_nums)
{
	using namespace std;
	
	map<int,int> count_eachNums;
	
	int i;
	for(i=0;i<count_nums;i++)
	{
		if(count_eachNums.find(nums[i])==count_eachNums.end())
		{
			count_eachNums.insert(map<int,int>::value_type(nums[i],1));
		}
		else
		{
			count_eachNums[nums[i]]++;
		}
	}
	for(i=0;i<count_nums;i++)
	{
		appearance[i]=count_eachNums[nums[i]];
	}
}

void write_calcedArray(int nums[],int appearance[],const int count_nums)
{
	for(int i=0;i<count_nums;i++)
	{
		nums[i]=appearance[i];
	}
}

bool is_notMoved(int nums[],int appearance[],const int count_nums)
{
	for(int i=0;i<count_nums;i++)
	{
		if(nums[i]!=appearance[i])
		{
			return false;
		}
	}
	return true;
}
void echo_intArray(int array[],const int length)
{
	using namespace std;
	
	cout<<array[0];
	for(int i=1;i<length;i++)
	{
		cout<<" "<<array[i];
	}
	cout<<endl;
}

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

int n;
int x[10000];

int main(){
	while(scanf("%d", &n),n){
		vector<int> tmp(n);
		vector<int> num(n);
		int t = 0;
		for(int i = 0; i < n; i++) scanf("%d", &num[i]);
		while(true){
			tmp = num;
			for(int i = 0; i < 1000; i++) x[i] = 0;
			for(int i = 0; i < n; i++) x[num[i]]++;
			for(int i = 0; i < n; i++) num[i] = x[num[i]];
			if(tmp == num){
				printf("%d\n%d", t, num[0]);
				for(int i = 1; i < n; i++) printf(" %d", num[i]);
				printf("\n");
				break;
			}
			t++;
		}
	}
}

C++: #include <map>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
#include <algorithm>
#include <iostream>

using namespace std;
/** Problem0108 : Operation of Frequency of Appearance **/
int main()
{
	int s1[12], s2[12], n;
	map<int, int> f;
	
	while (cin >> n, n!= 0) {
		for (int i=0; i<n; i++)
			cin >> s1[i];
		
		for (int j=0; ; j++) {
			for (int i=0; i<n; i++)
				f[s1[i]]++;
		
			for (int i=0; i<n; i++)
				s2[i] = f[s1[i]];
			
			f.clear();
			
			bool flag=true;
			for (int i=0; i<n; i++)
				if (s1[i] != s2[i])
					flag=false;
			
			if (flag) {
				cout << j << endl;
				cout << s2[0];
				for (int k=1; k<n; k++)
					cout << " " << s2[k];
				cout << endl;
				goto end;
			}
			for (int i=0; i<n; i++)
				s1[i] = s2[i];
		}
	end: ;
	}
}

C++: #include<bits/stdc++.h>
using namespace std;

typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pair<int, int> > vii;
#define rrep(i, m, n) for(int (i)=(m); (i)<(n);  (i)++)
#define erep(i, m, n) for(int (i)=(m); (i)<=(n); (i)++)
#define  rep(i, n)    for(int (i)=0; (i)<(n);  (i)++)
#define rrev(i, m, n) for(int (i)=(n)-1; (i)>=(m); (i)--)
#define erev(i, m, n) for(int (i)=(n); (i)>=(m); (i)--)
#define  rev(i, n)    for(int (i)=(n)-1; (i)>=0; (i)--)
#define vrep(i, c)    for(__typeof((c).begin())i=(c).begin(); i!=(c).end(); i++)
#define  ALL(v)       (v).begin(), (v).end()
#define mp            make_pair
#define pb            push_back
template<class T, class S> inline bool minup(T& m, S x){ return m>(T)x ? (m=(T)x, true) : false; }
template<class T, class S> inline bool maxup(T& m, S x){ return m<(T)x ? (m=(T)x, true) : false; }

const int    INF = 1000000000;
const ll     MOD = 1000000007LL;
const double EPS = 1E-12;

template<typename T> ostream& operator << (ostream& r, const vector<T> t){vrep(v,t)r<<*v<<(v+1==t.end()?"":" ");return r;}
template<typename T> ostream& operator << (ostream& r, const pair<vector<T>, int> p){int n=p.second;minup(n,p.first.size());rep(i,n-1)r<<p.first[i]<<' ';r<<p.first[n-1];return r;}
template<typename T> ostream& operator << (ostream& r, const pair<T*, int> p){int n=p.second-1;rep(i,n)r<<p.first[i]<<' ';return r<<p.first[n];}
template<typename T, size_t S> ostream& operator << (ostream& r, const T (&a)[S]){rep(i,S-1)r<<a[i]<<' ';return r<<a[S-1];}

const int MAX_N = 12;
int n;

bool check(vi& S, vi& P)
{
  int n = S.size();
  map<int, int> freq;
  rep(i, n) freq[S[i]] += 1;
  rep(i, n) P[i] = freq[S[i]];

  bool ok = true;
  rep(i, n) if(S[i] != P[i]) ok = false;
  S = P;
  return ok;
}

int main()
{
  while(~scanf(" %d", &n) && n){
    vi S(n);
    vi P(n);
    int res = 0;
    rep(i, n) scanf(" %d", &S[i]);
    while(!check(S, P)) res += 1;
    printf("%d\n", res);
    cout << P << endl;
  }

  return 0;
}

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