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

using namespace std;

int main(void){
	std::ios_base::sync_with_stdio();

	int n;
	int arr[12];
	int arr2[12];
	int cnt;
	map<int,int> ind;
	bool f;

	while(1){
		cin>>n;
		if(n==0) break;
		for(int i=0;i<n;i++){
			cin>>arr[i];
		}
		f=true;
		cnt=-1;
		while(f){
			cnt++;
			ind.clear();
			for(int i=0;i<n;i++){
				arr2[i]=arr[i];
			}
			for(int i=0;i<n;i++){
				ind[arr[i]]=0;
			}
			for(int i=0;i<n;i++){
				ind[arr[i]]++;
			}
			for(int i=0;i<n;i++){
				arr[i]=ind[arr[i]];
			}
			f=false;
			for(int i=0;i<n;i++){
				if(arr[i]!=arr2[i]) f=true;
			}
		}
		cout<<cnt<<endl;
		for(int i=0;i<n-1;i++){
			cout<<arr[i]<<" ";
		}
		cout<<arr[n-1]<<endl;
	}
	return 0;
}

C++: #include <iostream>
#include <fstream>
#include <typeinfo>
#include <vector>
#include <cmath>
#include <map>
#include <string>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <iomanip>
#include <cctype>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const double pi=acos(-1);
const double eps=1e-8;

int n,c;
vi num,tmp;

void func(){
	c++;
	for(int i=0;i<n;i++){
		int x=0;
		for(int j=0;j<n;j++){
			if(num[i]==num[j]) x++;
		}
		tmp[i]=x;
	}
}

int main(){
	while(1){
		cin>>n;
		if(!n) break;
		num=vi(n);
		tmp=vi(n);
		for(int i=0;i<n;i++) cin>>num[i];
		c=0;
		while(1){
			func();
			int ctmp=0;
			for(int i=0;i<n;i++){
				if(num[i]==tmp[i]) ctmp++;
			}
			if(ctmp==n) break;
			for(int i=0;i<n;i++) num[i]=tmp[i];
		}
		cout<<c-1<<endl;
		for(int i=0;i<n-1;i++) cout<<num[i]<<' ';
		cout<<num[n-1]<<endl;
	}
}

C++: #define _USE_MATH_DEFINES
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <cassert>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>
#include <iomanip>
#include <iterator>

using namespace std;

typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;

int main(){
	int n;
	while(cin>>n,n){
		vector<int>s(n),p(n);
		for(int i = 0; i < n; i++) cin>>p[i];
		int cnt = 0;
		do{
			s.swap(p);
			map<int,int> st;
			for(int i = 0; i < n; i++) st[s[i]]++;
			for(int i = 0; i < n; i++) p[i] = st[s[i]];
			cnt++;
		}while(s != p);
		cout << cnt - 1 << endl;
		for(int i = 0; i < n; i++) printf("%d%c",p[i],i==n-1?'\n':' ');
	}

    return 0;
}

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

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

		int cnt = 0;
		while (1) {
			vector<int> t = dt;
			for (int i=0; i<n; i++)
				dt[i] = count(t.begin(), t.end(), t[i]);

			if (t == dt) {
				cout << cnt << endl;
				for (int i=0; i<n-1; i++)
					cout << t[i] << ' ';

				cout << t[n-1] << endl;
				break;
			}
			cnt++;
		}
	}
	return 0;
}

C++: #include<stdio.h>

int same(int *x, int *y, int n){
    int i;
    for(i = 0;i < n;i++){
	if(x[i] != y[i])return 0;
    }
    return 1;
}

void swap(int *x, int *y){
    int p = *x;
    *x = *y;
    *y = p;
}

int main(){
    int i, j, n;
    while(scanf("%d", &n), n){
	int a[n], b[n], res = 0;
	for(i = 0;i < n;i++)scanf("%d", a + i);
	while(1){
	    for(i = 0;i < n;i++){
		b[i] = 0;
		for(j = 0;j < n;j++){
		    if(a[j] == a[i])b[i]++;
		}
	    }
	    if(same(a, b, n))break;
	    for(i = 0;i < n;i++)swap(a + i, b + i);
	    res++;
	}
	printf("%d\n", res);
	for(i = 0;i < n;i++){
	    if(i != 0)printf(" ");
	    printf("%d", a[i]);
	}
	puts("");
    }
    return 0;
}

C++: #include <iostream>
using namespace std;
bool jug(int* s1, int* s2, int len){
    for(int i = 0; i < len; ++i) {
        if (s1[i] != s2[i]) return false;
    }
    return true;
}
int main(){
    int n,count,tmp,x;
    int* s = new int[12];
    int* ans = new int[12];
    while(true) {
        cin >> n;
        if (n ==  0) {
            break;
	    cout << endl;
        }
        for(int i = 0; i < n; ++i) {
            cin >> s[i];
        }
        x = 0;
        while(true){
            for(int i = 0; i < n; ++i) {
                count = 0;
                for(int j = 0; j < n; ++j) {
                    if (s[i] == s[j]) {
                        ++count;
                    }
                }
                ans[i] = count;
            }

            if (jug(s, ans, n)) break;
            x++;

            for (int i = 0; i < n; i++) {
                tmp = s[i];
                s[i] = ans[i];
                ans[i] = tmp;
            }
        }
        cout << x << endl;
        for (int i = 0; i < n; i++) {
            cout << s[i] << " ";
        }
        cout << endl;

    }
    delete s;
    delete ans;
}

C++: #include <bits/stdc++.h>
#define MAX_N 15
using namespace std;

int data[MAX_N];
int n;

//出力
void print() {
    for(int r = 0; r < n; r++) {
        printf("%d", data[r]);
        if(r == n - 1) putchar('\n');
        else putchar(' ');
    }
}

//不動点であるか判定
bool judge() {
    for(int r = 0; r < n; r++) {
        if(count(data, data+n, data[r]) != data[r]) return(false);
    }
    return(true);
}

//数列を変換
void convert() {
    int tmp[n];
    for(int r = 0; r < n; r++) {
        tmp[r] = (int)count(data,data+n,data[r]);
    }
    memcpy(data, tmp, sizeof(tmp));
}

int solve() {
    int res = 0;
    do {
        convert();
        res++;
    }while(!judge());
    return(res);
}

int main(void) {
    while(cin >> n, n != 0) {
        for(int r = 0; r < n; r++) {
            cin >> data[r];
        }
        printf("%d\n", solve());
        print();
    }
    return(0);
}

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;
}