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 <vector>
#include <map>

using namespace std;

int main() {
  int n;
  while(cin >> n, n != 0){
    int s[2][n];
    for(int i = 0; i < n ; i++)
    {
      cin >> s[0][i];
    }
    bool fixed = false;
    int src_index = 0;
    int operation_count = 0;
    while(!fixed)
    {
      map<int, int> appearance_map;
      for(int i = 0; i < n ; i ++)
      {
        ++appearance_map[s[src_index][i]];
      }
      fixed = true;
      for(int i = 0; i < n; i++) {
        s[1-src_index][i] = appearance_map[s[src_index][i]];
        if(s[0][i] != s[1][i]){
          fixed = false;
        }
      }
      if(fixed)break;
      src_index = 1 - src_index;
      ++operation_count;
    }
    cout << operation_count << endl;
    for(int i = 0; i < n; i++) {
      cout << s[0][i] << " ";
    }
    cout << endl;
  }
}

C++: #include<iostream>

using namespace std;

int main()
{
	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(;;)
		{
			int flag=1;
			
			for(i=0;i<=12;i++)
				num[i]=0;
			
			for(i=0;i<n;i++)
				num[array[i]]++;
			
			for(i=0;i<n;i++)
			{
				if(array[i]!=num[array[i]])
					flag=0;
				array[i]=num[array[i]];
			}
			
			if(flag==1)
				break;
			ans++;
		}
		
		cout << ans << endl;
		for(i=0;i<n;i++)
		{
			if(i<n-1)
				cout << array[i] << " ";
			else
				cout << array[i] << endl;
		}
	}
	return 0;
}

C++: #include <iostream>
using namespace std;
int main(){
	int i,j,n;
	while(cin >> n, n){
		int p,s[2][14]={0};
		for(i=1;i<=n;i++) cin >> s[0][i];
		for(p=0;;p++){
			for(i=1;i<=n;i++){
				s[1][i]=0;
				for(j=1;j<=n;j++) 
					if(s[0][j] == s[0][i]) s[1][i] ++;
			}
			for(i=1;i<=n;i++) if(s[0][i] != s[1][i]) break;
			if(i>n) break;
			for(i=1;i<=n;i++) s[0][i] = s[1][i];
		}
		cout << p << endl;
		for(i=1;i<=n;i++) cout << s[1][i] << (i==n?"":" ");
		cout << endl;
	}
}

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

void sha(char *a, char *b, int k){
  int i;
  char w[101];
  for(i=0;i<101;i++)
    w[i]=0;
  for(i=0;i<k;i++){
    w[a[i]]++;
  }
  for(i=0;i<k;i++){
    b[i]=w[a[i]];
  }
}

int main(){
  int n;
  while(1){
    char s[13];
    char p[13];
    char q[13];
    scanf("%d", &n);
    char c;scanf("%c", &c);
    if(n!=0){
      int i;
      for(i=0;i<n;i++){
	scanf("%d", &s[i]);
      }
      char v;scanf("%c", &v);
    }
    else
      {break;}

    strcpy(p, s);
    int h=0;
    while(1){
      sha(p, q, n);
      //printf("\n");
      int flag=0;
      int u;
      for(u=0;u<n;u++){
	if(p[u]!=q[u])
	  flag=1;
      }
      if(flag==0){
	  printf("%d\n",h);
	  int d;
	  for(d=0;d<n-1;d++)
	    printf("%d ", p[d]);
	  printf("%d\n", p[n-1]);
	  break;}
      strcpy(p, q);
      //printf("%d\n", h);
      h++;
    }
  }
  
  //printf("%d\n",an);
  //int i;
  //for(i=0;i<n;i++){
  //  printf("%d ", ans[i]);
  //}
  //printf("\n");
  
  /*int t;
  for(t=0;t<n-1;t++){
    printf("%d ", p[t]);
  }
  printf("%d\n", p[n-1]);*/

  
  return 0;
}

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 <iostream>
#include <cstdlib>

using namespace std;

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

int main(int argc, char **argv)
{
	int n, *a, *b, *c, s;
	
	while(1){
		cin >> n;
		if(n == 0){
			break;
		}
		a = (int *)calloc(n+1, sizeof(int));
		b = (int *)calloc(n+1, sizeof(int));
		c = (int *)calloc(13, sizeof(int));
		for(int i = 0; i < n; i++){
			cin >> a[i];
			c[a[i]]++;
		}
		for(int i = 0; i < n; i++){
			b[i] = a[i];
			a[i] = c[a[i]];
		}
		s = 0;
		while(func(a, b, n)){
			for(int i = 0; i < n; i++){
				b[i] = a[i];
				a[i] = c[a[i]];
			}
			for(int i = 0; i < n; i++){
				c[i] = 0;
			}
			for(int i = 0; i < n; i++){
				c[a[i]]++;
			}
			s++;
		}
		s--;
		cout << s << endl;
		for(int i = 0; i < n-1; i++){
			cout << a[i] << " ";
		}
		cout << a[n-1] << endl;
		
		free(c);
		free(b);
		free(a);
	}
	
	return 0;
}

C++: #include <iostream>
using namespace std;
int n,t,s[100],sa[100];
void angel(int turn){
    int cnt;
    for(int i=0;i<n;i++){
        for(int o=0;o<n;o++){
            if(sa[i]==sa[o]){
                cnt++;
            }
        }
        s[i]=cnt;
        cnt=0;
    }
    int check=0;
    for(int i=0;i<n;i++){
        if(s[i]!=sa[i]){
            check=1;
        }
    }
    if(check==0){
        t=turn;
    }
    else{
        for(int i=0;i<n;i++){
            sa[i]=s[i];
        }
        angel(turn+1);
    }
}
int main(void){
    cin>>n;
    while(n!=0){
        for(int i=0;i<n;i++){
            cin>>s[i];
            sa[i]=s[i];
        }
        angel(0);
        cout<<t<<endl;
        for(int i=0;i<n;i++){
            cout<<s[i]<<' ';
        }
        cout<<endl;
        cin>>n;
    }
    return 0;
}

C++: #include<iostream>


using namespace std;

int main(){
	int in;

	while(cin >> in){
		int rev = 0, max = 0;

		if(in == 0) break;

		int data[15];

		for(int i = 0; i < in; i++){
			cin >> data[i];
			if(data[i] < max) max = data[i];
		}

		int sum[max];

		while(1){

			for(int	i = 0; i < max; i++){
				sum[i] = 0;
			}
		
			for(int i = 0; i < in; i++){
				sum[data[i]]++;
			}
			for(int i = 0; i < in; i++){
				data[i] = sum[data[i]];
			}
			int status = 0;

			for(int i = 0; i < in; i++){
				if(data[i] != sum[data[i]]) status = 1;
			}

			if(status == 0){
				cout << rev << endl;
				for(int i = 0; i < in; i++){
					cout << data[i] << " ";
				}
				cout << endl;
				break;
			}
			rev++;
		}
	}

	return 0;
}

C++: #include<iostream>
#include<vector>
using namespace std;
vector<int> f(vector<int> v) {
	int cnt[110] = {};
	for (int i = 0; i < v.size(); i++) 
		cnt[v[i]]++;
	vector<int> r;
	for (int i = 0; i < v.size(); i++)
		r.push_back(cnt[v[i]]);
	return r;
}
int main() {
	int n;
	while (cin >> n, n) {
		vector<int>b, a;
		for (int i = 0; i < n; i++) {
			int k; cin >> k;
			b.push_back(k);
		}
		int cnt = 0;
		while (true) {
			cnt++;
			a = f(b);
			if (a == b)break;
			b = a;
		}
		cout << --cnt << endl;
		for (int i = 0; i < a.size(); i++) {
			if (i)cout << ' '; cout << b[i];
		}
	}
}