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<stdio.h>
#include<iostream>
#include<list>
#include<map>
#include<math.h>
#include<vector>
#include<algorithm>
#include<string.h>
#include<iomanip>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) range(i,0,b)
#define debug(x) cout << "debug" << x << endl;
using namespace std;

int n, ans = 0;

void solve(int l1[], int count[]){
    int l2[12], sum = 0;
    int subcount[13] = {0};
    rep(i, n){
        l2[i] = count[ l1[i] ];
        subcount[ l2[i] ]++;
    }
    rep(i, n){
        sum+= l1[i] - l2[i];
    }
    if(sum != 0){
        ans++;
        solve(l2, subcount);
    }else{
        cout << ans << endl;
        rep(i, n){
            if(i == 0);
            else if(i == 1) cout << l1[i];
            else cout << ' ' << l1[i];
        }cout << endl;
    }
}

int main(){
    int l1[13], l2[13];
    while(cin >> n, n){
        int count[13] = {0};
        rep(i, n){
            cin >> l1[i];
            count[l1[i]]++;
        }
        ans = 0;
        solve(l1, count);
    }
}

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

void print(vector<int> &v1) {
  for(int j = 0; j < (int)v1.size(); ++j) {
	cout << v1[j];
	cout << (j < (int)v1.size() - 1 ? " " : "\n");
  }
}

int loop_cnt;
void op(vector<int> &v1) {
  vector<int> v2 = v1;
  for(int i = 0; i < (int)v1.size(); ++i) {
	int cnt = 0;
	for(int j = 0; j < (int)v1.size(); ++j) {
	  if(v1[j] == v1[i]) {
		cnt++;
		v2[j] = -1;
	  }
	}
	for(int j = 0; j < (int)v2.size(); ++j) {
	  if(v2[j] == -1) {
		v2[j] = cnt;
	  }
	}
  }
  if(v2 != v1) {
	loop_cnt++;
	op(v2);
  }
  else {
	cout << loop_cnt << endl;
	print(v1);
  }
}

int main() {
  int n;
  while(cin >> n && n) {
	loop_cnt = 0;
	vector<int> v(n);
	for(int i = 0; i < n; ++i) {
	  cin >> v[i];
	}
	op(v);
  }
  return 0;
}

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

using namespace std;

int main() {
  int n;
  while (cin >> n, n) {
    vector<int> vec(n);

    for (auto &v : vec)
      cin >> v;

    int cnt = 0;
    while (true) {
      vector<int> stat(101, 0);
      for (auto &v : vec)
        ++stat[v];

      vector<int> vec2(n, 0);
      for (int i = 0; i < n; ++i)
        vec2[i] = stat[vec[i]];

      if (vec == vec2)
        break;
      vec = vec2;
      ++cnt;
    }

    cout << cnt << endl;
    cout << vec[0];
    for (auto itr = vec.begin() + 1; itr != vec.end(); ++itr)
      cout << " " << *itr;
    cout << endl;
  }
}

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

int ans[113][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;
	}
}

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

using namespace std;

int main()
{
	string str1,str2;
	int n,i,j,num[100],array[100];
	
	for(;;)
	{
		cin >> n;
		if(n==0)
			break;
		
		
		for(i=0;i<n;i++)
			cin >> array[i];
		
		int ans=0;
		for(;;)
		{
			for(i=0;i<=12;i++)
				num[i]=0;
			bool flag=true;
			for(i=0;i<n;i++)
				num[array[i]]++;
			
			for(i=0;i<n;i++)
			{
				if(array[i]!=num[array[i]])
					flag=false;
				array[i]=num[array[i]];
			}
			if(flag==true)
				break;
			ans++;
		}
		
		cout << ans << endl;
		for(i=0;i<n;i++)
		{
			if(i<n-1)
				cout << array[i] << " ";
			else
				cout << array[i] << endl;
		}
	}
}

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

int a,c[20],d[20];
int main(){
  while(true){
    for(int i=0;i<20;i++) 
      {c[i]=0;d[i]=0;}
    cin>>a;
    if(a==0){break;}
    for (int i=0;i<a;i++){
      cin>>c[i];}
    while(true){
      for(int i=0;i<a;i++){
	for(int j=0;j<a;j++){ 
	  if(c[i]==c[j]){d[i]++;}
	}
      }
      int k=0;
      for(int i=0;i<a;i++)
	{ if(c[i]==d[i]){k++;}
	  c[i]=d[i];
	  d[i]=0;}
 
      if(k>a-2){break;}
    }
    for(int i=0;i<a;i++){
      printf("%d",c[i]);
      if(i!=a-1){printf(" ");}
    }
    
    
  }
}

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

using namespace std;

void solve()
{
	int N;
	while(cin >> N, N)
	{
		vector<int> Vec(N);
		for(int i = 0; i < N; ++i)
		{
			cin >> Vec[i];
		}
		int count = 0;
		bool Flag = true;
		while(Flag)
		{
			++count;
			map<int, int> Map;
			Flag = false;
			for(int i = 0; i < N; ++i)
			{
				++Map[Vec[i]];
			}
			vector<int> VecBuf(N);
			for(int i = 0; i < N; ++i)
			{
				VecBuf[i] = Map[Vec[i]];
			}
			for(int i = 0; i < N; ++i)
			{
				if(Vec[i] != VecBuf[i])
				{
					Flag = true;
					for(int j = 0; j < N; ++j)
					{
						Vec[j] = VecBuf[j];
					}
					goto NEXT;
				}
			}
NEXT:
			;
		}
		cout << --count << endl;
		for(int i = 0; i < N - 1; ++i)
		{
			cout << Vec[i] << " ";
		}
		cout << Vec[N - 1] << endl;
	}
}

int main()
{
	solve();
	return(0);
}

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

using namespace std;

int main()
{
	int a[12],n;
	for(;scanf("%d",&n),n;){
		for(int i=0;i<n;i++)	scanf("%d",a+i);

		int k;
		for(k=0;;k++){
			map<int,int> cnt;
			for(int i=0;i<n;i++)	cnt[a[i]]++;

			bool b=true;
			for(int i=0;i<n;i++){
				if(a[i]!=cnt[a[i]])	b=false;
				a[i]=cnt[a[i]];
			}
			if(b)	break;
		}

		printf("%d\n",k);
		for(int i=0;i<n;i++)	printf("%s%d",i?" ":"",a[i]);
		puts("");
	}

	return 0;
}

C++: #include <iostream>
using namespace std;
int main(){
	int n,s[12],o[12];
	while(cin>>n){
		if(!n)break;
		int step=0;
		for(int i=0;i<n;++i) cin>>s[i];
		for(int f=1;f;++step){
			for(int i=0;i<n;++i) o[i]=s[i];
			for(int i=0,count=0;i<n;++i){
				count=0;
				for(int j=0;j<n;++j){
					if(o[i]==o[j])++count;
				}
				s[i]=count;
			}
			f=0;
			for(int i=0;i<n;++i) if(s[i]!=o[i])f=1;
		}
		cout<<step<<"\n";
		for(int i=0;i<n;++i) cout<<s[i]<<((i!=n-1)?" ":"\n");
	}
	return 0;
}