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 <algorithm>
#include <cmath>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <cassert>
#include <functional>

using namespace std;

#define LOG(...) printf(__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define CLR(a) memset((a), 0 ,sizeof(a))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int dx[] = { -1, 0, 1, 0 }; const int dy[] = { 0, 1, 0, -1 };

struct UnionFind {
	vector<int> v;
	UnionFind(int n) : v(n)  { for (int i = 0; i < n; i++) v[i] = i; }
	int  find(int x)         { return v[x] == x ? x : v[x] = find(v[x]); }
	void unite(int x, int y) { v[find(x)] = find(y); }
};

int main() {
	int n;
	while (cin>>n,n){
		vector < int > num(n);
		REP(i,n){
			cin >> num[i];
		}
		int count=-1;
		vector < int > num2(n);
		num2 = num;
		do
		{
			num = num2;
			count++;
			REP(i, n){
				int cnt = 0;
				REP(j, n){
					if (num[i] == num[j])
						cnt++;
				}
				num2[i] = cnt;
			}

		} while (num!=num2);
		cout << count << endl;
		REP(i,n){
			cout << num[i];
			if (i == n - 1)
				cout << endl;
			else
				cout << ' ';
		}
	}
}

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=0;
	int s[13];
	map<int,int> sc;
	bool ans=true;
	while(1){
		ans2=0;
		cin >> n;
		for(a=0;a<=12;a++)s[a]=0;
		if(n==0)break;
		for(a=0;a<n;a++){
			cin >> s[a];
		}
		for(a=0;a<n;a++){
			sc[s[a]]++;
		}
		while(1){
			ans=true;
			for(a=0;a<n;a++){
				if(s[a]!=sc[s[a]])ans=false;
				s[a]=sc[s[a]];
			}
			if(ans==true)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 n;
int ar1[20] = {};
int ar2[20] = {};


int func(int x){
	int val;
	int cnt = 0;;
	for(int i = 0; i < n; i++){
		if(ar1[i] == x){
			cnt++;
		}
	}
	val = cnt;
	return val;
}


int main(){
	while(cin >> n, n){
		for(int i = 0; i < n; i++){
			cin >> ar1[i]; 
		}
		int all_cnt = 0;
		while(1){
			for(int i = 0; i < n; i++){
				ar2[i] = func(ar1[i]);		
			}

			bool flag = true;
			for(int i = 0; i < n; i++){
				if(ar1[i] != ar2[i]){
					flag = false;
				}
			}
			if(flag == true) {
				cout << all_cnt << endl;
				for(int i = 0; i < n; i++){
					cout << ar2[i];
					if(i != n-1){
						cout << " ";
					}
				}
				cout << endl;
				break;
			}else{
				all_cnt++;
				for(int i = 0; i < n; i++){
					ar1[i] = ar2[i];
				}
				continue;
			}
		}
	}
}

C++: #include <cstdio>
#include <vector>
#include <map>
using namespace std;
typedef vector<int> vi;

vi C;

bool compare(vi S, vi C) {
	for (int i=0; i<S.size(); i++) {
		if (S[i] != C[i]) return false;
	}
	return true;
}

int solve(vi S, int cnt) {
	C = vi(S.size());
	map<int, int> ma;
	for (int i=0; i<S.size(); i++) {
		if (ma.empty() || ma.find(S[i])==ma.end()) {
			ma[S[i]] = 1;
		} else {
			ma[S[i]]++;
		}
	}
	for (int i=0; i<S.size(); i++) {
		C[i] = ma[S[i]];
	}
	if (compare(S, C)) {
		return cnt;
	}
	return solve(C, cnt+1);
}

int main() {
	int n;
	while (scanf("%d",&n)&&n!=0) {
		vi S(n);
		for (int i=0; i<n; i++) scanf("%d",&S[i]);
		int res = solve(S, 0);
		printf("%d\n", res);
		for (int i=0; i<C.size()-1; i++) printf("%d ",C[i]);
		printf("%d\n", C[C.size()-1]);
	}
}

C++: #include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<map>
#include<set>
#include<queue>
#include<cstdio>
#include<climits>
#include<cmath>
#include<cstring>
#include<string>
#include<sstream>

#define f first
#define s second
#define mp make_pair

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define ALL(c) (c).begin(), (c).end()

using namespace std;

typedef unsigned int uint;
typedef long long ll;

int main(){
  int n;
  while(cin>>n, n){
    int arr[2][n];
    int *next = arr[1], *prev = arr[0];
    int cnt = -1;
    REP(i,n) cin>>arr[0][i];
    do{
      cnt++;
      REP(i,n) next[i] = (int)count(prev, prev+n, prev[i]);
      swap(prev, next);
    }while(memcmp(prev, next, sizeof(int) * n) != 0);
    printf("%d\n",cnt);
    REP(i,n) printf("%d%c",prev[i],i==n-1?'\n':' ');
  }
  return 0;
}

C++: #include <cstdio>
int n;
int dats[15]={};
int mat[100]={};
int main(void){
	int i,j,co;
	bool fl;
	while(1){
		scanf("%d",&n);
		if(n==0)break;
		for(i=0;i<n;i++){
			scanf("%d",&(dats[i]));
		}
		co=0;
		while(1){
			fl=true;
			for(i=0;i<100;i++)mat[i]=0;
			for(i=0;i<n;i++){
				mat[dats[i]]++;
			}
			for(i=0;i<n;i++){
				if(mat[dats[i]]!=dats[i]){
					fl=false;
					dats[i]=mat[dats[i]];
				}
			}
			if(fl)break;
			co++;
		}
		printf("%d\n",co);
		for(i=0;i<n-1;i++){
			printf("%d ",dats[i]);
		}
		printf("%d\n",dats[n-1]);
	}
	return 0;
}

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

using namespace std;

int main() {

	int n;

	while(cin >> n) {
		if(!n) {
			break;
		}

		deque<int> s;
		for(int i=0; i<n; i++) {
			int x;
			cin >> x;
			s.push_back(x);
		}
		int f=1, p=0;
		while(f) {
			for(int i=0; i<n; i++) {
				int c=1;
				for(int j=0; j<n; j++) {
					if(i!=j&&s[i]==s[j]) {
						c++;
					}
				}
				s.push_back(c);
			}
			for(int i=0; i<n-1; i++) {
				if(s[i]!=s[i+n]) {
					f=1;
					break;
				}
				f=0;
			}
			for(int i=0; i<n; i++) {
				s.pop_front();
			}
			p++;
		}
		p--;
		cout << p << endl << s[0];
		for(int i=1; i<n; i++) {
			cout << " " << s[i];
		}
		s.clear();

	}

	return 0;

}