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);
      if(strcmp(p, q)==0){
	  printf("%d\n",h);
	  int d;
	  for(d=0;d<n;d++)
	    printf("%d ", p[d]);
	  printf("\n");
	  break;}
      strcpy(p, q);
      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 <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;
	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;
	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 <stdio.h>
#include<math.h>
#include <algorithm>

using namespace std;


int main(){

	int n,table[101],count;
	bool FLG;

	while(true){
		scanf("%d",&n);
		if(n == 0)break;

		for(int i=0; i< 101; i++)table[i] = 0;
		int array[n],pre[n];
		count = 0;

		for(int i=0; i< n; i++){
			scanf("%d",&array[i]);
			table[array[i]]++;
		}

		while(true){
			FLG = true;

			if(count != 0){
				for(int i=0; i < n; i++){
					if(array[i] != pre[i]){
						FLG = false;
						break;
					}
				}
			}
			if(FLG)break;

			for(int i=0; i< n; i++){
				pre[i] = array[i];
				array[i] = table[array[i]];
			}

			for(int i=0; i< 101; i++)table[i] = 0;

			for(int i=0; i < n; i++)table[array[i]]++;
			count++;
		}

		printf("%d\n",count-1);

		printf("%d",array[0]);
		for(int i=1; i<n; i++)printf(" %d",array[i]);
		printf("\n");

	}

    return 0;
}

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

int main(){
    int n;
    while (1){
	cin >> n;
	if (n == 0) break;
	vector<int> s;
	int b;
	for (int i = 0; i < n; i++){
	    cin >> b;
	    s.push_back(b);
	}
	int c = 0;
	while (1){
	    vector<int> freq(1000, 0);
	    for (int i = 0; i < n; i++)
		freq[s[i]]++;

	    vector<int> ss = s;
	    for (int i = 0; i < n; i++)
		ss[i] = freq[ss[i]];

	    if (ss == s){
		cout << c << endl;
		for (int i = 0; i < s.size(); i++)
		    printf("%d%c", s[i], (i == s.size()-1)? '\n':' ');
		break;
	    }

	    s = ss;
	    c++;
	}
    }
}

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

using namespace std;

vector<int> C(vector<int> v) {
	map<int, int> m;

	for (int i = 0; i < v.size(); ++i)
		++m[v[i]];

	vector<int> ret;
	for (int i = 0; i < v.size(); ++i)
		ret.push_back(m[v[i]]);

	return ret;
}

int main() {
	int n;
	while (cin >> n, n) {
		vector<int> v;
		for (int i = 0; i < n; ++i) {
			int a; cin >> a;
			v.push_back(a);
		}

		vector<int> bv = v;
		while (1) {
			v = C(v);
			if (v == bv) break;
			bv = v;
		}

		for (int i = 0; i < v.size(); ++i)
			if (i == v.size()-1) cout << v[i] << endl;
			else cout << v[i] << " ";
	}
}

C++: #include <iostream>
#include <math.h>
#include <algorithm>
#include <map>
#include <cstdio>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
int main(){
  int n;
	while(true){
	cin>>n;
	if(n==0){break;}
	int *a=new int[n];
	map<int,int>Map;
	rep(i,n){
		cin>>a[i];
	}
	for(int count=0;;count++){
		rep(i,n){
			Map[a[i]]++;
		}
		int *s=new int[n];
		rep(i,n){
			s[i]=Map[a[i]];
		}
		if(a==s){cout<<count<<endl; for(int i=0;i<n;i++){
		if(i!=0){
		cout<<" ";
		}
		cout<<a[i];
	}
	cout<<endl;
	break;}
		rep(i,n){	
			s[i]=a[0];
		}
		  
	}
	}
	 
	return 0;
}

C++: #include<stdio.h>
#include<algorithm>
using namespace std;
int main()
{
	const int N = 12;
	int n,i,c;
	int a[N],b[N],(*pre)[N], (*next)[N];
	for(;;)
	{
		scanf("%d",&n);
		if(!n) break;
		for(i = 0; i < n; ++i)
			scanf("%d", &a[i]);

		c = 0;
		pre = &a;
		next = &b;
		for(;;)
		{
			for(i = 0; i < n; ++i)
			{
				(*next)[i] = count(*pre, *pre+N, (*pre)[i]);
			}
			if(equal(*pre, *pre+N, *next))
				break;
			swap(next, pre);
			c++;
		}
		printf("%d\n", c);
		for(i = 0; i < n; ++i)
			printf("%s%d", (i?" ":""), (*pre)[i]);
		putchar('\n');
	}
	return 0;
}

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

int ans[120][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 <vector>
#include <map>

using namespace std;

vector<int> C(vector<int> v) {
	map<int, int> m;

	for (int i = 0; i < v.size(); ++i)
		++m[v[i]];

	vector<int> ret;
	for (int i = 0; i < v.size(); ++i)
		ret.push_back(m[v[i]]);

	return ret;
}

int main() {
	int n;
	while (cin >> n, n) {
		vector<int> v;
		for (int i = 0; i < n; ++i) {
			int a; cin >> a;
			v.push_back(a);
		}

		int count = 0;
		vector<int> bv = v;
		while (1) {
			v = C(v);
			if (v == bv) break;
			bv = v;
			++count;
		}

		cout << count << endl;
		for (int i = 0; i < v.size(); ++i)
			if (i == v.size()-1) cout << v[i] << endl;
			else cout << v[i] << " ";
	}
}