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 <cstdio>

using namespace std;

int main(){
	
	int n, loop, count;
	
	bool same;
	
	int a[20], b[20];
	
	cin >> n;
	
	while(n != 0){
		
		for(int i = 0; i < n; i++){
			cin >> a[i];
		}
		
		for(loop = 0; loop < 20; loop++){
			if(loop % 2 == 0){
				for(int i = 0; i < n; i++){
					count = 0;
					for(int j = 0; j < n; j++){
						if(a[i] == a[j]){
							count++;
						}
					}
					b[i] = count;
				}
			}else{
				for(int i = 0; i < n; i++){
					count = 0;
					for(int j = 0; j < n; j++){
						if(b[i] == b[j]){
							count++;
						}
					}
					a[i] = count;
				}
			}
			
			same = true;
			
			for(int i = 0; i < n; i++){
				if(a[i] != b[i]){
					same = false;
					break;
				}
			}
			if(same){
				break;
			}
		}
		
		printf("%d\n", loop);
		printf("%d", a[0]);
		
		for(int i = 1; i < n; i++){
			printf(" %d", a[i]);
		}
		
		printf("\n");
		
		cin >> n;
	}
	
	return 0;
}

C++: #include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<time.h>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double EPS=1e-10;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
int main(){
	int n;
	while(cin>>n,n){
		vector<int>in(n);
		rep(i,n)cin>>in[i];
		int co=0;
		while(1){
			co++;
			map<int,int>a;
			rep(i,n)a[in[i]]++;
			bool h=true;
			rep(i,n){
				if(in[i]!=a[in[i]])h=false;
				in[i]=a[in[i]];
			}
			if(h)break;
		}
		cout<<co-1<<endl;
		rep(i,9)cout<<in[i]<<" ";
		cout<<in[9]<<endl;
	}
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define REP( i, m, n ) for ( int i = (int)m; i < (int)n; i++ )
#define UREP( i, m, n ) for ( unsigned int i = (unsigned int)m; i < (unsigned int)n; i++ )
#define ITER( c ) __typeof( (c).begin() )
#define IREP( c, it ) for ( ITER(c) it = c.begin(); it != c.end(); ++it )
#define ALL( c ) (c).begin(), (c).end()
#define PB( n ) push_back( n )
#define MP( a, b ) make_pair( a, b )
#define fst first
#define snd second

int main()
{
	while ( true )
	{
		int n;
		cin >> n;

		if ( n == 0 )
		{
			break;
		}

		vector<int> current;

		REP( i, 0, n )
		{
			int in;
			cin >> in;
			current.PB( in );
		}

		int count = 0;
		while ( true )
		{
			vector<int> next;
			map<int,int> dist;

			REP( i, 0, n )
			{
				dist[ current[i] ]++;
			}

			REP( i, 0, n )
			{
				next.PB( dist[ current[i] ] );
			}

			if ( current == next )
			{
				break;
			}
			else
			{
				count++;
				current = next;
			}
		}

		cout << count << endl;
		REP( i, 0, n )
		{
			cout << current[i] << ( i + 1 == n ? '\n' : ' ' );
		}
	}

	return 0;
}

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

int n = 0;
int counter = 0;

vector<int> operation_of_fa(const vector<int> num_seq);

int main()
{
	int num = 0;
	while (true) {
		cin >> n;
		if(n==0) break;
		vector<int> first_num_seq;
		for(int i=0;i<n;i++) {
			cin >> num;
			first_num_seq.push_back(num);
		}

		vector<int> operated_seq = operation_of_fa(first_num_seq);

		cout << counter << endl;
		for(int i=0; i<n; i++) {
			cout << operated_seq[i];
			if (i<n-1)
				cout << ' ';
		}
		cout << endl;
	}
	return 0;
}


vector<int> operation_of_fa(const vector<int> num_seq)
{
	int frequency = 0;
	vector<int> operated_seq;
	for (int i=0;i<n;i++) {
		frequency = 0;
		for (int j=0;j<n;j++) 
			if (num_seq[i] == num_seq[j])
				frequency++;
		operated_seq.push_back(frequency);
	}
	
	if (num_seq != operated_seq) {
		counter++;
		return operation_of_fa(operated_seq);
	}
	else
		return operated_seq;
}

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

int main(){
    while (1){
        int n; cin>>n;
        if (n==0)
            break;
        int buf,cnt=0,f;
        vector <int> a;
        vector <int> c;
        for(int i=0; i<n; i++){
            cin>>buf;
            a.push_back(buf);
            c.push_back(1);
        }
        do{
            f=0;
            for(int i=1; i<n; i++){
                for(int j=0; j<i; j++){
                    if(a[i]==a[j]){
                        c[i]++;
                        c[j]++;
                    }
                }
            }
            cnt++;
            for(int i=0; i<n; i++){
                if(a[i]!=c[i]){
                    a[i]=c[i];
                    f=1;
                }
                c[i]=1;
            }
        }while (f);
        cout<<cnt-1<<endl;
        for(int i=0; i<n-1; i++)
            cout<<a[i]<<" ";
        
        cout<<a[n-1]<<endl;
    }
    return 0;
}

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

int n;
int cnt;
deque<int> c;
int a[12];

void Op(deque<int> s)
{
  for (int i = 0; i < n; i++){
    c.push_back(count(s.begin(), s.end(), a[i]));
    a[i] = c.back();
  }
  cnt++;
}

int main()
{
  while (cin >> n, n){
    deque<int> s;
    int cn = 0;
    cnt = 0;

    for (int i = 0; i < n; i++){
      cin >> a[i];
      s.push_back(a[i]);
    }
    while (cn != n){
      Op(s);
	  cn = 0;
      for (int i = 0; i < n; i++){
		if (s.front() == c.front()){
          cn++;
        }
        s.pop_front();
        s.push_back(c.front());
        c.pop_front();
	  }
    }
    cout << cnt - 1 << "\n" << s[0];
    for (int i = 1; i < n; i++){
      cout << " " << s[i];
    }
    cout << endl;
  }
  
  return (0);
}

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

int main(){
	int n;
	vector<int> a(12), b(12);
	while(cin >> n, n){
		for(int i = 0;i < n;i++)cin >> b[i];
		int ans = 0;
		while(1){
			for(int i = 0;i < n;i++)
				a[i] = count(b.begin(), b.end(), b[i]);
			if(a == b)break;
			b = a;ans++;
		}
		cout << ans << endl;
		for(int i = 0;i < n;i++)
			cout << b[i] << (i == n-1 ? "\n" : " ");
	}
	return 0;
}

C++: #include <map>
#include <vector>
#include <cstdio>
using namespace std;
int main(){
	int i,n,x;
	for(;scanf("%d",&n),n;){
		vector<int>v,u;
		for(i=0;i<n;i++)scanf("%d",&x),v.push_back(x);
		for(x=0;;x++){
			u.clear();
			map<int,int>m;
			for(i=0;i<n;i++)m[v[i]]++;
			for(i=0;i<n;i++)u.push_back(m[v[i]]);
			if(v==u)break;
			v=u;
		}
		printf("%d\n%d",x,u[0]);
		for(i=1;i<n;i++)printf(" %d",u[i]);
		puts("");
	}
}