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 <vector>
#include <string>
#include <map>
#include <algorithm>
#include <cstdio>
using namespace std;

int main(){
	int n;
	while(cin >> n, n){
		vector<vector<int> > vvi;
		vector<int> vi;
		for(int i = 0; i < n; i++){
			int k;
			cin >> k;
			vi.push_back(k);
		}
		vvi.push_back(vi);
		int cnt = 0;
		do{
			vi.clear();
			for(int i = 0; i < vvi[cnt].size(); i++){
				vi.push_back(count(vvi[cnt].begin(), vvi[cnt].end(), vvi[cnt][i]));
			}
			vvi.push_back(vi);
			cnt++;
		}while(vvi[cnt] != vvi[cnt-1]);

		cout << cnt-1 << endl;
		for(int i = 0; i < vvi[cnt].size(); i++){
			if(i){
				cout << ' ';
			}
			cout << vvi[cnt][i];
		}
		cout << endl;
	}

	return 0;
}

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 ans2;
	int s[13];
	int ans=1;
	while(1){
		ans2=0;
		cin >> n;
		if(n==0)break;
		for(a=0;a<n;a++){
			cin >> s[a];
		}
		map<int,int> sc;
		for(a=0;a<n;a++){
			sc[s[a]]++;
		}
		while(1){
			ans=1;
			for(a=0;a<n;a++){
				if(s[a]!=sc[s[a]])ans=0;
				s[a]=sc[s[a]];
			}
			if(ans==1)break;
			else{
				ans2++;
				for(a=0;a<n;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;
	}
	return 0;
}

C++: #include<iostream>

using namespace std;

int main(){
	int in;

	while(cin >> in){
		int rev = 0, max = 0;

		if(in == 0) break;

		int data[in];

		for(int i = 0; i < in; i++){
			cin >> data[i];
			if(data[i] > max) max = data[i];
		}

		while(1){

			int sum[max+1];

			for(int	i = 0; i <= max; i++){
				sum[i] = 0;
			}
		
			for(int i = 0; i < in; i++){
				sum[data[i]]++;
			}

			int status = 0;

			for(int i = 0; i < in; i++){
				if(data[i] != sum[data[i]]) status = 1;
			}

			/*for(int i = 0; i < in; i++) cout << data[i] << " ";
			cout << endl;*/

			if(status == 0){
				cout << rev << endl;
				for(int i = 0; i < in; i++){
					if(i != 0) cout << " ";
					cout << data[i];
				}
				cout << endl;
				break;
			}

			for(int i = 0; i < in; i++){
				data[i] = sum[data[i]];
			}
			rev++;
			max = in;
		}
	}

	return 0;
}

C++: #include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <fstream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <assert.h>


using namespace std;


#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define clr(a) memset((a),0,sizeof(a))
#define nclr(a) memset((a),-1,sizeof(a))
#define pb push_back
#define INRANGE(x,s,e) ((s)<=(x) && (x)<(e))
#define MP(a,b) make_pair((a),(b))

int main(){
	int n;
	while(cin>>n,n){
		vector<int> S1(n), S2(n), B(10000,0);
		int count=0;
		rep(i,n){
			cin>>S1[i];
		}
		while(1){
			rep(i,B.size())B[i]=0;
			
			rep(i,S1.size())
				B[S1[i]]++;
			
			for(int j=0;j<S1.size();j++){
				S2[j]=B[S1[j]];
			}
			if(S1==S2){ 
				break;
			}
			S1=S2;count++;
		}
		cout<<count<<endl;
		rep(i,S1.size()-1)
			cout<<S1[i]<<" ";
		cout<<S1[S1.size()-1]<<endl;
	}
	return 0;
}

C++: #include <utility>
#include <vector>
#include <math.h>
#include <algorithm>
#include <string>
#include <iostream>
using namespace std;

bool mani(int a[12], int n)
{
	int b[12];
	fill(b, b + 12, 0);
	for (int i = 0; i < n; i++)
		for (int j = 0; j < n; j++)
			if (a[i] == a[j])
				b[i]++;
	bool f = true;
	for (int i = 0; i < n; i++)
	{
		if (a[i] != b[i])
		{
			f = false;
			break;
		}
		a[i] = b[i];
	}
	
	return f;
}


int main()
{
	int n, a[12];
	cin >> n;
	while (true)
	{
		int c = 0;
		a[1] = -1;
		for (int i = 0; i < n; i++)
			cin >> a[i];
		if (a[0] == 0 && a[1] == -1) break;
		while (true)
		{
			if (mani(a, n))
				break;
			c++;
		}
		cout << c << endl;
		cout << a[0];
		for (int i = 1; i < n; i++)
			cout << " " << a[i];
		cout << endl;
	}
	return 0;
}

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,"\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,"\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;
}