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 <map>
#include <iostream>
using namespace std;

int ans[200][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<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;

int main(){

	int N;
	while(1){
		cin>>N;if(N==0)break;
	int s[15]={};
	for(int i=0;i<N;i++)
		cin>>s[i];

	int a[15]={};
	
	for(int i=0;i<N;i++){int p=0;
	for(int j=0;j<N;j++)
	{if(s[i]==s[j])p++;}
	a[i]=p;
	}

	int X=0;
	while(1){bool F=true;
		for(int i=0;i<N;i++)
			if(a[i]!=s[i])F=false;

		if(F==true)break;
		for(int i=0;i<N;i++)
			s[i]=a[i];
		for(int i=0;i<N;i++){int p=0;
	for(int j=0;j<N;j++)
	{if(s[i]==s[j])p++;}
	a[i]=p;
	}
		X++;
	}

	cout<<X<<endl;
	for(int i=0;i<N;i++)
	{	if(i>0)cout<<" ";cout<<a[i];

	
	}
	cout<<endl;
	}
	return 0;
}

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

int main(){
	int n;
	while(1){
		cin >> n;
		if(n==0) break;
		int a[n];
		int e = 0;
		for(int i=0;i<n;i++) cin >> a[i];
		while(1){
			int b[100000],c[n];
			for(int i=0;i<n;i++) b[i] = 0;
			for(int i=0;i<n;i++) b[a[i]]++;
			for(int i=0;i<n;i++) c[i] = b[a[i]];
			int d = 0;
			for(int i=0;i<n;i++) if(a[i]==c[i]) d++;
			if(d==n) break;
			e++;
			for(int i=0;i<n;i++) a[i] = c[i];
		}
		cout << e << endl;
		cout << a[0];
		for(int i=1;i<n;i++) cout << " " << a[i];
		cout << endl;
	}
}

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

int main(){
	vector<int> now, next;
	int len;
	while( cin >> len, len ){
		now.resize(len);
		next.resize(len);
		for( int i=0; i<len; i++ ){
			cin >> next[i];
		}
		int ope=0;
		while(!(now == next)){
			ope++;
			for( int i=0; i<len; i++ )	now[i] = next[i];
			for( int i=0; i<len; i++ ){
				int cnt=0;
				for( int j=0; j<len; j++ ){
					if( now[i] == now[j] )	cnt++;
				}
				next[i] = cnt;
			}
		}
		cout << ope-1 << endl;
		cout << now[0];
		for( int i=1; i<len; i++ ){
			cout << " " << now[i];
		}
		cout << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <vector>
#include <list>
#include <algorithm>
#include <cmath>
#include <stack>
#include <map>
#include <numeric>
#include <sstream>
#include <queue>
#include <iomanip>
using namespace std;

#define REP(i,n) for(int (i)=0; (i)<(n); (i)++)
#define FOR(i,a,b) for(int (i)=(a); (i)<(b); (i)++)
#define PUSH(n,v) for(int i=0; i<(n); i++) {int j; cin >> j; v.push_back(j);}
#define ALL(v) v.begin(), v.end()
#define print(s) cout << (s) << endl
#define printV(v) for(int zxc=0;zxc<v.size()-1;zxc++){cout << v[zxc] << " ";} cout << v.back() << endl;

vector<int> freq(vector<int> v) {
    vector<int> w(v);
    vector<int> a(v.size(),0);
    sort(ALL(w));
    REP(i,v.size()) {
        a[i] += upper_bound(ALL(w), v[i]) - lower_bound(ALL(w), v[i]);
    }
    return a;
}

bool same(vector<int> a, vector<int> b) {
    REP(i,a.size()) if (a[i] != b[i]) return false;
    return true;
}

void solve108(int n) {
    vector<int> v;
    PUSH(n,v);
    int cnt = 0;
    vector<int> a;
    while (true) {
        a = freq(v);
        if (same(v,a)) break;
        v = a;
        cnt++;
    }
    cout << cnt << endl;
    printV(a);
}

int main() {
    int n;
    while (cin >> n, n) {
        solve108(n);
    }
    return 0;
}

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

using namespace std;

int main() {
  int n;
  cin >> n;
  int s[2][n];
  while((cin >> s[0][0]), s[0][0] != 0){
    for(int i = 1; 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;


void hind(int in[], int out[], int length) {
  int temp[length];
  fill(&temp[0], &temp[length], 0);
  for(int i = 0; i < length; i++) {
    for(int j = 0; j < length; j++) {
      if(in[j] == in[i]) {
	temp[j]++;
      }
    }
  }
  for(int i = 0; i < length; i++) {
    out[i] = temp[i];
  }
}

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

void dainyu(int a[], int b[], int length) {
  for(int i = 0; i < length; i++) {
    a[i] = b[i];
  }
}

int main() {
  while(1) {
    int n;
    cin >> n;
    if(n == 0) break;

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

    int cnt;
    int data2[n];
    dainyu(data2, data, n);
    for(cnt = 0; !(cnt >= 1 && isEqual(data, data2, n)); cnt++) {
      dainyu(data, data2, n);
      hind(data, data2, n);
    }
    cout << cnt-1 << endl;
    for(int i = 0; i < n; i++) {
      if(i != 0) cout << ' ';
      cout << data2[i];
    }
    cout << endl;
  }
}

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

int main()
{
	int n,c,i;
	int pre[12],now[12],cnt[12];
	while(cin >> n,n)
	{
		for(i=0; i<n; i++)
		{
			cin >> pre[i];
			now[i] = 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;
}