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 <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <fstream>
using namespace std;
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v;}
template<class T> inline string toStr(T x) { ostringstream sout; sout << x; return sout.str();}
typedef vector<int> vi;
typedef vector<vi>  vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n) FOR(i,0,(n)-1)
const double EPS = 1e-12;
const double PI = acos(-1.0);
const int INF = INT_MAX/10;

int main() {
	int n;
	while(cin >> n, n) {
		vi S(n);
		REP(i, n) {
			cin >> S[i];
		}

		int count = 0;
		while(true) {
			vi C(n, 1);
			REP(i, n) {
				FOR(j, i+1, n-1) {
					if(S[i] == S[j]) {
						C[i]++;
						C[j]++;
					}
				}
			}

			if(S == C) {
				break;
			} else {
				S = C;
				count++;
			}
		}

		cout << count << endl;
		REP(i, n) {
			cout << S[i];
			if(i != n-1) {
				cout << " ";
			}
		}
		cout << endl;
	}

	return 0;
}

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

int main(){
	int n, a, ans, eqCount;
	vector<int> foo1, foo2;

	while( cin >> n , n ){
		ans = 0;
		foo1.clear();
		for(int i=0 ; i<n ; i++){
			cin >> a;
			foo1.push_back(a);
		}
		while( foo1 != foo2 ){
			ans++;
			foo2.clear();
			for(int i=0 ; i<foo1.size() ; i++){
				a = count( foo1.begin() , foo1.end() , foo1.at(i) );
				foo2.push_back(a);
			}
			swap( foo1 , foo2 );
		}
		cout << (ans-1) << endl;
		for(int i=0 ; i<foo2.size() ; i++){
			cout << foo2[i];
			( i == foo2.size()-1 )? cout << endl : cout << " " ;
		}
	}
}

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

int main()
{

	int n, cnt, flg;
	int s[12], cs[12];

	while (cin >> n)
	{
		if (n == 0) break;
		cnt = 0;
		flg = 1;

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

		for (int i = 0; i < 12; i++)
		{
			cs[i] = 0;
		}

		while (1)
		{
			flg = 0;
			for (int i = 0; i < n; i++)
			{
				for (int j = 0; j < n; j++)
				{
					if (s[i] == s[j])
					{
						cs[i]++;
					}
				}
			}
			cnt++;
			for (int i = 0; i < n; i++)
			{
				if (s[i] != cs[i])
				{
					flg++;
				}
			}
			if (flg==0)
			{
				cnt--;
				break;
			}
			else
			{
				for (int i = 0; i < n; i++)
				{
					s[i] = cs[i];
					cs[i] = 0;
				}
			}
		}
		
		cout << cnt << endl;
		for (int i = 0; i < n-1; i++)
		{
			cout << cs[i] << " ";
		}
		cout << cs[n-1] << endl;
	}

	return 0;
}

C++: #define _USE_MATH_DEFINES
#include "bits/stdc++.h"
using namespace std;

//#define int long long
#define DBG 1
#define dump(o) if(DBG){cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) if(DBG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define each(it,c) for(auto it=(c).begin();it!=(c).end();it++)
#define all(c) c.begin(),c.end()
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);
const double EPS = 1e-10;
vector<int> next(vector<int>v) {
	vector<int>c(101, 0);
	rep(i, 0, v.size()) {
		c[v[i]]++;
	}
	vector<int>res;
	rep(i, 0, v.size()) {
		res.push_back(c[v[i]]);
	}
	return res;
}
signed main() {
	int n; cin >> n; vector<int>w,v(n); rep(i, 0, n)cin >> v[i];
	vector<int>c(101, 0);
	rep(i, 0, n) c[v[i]]++;
	int cnt(0);
	while (1) {
		w = v;
		v = next(v);
		if (v == w)break;
		cnt++;
	}
	cout << cnt << endl;
	rep(i, 0, v.size()) cout << v[i] << (i == v.size() - 1 ? '\n' : ' ');

	return 0;
}

C++: #include <iostream>
#include <set>

using namespace std;

int main()
{
	int n;
	int sp[2][12];
	multiset<int> cnt;

	while(cin >> n, n)
	{
		for(int i=0; i < n; i++) {
			cin >> sp[0][i];
		}
		int idx = 0;
		int count = -1;
		while(1)
		{
			int ii =  (idx + 1) % 2;
			cnt.clear();
			for(int i=0; i < n; i++) {
				cnt.insert(sp[idx][i]);
			}
			bool hit = true;
			for(int i=0; i < n; i++) {
				sp[ii][i] = cnt.count(sp[idx][i]);
				if(sp[idx][i] != sp[ii][i]) hit = false;
			}
			count++;
			if(hit) break;
			idx = ii;
		}
		cout << count << endl;
		for(int i=0; i < n-1; i++) {
			cout << sp[0][i] << ' ';
		}
		cout << sp[0][n-1] << endl;
	}
	return 0;
}

C++: #include<iostream>
#include<map>
#include<string>
#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);
		}
	}
	
}
//-----------------------------------------------------------

void listen_nums(int nums[],const int count_nums)
{
	using namespace std;
	int i=0;
	string str;
	while(i<count_nums-1)
	{
		getline(cin,str,' ');
		nums[i]=atoi(str.c_str());
		i++;
	}
	cin>>nums[i];
}

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