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<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;d++)
	    printf("%d ", p[d]);
	  printf("\n");
	  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>
using namespace std;
int main(void){

    int n;

    while(cin>>n){
        if(n==0)break;
        int a[13];
        int b[100000]={0};
        int c[13];
        for(int i=0;i<n;i++){
            cin>>a[i];
            b[a[i]]++;
        }
        int j=0;
        while(1){

            bool flg = false;
            for(int i=0;i<n;i++){
                c[i] = b[a[i]];
                if(c[i]!=a[i])flg = true;
                //cout<<c[i]<<" ";
            }
            //cout<<endl;
            if(!flg)break;
            for(int k=0;k<n;k++)b[k]=0;
            for(int k=0;k<n;k++){
                a[k] = c[k];
                b[a[k]]++;
            }
            j++;
        }
        cout<<j<<endl;
        for(int i=0;i<n;i++){
            cout<<c[i]<<" ";
        }
        cout<<endl;

    }

    return 0;
}

C++: #include <iostream>

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

void copy(int *a, int *b, int n)
{
	for (int i=0; i<n; i++) {
		a[i] = b[i];
	}
}

int main()
{
	int n;
	while (true) {
		std::cin >> n;
		if (n==0) break;
		
		int* s = new int[n];
		
		for (int i=0; i<n; i++) {
			std::cin >> s[i];
		}
		
		int* c = new int[n];
		int op_count = 0;
		
		while (true) {
			for (int i=0; i<n; i++) {
				int appearance = 0;
				for (int j=0; j<n; j++) {
					if (s[i] == s[j]) appearance++;
				}
				c[i] = appearance;
			}
			if (isSame(s,c,n)) break;
			copy(s,c,n);
			op_count++;
		}
		
		std::cout << op_count << std::endl;
		for (int i=0; i<n; i++) {
			if (i==0) std::cout << c[i];
			else std::cout << " " << c[i];
		}
		std::cout << std::endl;
		
		delete[] s;
		delete[] c;
	}
	
	return 0;
}

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

using namespace std;

#define MAX_ELEMENT 12
#define MAX_LINE 200

void calculate(vector<vector<int>>& calcVec) {
	map<int, int> calcMap, checkMap;
	int cnt, i, j;
	bool check;
	printf("Output:\n");
	for (i = 0; i < calcVec.size(); i++) {
		for (j = 0; j < calcVec[i].size(); j++) {
			calcMap[calcVec[i][j]]++;
		}
		cnt = 1;
		while (cnt) {
			check = true;
			for (j = 0; j < calcVec[i].size(); j++) {
				calcVec[i][j] = calcMap[calcVec[i][j]];
				checkMap[calcVec[i][j]]++;
			}
			for (j = 0; j < calcVec[i].size(); j++) {
				check &= (calcVec[i][j] == checkMap[calcVec[i][j]]);
			}
			if (check)break;
			calcMap = checkMap;
			checkMap.clear();
			cnt++;
		}
		printf("%d\n",cnt);
		for (j = 0; j < calcVec[i].size(); j++) {
			printf("%d ", calcVec[i][j]);
		}
		printf("\n");
		calcMap.clear();
		checkMap.clear();
	}
}

void getInputValue(vector<vector<int>>& calcVec) {
	string num, buf1, buf2;
	vector<int> vec;
	printf("Input:\n");
	for (int i = 0; i < MAX_LINE; i++) {
		getline(cin, num);

		int ele_length = atoi(num.c_str());
		if (!ele_length) { break; }

		vec.reserve(ele_length);
		getline(cin, buf1);
		stringstream ss(buf1);
		while (getline(ss, buf2, ' ')) {
			int value = atoi(buf2.c_str());
			if (!value) { break; }
			if (ele_length == vec.size()) { break; }
			vec.emplace_back(value);
		}
		calcVec.push_back(vec);
		vec.clear();
	}
}


int main() {
	vector<vector<int>> calcVec;
	getInputValue(calcVec);
	calculate(calcVec);
	return 0;
}

C++: #include<iostream>
using namespace std;
int n,a[33],cnt;
main()
{
    while(cin>>n,n)
    {
        cnt=0;
        for(int i=0;i<n;i++)cin>>a[i];
        int b[33];
        while(1)
        {
            for(int i=0;i<n;i++)
            {
                b[i]=0;
                for(int j=0;j<n;j++)b[i]+=a[i]==a[j];
            }
            bool f=1;
            for(int i=0;i<n;i++)f&=a[i]==b[i];
            if(f)
            {
                cout<<cnt<<endl;
                break;
            }
            cnt++;
            for(int i=0;i<n;i++)a[i]=b[i];
        }
    }
}

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

int main()
{
	int n;
	while(cin >> n,n)
	{
		int retu[13],mae[13];
		for (int i = 0; i < n; i++)
		{
			cin >> retu[i];
			mae[i] = retu[i];
		}
		int ans = 0;
		while(1)
		{
			int kazu[13] = {};
			for (int i = 0; i < n; i++)
			{
				mae[i] = retu[i];
				++kazu[retu[i]];
			}
			for (int i = 0; i < n; i++)
				retu[i] = kazu[retu[i]];
			int h = 0;
			for (int i = 0; i < n; i++)
				h += (mae[i] == retu[i]);
			if(h == n)
			{
				cout << ans << endl;
				break;
			}
			++ans;
		}
	}
}

C++: #include <iostream>
#include <cstdio>
#include <cstdlib>
using namespace std;
int main(void){
  char d1[12],d2[12];
  int n1,n2;
  int n,a;
  while(cin>>n,n!=0){
    for(int i=0;i<n;i++){
      scanf("%d",&d2[i]);
      d2[i]+='0';
    }
    a=0;
    n1=0;
    n2=atoi(d2);
    while(n1!=n2){
      n1=n2;
      for(int j=0;j<n;j++){
	d1[j]=d2[j];
	d2[j]=0;
      }
      for(int j=0;j<n;j++){
	for(int k=0;k<n;k++){
	  if(d1[j]==d1[k]){
	    d2[j]++;
	  }
	}
	d2[j]+='0';
      }
      n2=atoi(d2);
      a++;
    }
    cout<<a-1<<endl;
    for(int j=0;j<n-1;j++){
      printf("%c ",d1[j]);
    }
    cout<<d1[n-1]<<endl;
  }
  return 0;
}

C++: #include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <map>
using namespace std;

int main(){
	int n,v;
	map<int,int> mp;
	while(1){
		vector<int>  b ;
		cin >> n ;
		if(n==0){
			return 0;
		}
		for(int i=0;i<n;i++){
			cin >> v;
			b.push_back(v);
		}
		for(int j=0;;j++){
			vector<int>  a ;
			for(int i=0;i<=12;i++){
				mp[i]=0;
			}
			for(int i=0;i<n;i++){
			mp[b[i]] ++;
		}
			for(int i=0;i<n;i++){
				a.push_back(mp[b[i]]);
			}
			if(a == b){
				cout << j << "\n";
				cout << " " << a[0] ;
				for(int i=1;i<n;i++){
					cout << " " << a[i] ;
				}
				cout << "\n";
				break;
			}
			else{
				b = a;
			}
		}
	}
}

C++: #include<iostream>
#include<cmath>
using namespace std;
int main(){
long n,a[13],b[13],i,j,k,m=0;
while(cin>>n){
if(n==0)break;
for(i=0;i<n;i++)cin>>a[i];
for(;;){
for(i=0;i<n;i++){
for(k=0,j=0;j<n;j++)if(a[i]==a[j])k++;
b[i]=k;
}
for(i=0;i<n;i++)if(a[i]!=b[i])break;
if(i!=n)m++;else break;
for(i=0;i<n;i++)a[i]=b[i];
}
cout<<m<<endl;
cout<<b[0];
for(i=1;i<n;i++)cout<<" "<<b[i];
cout<<endl;
}
return 0;
}