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++: // 2011/01/23 Tazoe

#include <iostream>
using namespace std;

int main()
{
	while(true){
		int n;
		cin >> n;
		if(n==0)
			break;

		int S[12];
		for(int i=0; i<n; i++)
			cin >> S[i];

		int cnt = 0;
		int P[12];
		while(true){
			for(int i=0; i<n; i++)
				P[i] = 0;

			for(int i=0; i<n; i++)
				for(int j=0; j<n; j++)
					if(S[i]==S[j])
						P[i]++;

			bool flg = true;
			for(int i=0; i<n; i++)
				if(S[i]!=P[i]){
					flg = false;
					break;
				}

			if(flg)
				break;
			else
				cnt++;

			for(int i=0; i<n; i++)
				S[i] = P[i];
		}

		cout << cnt << endl;
		for(int i=0; i<n; i++){
			cout << P[i];
			if(i!=n-1)
				cout << ' ';
			else
				cout << endl;
		}
	}

	return 0;
}

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

bool check(vector<int> s, vector<int> freq_s);

int main()
{
	int n;
	
	while (scanf("%d", &n), n != 0){
		vector<int> s, freq_s;
		map<int, int> freq;
		
		for (int i = 0; i < n; i++){
			int t;
			scanf("%d", &t);
			s.push_back(t);
		}
		int cnt;
		for (cnt = 0; ; cnt++){
			freq.clear();
			freq_s.clear();
			for (int i = 0; i < s.size(); i++){
				freq[s[i]]++;
			}
			for (int i = 0; i < s.size(); i++){
				freq_s.push_back(freq[s[i]]);
			}
			if (check(s, freq_s)) break;
			else s = freq_s;
		}
		printf("%d\n", cnt);
		printf("%d", freq_s[0]);
		for (int i = 1; i < freq_s.size(); i++){
			printf(" %d", freq_s[i]);
		}
		puts("");
	}
	
	return 0;
}

bool check(vector<int> s, vector<int> freq_s)
{
	if (s.size() != freq_s.size()) return false;
	for (int i = 0; i < s.size(); i++){
		if (s[i] != freq_s[i]) return false;
	}
	return true;
}

C++: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for( int i = 0; i < n; i++ )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    /*
    cin.tie(0);
    ios::sync_with_stdio(false);
    //*/
    int flag = 1;
    int n; cin >> n;
    while (n != 0) {
        int count = 0;
        int p[n];
        int q[101] = {0};
        rep(i, n) {
            cin >> p[i];
        }

        while (flag == 1){
            flag = 0;
            fill(q, q+101, 0);
            rep(i, n) q[p[i]]++;
            //rep(i, n) cout << q[p[i]] << " ";
            for (int i = 0; i < n-1; i++) {
                if (p[i] != q[p[i]]) flag = 1;
            }
            rep(i ,n) p[i] = q[p[i]];
            count++;
        }
        rep(i, n-1) cout << q[p[i]] << " ";
        cout << q[p[n-1]] << endl;
        cout << count-1;
        cin >> n;
    }

    return 0;
}

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

using namespace std;

bool equal(int* a, int* b, int n) {
  for (int i = 0; i < n; i++)
    if (a[i] != b[i])
      return false;
  return true;
}

int main() {
  for (;;) {
    int n;
    cin >> n;
    if (!n) return 0;
    int p[n], s[n], result = 0;
    for (int i = 0; i < n; i++)
      cin >> p[i];
    for (;;) {
      for (int i = 0; i < n; i++)
        s[i] = p[i];
      map<int, int> counts;
      for (int i = 0; i < n; i++)
        counts[s[i]]++;
      for (int i = 0; i < n; i++)
        p[i] = counts[s[i]];
      if (equal(p, s, n)) break;
      result++;
    }
    cout << result << endl;
    for (int i = 0; i < n-1; i++)
      cout << p[i] << ' ';
    cout << p[n-1] << endl;
  }
}

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

int main()
{
	int n,c,i;
	int pre[12],now[12],cnt[12];
	while(cin >> n,n)
	{
		map<int,int> m;
		for(i=0; i<n; i++)
		{
			cin >> pre[i];
			m[pre[i]] = i+1;
		}
		for(i=0; i<n; i++)
			now[i] = m[pre[i]];	

		for(c=0; ; c++)
		{
			for(i=0; i<n; i++)
				cnt[i] = 0;

			for(i=0; i<n; i++)
				cnt[now[i]-1]++;		

			for(i=0; i<n; i++)
				now[i] = cnt[now[i]-1];

			for(i=0; i<n; i++)
				if(now[i]!=pre[i])
					break;

			if(i==n) break;

			for(i=0; i<n; i++)
				pre[i] = now[i];
		}

		cout << c << endl << now[0];
		for(i=1; i<n; i++)
			cout << " " << now[i];
		cout << endl;


	}
	return 0;
}

C++: #include <stdio.h>
#include <string.h>

int main(void)
{
	int s[12];
	int c[12];
	
	while (1){
		int n;
		int count;
		
		scanf("%d", &n);
		
		if (n == 0){
			break;
		}
		
		for (int i = 0; i < n; i++){
			scanf("%d", &s[i]);
		}
		
		count = 0;
		do {
			for (int i = 0; i < n; i++){
				c[i] = 0;
				for (int j = 0; j < n; j++){
					if (s[i] == s[j]){
						c[i]++;
					}
				}
			}
			if (memcmp(s, c, sizeof(int) * n) == 0) break;
			memcpy(s, c, sizeof(s));
			
			count++;
		} while (1);
		
		printf("%d\n", count);
		printf("%d", s[0]);
		for (int i = 1; i < n; i++){
			printf(" %d", s[i]);
		}
		puts("");
	}
	
	return (0);
}

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

bool check(vector<int> &a,vector<int> &b)
{
	if(a.size()!=b.size())return true;
	for(int i=0;i<a.size();i++)if(a[i]!=b[i])return true;
	return false;
}

int main()
{
	int n;
	while(cin>>n&&n)
	{
		vector<int> a,b;
		for(int i=0;i<n;i++)
		{
			int x;
			cin>>x;
			a.push_back(x);
		}
		int ans;
		for(ans=-1;check(a,b);ans++)
		{
			b.clear();
			for(int i=0;i<a.size();i++)
			{
				b.push_back(count(a.begin(),a.end(),a[i]));
			}
			swap(a,b);
		}
		cout<<ans<<endl;
		for(int i=0;i<a.size();i++)
		{
			cout<<(i==0?"":" ")<<a[i];
		}
		cout<<endl;
	}
}

C++: #include<algorithm>
#include<iostream>
#include<map>
#include<cstring>

int n;
int a[12], prv[12];
std::map<int, int> cnt, tmp;
int ans;

int main()
{
	while( std::cin >> n, n )
	{
		ans = 0;
		memset( a, 0, sizeof( a ) );
		memset( prv, 0, sizeof( prv ) );
		cnt.clear();
		tmp.clear();

		for( int i = 0; i != n; ++i )
		{
			std::cin >> a[i];
			++cnt[a[i]];
		}

		while( true )
		{
			std::copy( a, a + 12, prv );

			for( int i = 0; i != n; ++i )
			{
				a[i] = cnt[a[i]];
				++tmp[a[i]];
			}

			if( std::equal( a, a + 12, prv ) )
				break;

			++ans;

			cnt = tmp;
			tmp.clear();
		}

		std::cout << ans << std::endl;
		for( int i = 0; i != n; ++i )
			std::cout << a[i] << ( i == n - 1 ? '\n' : ' ' );
	}

	return 0;
}

C++: #include <iostream>
#include <math.h>
#include <algorithm>
#include <map>
#include <cstdio>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
int main(){
  int n;
	while(true){
	cin>>n;
	if(n==0){break;}
	int *a=new int[n];
	map<int,int>Map;
	rep(i,n){
		cin>>a[i];
	}
	for(int count=0;;count++){
		rep(i,n){
			Map[a[i]]++;
		}
		int *s=new int[n];
		rep(i,n){
			s[i]=Map[a[i]];
		}
		if(a==s){cout<<count<<endl;break;}
		rep(i,n){	
			s[i]=a[0];
		}
		  
	}
	}
	  for(int i=0;i<n;i++){
		if(i!=0){
		cout<<" ";
		}
		cout<<a[i];
	}
	cout<<endl;
	
	return 0;
}

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

int main() {
  int a[12], b[13];
  int c, n;
  bool f;
  map<int, int> m;

  while (cin >> n && n) {
    m.clear();
    for (int i=0; i<n; i++) {
      cin >> a[i];
      m.insert(map<int, int>::value_type(a[i], i+1));
      a[i] = m[a[i]];
    }

    c = -1;
    do {
      f = true;
      for (int i=1; i<=n; i++) b[i]=0;
      for (int i=0; i<n; i++) b[a[i]]++;
      for (int i=0; i<n; i++) {
        if (a[i] != b[a[i]]) f=false;
        a[i] = b[a[i]];
      }
      c++;
    } while (!f);
    cout << c << endl;
    cout << a[0];
    for (int i=1; i<n; i++) cout << " " << a[i];
    cout << endl;
  }

  return 0;
}