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<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    while(cin>>n,n){
        int ans[1000]={},kawa[1000];
        for(int i=0;i<n;i++)cin>>kawa[i];
        for(int i=0;;i++){
            int num[1000]={};
            for(int j=0;j<n;j++)num[kawa[j]]++;
            bool rever=0;
            for(int j=0;j<n;j++){
                kawa[j]=num[kawa[j]];
                if(kawa[j]!=ans[j])rever=1;
            }
            if(!rever){
                cout<<i<<endl<<kawa[0];
                for(int j=1;j<n;j++)cout<<" "<<kawa[j];
                cout<<endl;
                break;
            }
            else for(int j=0;j<n;j++)ans[j]=kawa[j];
        }
    }
}

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

int n;
int x[1000];

int main(){
	while(scanf("%d", &n),n){
		vector<int> tmp(n);
		vector<int> num(n);
		int t = 0;
		for(int i = 0; i < n; i++) scanf("%d", &num[i]);
		while(true){
			for(int i = 0; i < 1000; i++) x[i] = 0;
			for(int i = 0; i < n; i++) x[num[i]]++;
			for(int i = 0; i < n; i++) num[i] = x[num[i]];
			if(tmp == num){
				printf("%d\n%d", t, num[0]);
				for(int i = 1; i < n; i++) printf(" %d", num[i]);
				printf("\n");
				break;
			} else tmp = num;
			t++;
		}
	}
}

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

using namespace std;

int main() {
	int n;
	int number[12];
	int hantei;
	int count;

	while (cin >> n) {
		if (n == 0) {
			break;
		}
		int counter[100] = {0};
		for (int i = 0; i < n; i++) {
			cin >> number[i];
			counter[number[i]-1]++;
		}
		hantei = 0;
		count = 0;
		while (1) {
			for (int i = 0; i < n; i++) {
				if (number[i] == counter[number[i]-1]) {
					if (i == n-1) {
						hantei = 1;
						break;
					}
					continue;
				} else {
					break;
				}
			}
			if (hantei == 1) {
				break;
			}
			for (int i = 0; i < n; i++) {
				number[i] = counter[number[i]-1];
			}
			for (int i = 0; i < 100; i++) {
				counter[i] = 0;
			}
			for (int i = 0; i < n; i++) {
				counter[number[i]-1]++;
			}
			count++;
		}
		cout << count << endl;
		cout << number[0];
		for (int i = 1; i < n; i++) {
			cout << " " << number[i] ;
		}
		cout << endl;
	}
	return 0;
}

C++: #define _CRT_SECURE_NO_WARNINGS
#include"bits/stdc++.h"
#ifdef _DEBUG
#define DBG(n) n
#else
#define DBG(n)
#endif
#define INF         1e9
#define INFLL       1e18
#define EPS         1e-9
#define REP(i,n)    for(ll i=0,i##_len=(n);i<i##_len;++i)
#define REP1(i,n)   for(ll i=1,i##_len=(n);i<=i##_len;++i)
#define REPR(i,n)   for(ll i=(n)-1;i>=0;--i)
#define REPR1(i,n)  for(ll i=(n);i>0;--i)
#define REPC(i,obj) for(auto i:obj)
#define ALL(obj)    (obj).begin(),(obj).end()
#define SETP(n)     cout<<fixed<<setprecision(n)
using namespace std;
using ll = long long;
template<typename T = ll>inline T in() { T ret; cin >> ret; return ret; }

signed main()
{
	for (ll n = in(); n != 0; n = in()) {
		ll ans = 0;
		vector<ll>s(n);
		REP(i, n) s[i] = in();
		while (true) {
			vector<ll>prev(s);
			map<ll, ll>mp;
			REP(i, n)++mp[s[i]];
			REP(i, n)s[i] = mp[s[i]];
			if (s == prev)break;
			++ans;
		}
		cout << ans << endl;
		REP(i, n) {
			if (i != 0)cout << ' ';
			cout << s[i];
		}
		cout << endl;
	}
}

C++: #include <cstdio>
#include <cstring>
#define buf 10000
using namespace std;

void BubbleSort(int n);
void Search(int n);
void Answer(int n,int ans);
void Copy(int n);
int Log(int n);
int A[300],B[300],C[300]={0},D[300]={0},ans;

int main(void){
  int i,n,m,z,num;
  char str[buf],*line;

  for( ;fgets(str,sizeof(str),stdin)!=NULL; ){
    sscanf(str,"%d",&n);
    if(n==0) break; ans=0;
    fgets(str,sizeof(str),stdin);
    line=strtok(str," ");
    sscanf(line,"%d",&m); A[0]=m;
    for(i=1;i<n;i++){
      line=strtok(NULL," ");
      sscanf(line,"%d",&m);
      A[i]=m;
    }
    for( ; ; ){
      Copy(n);
      BubbleSort(n);
      Search(n);
      z=Log(n);
      if(z) break;    
    }
    Answer(n,ans);
  }
  return 0;
}

int Log(int n){
  int i,num=0;
  for(i=0;i<n;i++){
    if(D[i]==C[i])
      num++;
  }
  if(num==n)
    return 1;
  else{
    for(i=0;i<n;i++){
      C[i]=D[i];
      A[i]=D[i];
    }
    ans+=1;
  }
  return 0;
}

void Copy(int n){
  int i;
  for(i=0;i<n;i++){
    B[i]=A[i];
  }
}

void Answer(int n,int ans){
  int i;
  printf("%d\n",ans);
  for(i=0;i<n;i++){
  if(i) printf(" ");
     printf("%d",D[i]);
  }
  printf("\n");
}

void Search(int n){
  int i,j,tmp=0,cnt=1;
  B[n]=0;
  for(i=0;i<n;i++){
    if(B[i]==B[i+1])
      cnt+=1;
    else{
      for(j=0;j<n;j++){
        if(B[tmp]==A[j])
          D[j]=cnt;
      }
      tmp=i+1; cnt=1;
    }
  }
}

void BubbleSort(int n){
  int i,j,tmp;
  for(i=0;i<n-1;i++){
    for(j=n-1;j>i;j--){ 
      if(B[j] < B[j-1]){
        tmp = B[j-1];
        B[j-1] = B[j];
        B[j] = tmp;
      }
    }
  }
}

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

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

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

int ans[150][2][12];//二つ目の次元の0の0に数列の長さ、0の1に操作回数、1に答えの数列

int counter=0,flag=0;

void solve(){
	int n;
	cin >> n;
	if(n==0){flag=1;return;}
	ans[counter][0][0]=n;
	
	int S[12];//数列
	for(int i=0;i<n;i++){
		cin >> S[i];
	}
	
	bool check=false;//操作の有無のフラグ
	int time=0;//操作回数
	do{
		map<int,int> marker;
		for(int i=0;i<n;i++){
			marker[S[i]];
			marker[S[i]]++;
		}
		check=false;
		for(int i=0;i<n;i++){
			if(S[i]!=marker[S[i]]){
				check=true;
				S[i]=marker[S[i]];
			}
		}
		if(check) time++;
	}while(check);
	
	ans[counter][0][1]=time;
	for(int i=0;i<n;i++){
		ans[counter][1][i]=S[i];
	}
	counter++;
}

int main(){
	while(flag==0)solve();
	for(int i=0;i<counter;i++){
		cout << ans[i][0][1] << endl;
		for(int j=0;j<ans[i][0][0]-1;j++){
			cout << ans[i][1][j]<<" ";
		}
		cout << ans[i][1][ans[i][0][0]-1] << endl;
	}
}